Enforce statement format validity
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / concurrent / MappingCheckedFuture.java
index 48f69e2da3ba29832d82141d338c3c3233dd44fd..ce70f35a02f77d7f3692931d0e8486cbd9be3026 100644 (file)
@@ -8,24 +8,25 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.util.concurrent.AbstractCheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.AbstractCheckedFuture;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.function.Function;
+import javax.annotation.Nonnull;
 
 /**
  * An implementation of CheckedFuture that provides similar behavior for the <code>get</code> methods
  * that the <code>checkedGet</code> methods provide.
- * <p>
- * For {@link CancellationException} and {@link InterruptedException}, the specified exception mapper
+ *
+ * <p>For {@link CancellationException} and {@link InterruptedException}, the specified exception mapper
  * is invoked to translate them to the checked exception type.
- * <p>
- * For {@link ExecutionException}, the mapper is invoked to translate the cause to the checked exception
+ *
+ * <p>For {@link ExecutionException}, the mapper is invoked to translate the cause to the checked exception
  * and a new ExecutionException is thrown with the translated cause.
  *
  * @author Thomas Pantelis
@@ -33,13 +34,13 @@ import com.google.common.util.concurrent.ListenableFuture;
  * @param <V> The result type returned by this Future's get method
  * @param <X> The checked exception type
  */
-public class MappingCheckedFuture<V, X extends Exception> extends AbstractCheckedFuture<V, X> {
+public final class MappingCheckedFuture<V, X extends Exception> extends AbstractCheckedFuture<V, X> {
 
     private final Function<Exception, X> mapper;
 
-    private MappingCheckedFuture( ListenableFuture<V> delegate, Function<Exception, X> mapper ) {
-        super( delegate );
-        this.mapper = Preconditions.checkNotNull( mapper );
+    private MappingCheckedFuture(final ListenableFuture<V> delegate, final Function<Exception, X> mapper) {
+        super(delegate);
+        this.mapper = requireNonNull(mapper);
     }
 
     /**
@@ -51,45 +52,46 @@ public class MappingCheckedFuture<V, X extends Exception> extends AbstractChecke
      * @return a new <code>MappingCheckedFuture</code>
      */
     public static <V, X extends Exception> MappingCheckedFuture<V, X> create(
-            ListenableFuture<V> delegate, Function<Exception, X> mapper ) {
-        return new MappingCheckedFuture<V, X>( delegate, mapper );
+            final ListenableFuture<V> delegate, final Function<Exception, X> mapper) {
+        return new MappingCheckedFuture<>(delegate, mapper);
     }
 
     @Override
-    protected X mapException( Exception e ) {
-        return mapper.apply( e );
+    @SuppressWarnings("checkstyle:parameterName")
+    protected X mapException(@Nonnull final Exception e) {
+        return mapper.apply(e);
     }
 
-    private ExecutionException wrapInExecutionException( String message, final Exception e ) {
-        return new ExecutionException( message, mapException( e ) );
+    private ExecutionException wrapInExecutionException(final String message, final Exception ex) {
+        return new ExecutionException(message, mapException(ex));
     }
 
     @Override
     public V get() throws InterruptedException, ExecutionException {
         try {
             return super.get();
-        } catch( InterruptedException e ) {
+        } catch (final InterruptedException e) {
             Thread.currentThread().interrupt();
-            throw wrapInExecutionException( "Operation was interrupted", e );
-        } catch( CancellationException e ) {
-            throw wrapInExecutionException( "Operation was cancelled", e );
-        } catch( ExecutionException e ) {
-            throw wrapInExecutionException( e.getMessage(), e );
+            throw wrapInExecutionException("Operation was interrupted", e);
+        } catch (final CancellationException e) {
+            throw wrapInExecutionException("Operation was cancelled", e);
+        } catch (final ExecutionException e) {
+            throw wrapInExecutionException(e.getMessage(), e);
         }
     }
 
     @Override
-    public V get( long timeout, TimeUnit unit )
+    public V get(final long timeout, @Nonnull final TimeUnit unit)
             throws InterruptedException, ExecutionException, TimeoutException {
         try {
-            return super.get( timeout, unit );
-        } catch( InterruptedException e ) {
+            return super.get(timeout, unit);
+        } catch (final InterruptedException e) {
             Thread.currentThread().interrupt();
-            throw wrapInExecutionException( "Operation was interrupted", e );
-        } catch( CancellationException e ) {
-            throw wrapInExecutionException( "Operation was cancelled", e );
-        } catch( ExecutionException e ) {
-            throw wrapInExecutionException( e.getMessage(), e );
+            throw wrapInExecutionException("Operation was interrupted", e);
+        } catch (final CancellationException e) {
+            throw wrapInExecutionException("Operation was cancelled", e);
+        } catch (final ExecutionException e) {
+            throw wrapInExecutionException(e.getMessage(), e);
         }
     }
 }