Fix warnings in TransactionAdapter
[mdsal.git] / binding / mdsal-binding-util / src / main / java / org / opendaylight / mdsal / binding / util / TransactionAdapter.java
index 35110027b5803de76f0c759a5114d018c4edb2bc..65b2618a2d9f5f667daa4dc401bfb335b35bd93d 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.mdsal.binding.util;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ForwardingObject;
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.Optional;
@@ -45,11 +44,11 @@ public final class TransactionAdapter {
      * @throws NullPointerException if the provided transaction is {@code null}.
      */
     public static ReadWriteTransaction toReadWriteTransaction(
-            TypedReadWriteTransaction<? extends Datastore> datastoreTx) {
+            final TypedReadWriteTransaction<? extends Datastore> datastoreTx) {
         if (datastoreTx instanceof TypedReadWriteTransactionImpl) {
-            TypedReadWriteTransactionImpl nonSubmitCancelableDatastoreReadWriteTransaction =
-                    (TypedReadWriteTransactionImpl) datastoreTx;
-            return new ReadWriteTransactionAdapter(nonSubmitCancelableDatastoreReadWriteTransaction.datastoreType,
+            TypedReadWriteTransactionImpl<?> nonSubmitCancelableDatastoreReadWriteTransaction =
+                    (TypedReadWriteTransactionImpl<?>) datastoreTx;
+            return new ReadWriteTransactionAdapter<>(nonSubmitCancelableDatastoreReadWriteTransaction.datastoreType,
                     nonSubmitCancelableDatastoreReadWriteTransaction);
         }
         throw new IllegalArgumentException(
@@ -63,51 +62,51 @@ public final class TransactionAdapter {
      * @param datastoreTx The transaction to adapt.
      * @return The adapted transaction.
      */
-    public static WriteTransaction toWriteTransaction(TypedWriteTransaction<? extends Datastore> datastoreTx) {
+    public static WriteTransaction toWriteTransaction(final TypedWriteTransaction<? extends Datastore> datastoreTx) {
         if (datastoreTx instanceof TypedWriteTransactionImpl) {
-            TypedWriteTransactionImpl nonSubmitCancelableDatastoreWriteTransaction =
-                    (TypedWriteTransactionImpl) datastoreTx;
-            return new WriteTransactionAdapter(nonSubmitCancelableDatastoreWriteTransaction.datastoreType,
+            TypedWriteTransactionImpl<?> nonSubmitCancelableDatastoreWriteTransaction =
+                    (TypedWriteTransactionImpl<?>) datastoreTx;
+            return new WriteTransactionAdapter<>(nonSubmitCancelableDatastoreWriteTransaction.datastoreType,
                     nonSubmitCancelableDatastoreWriteTransaction);
         }
         throw new IllegalArgumentException(
                 "Unsupported TypedWriteTransaction implementation " + datastoreTx.getClass());
     }
 
-    // We want to subclass this class, even though it has a private constructor
-    @SuppressWarnings("FinalClass")
-    private static class WriteTransactionAdapter<D extends Datastore, T extends TypedWriteTransaction<D>>
+    private static class WriteTransactionAdapter<S extends Datastore, D extends TypedWriteTransaction<S>>
             extends ForwardingObject implements WriteTransaction {
         private final LogicalDatastoreType datastoreType;
-        private final T delegate;
+        private final D delegate;
 
-        private WriteTransactionAdapter(LogicalDatastoreType datastoreType, T delegate) {
+        WriteTransactionAdapter(final LogicalDatastoreType datastoreType, final D delegate) {
             this.datastoreType = datastoreType;
             this.delegate = delegate;
         }
 
         @Override
-        public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        public <T extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
+                final T data) {
             checkStore(store);
             delegate.put(path, data);
         }
 
         @Override
-        public <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
-                boolean createMissingParents) {
+        public <T extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
+                final T data, final boolean createMissingParents) {
             checkStore(store);
             delegate.put(path, data, createMissingParents);
         }
 
         @Override
-        public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
+        public <T extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
+                final T data) {
             checkStore(store);
             delegate.merge(path, data);
         }
 
         @Override
-        public <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
-                boolean createMissingParents) {
+        public <T extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
+                final T data, final boolean createMissingParents) {
             checkStore(store);
             delegate.merge(path, data, createMissingParents);
         }
@@ -118,7 +117,7 @@ public final class TransactionAdapter {
         }
 
         @Override
-        public void delete(LogicalDatastoreType store, InstanceIdentifier<?> path) {
+        public void delete(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
             checkStore(store);
             delegate.delete(path);
         }
@@ -128,30 +127,31 @@ public final class TransactionAdapter {
             throw new UnsupportedOperationException("Managed transactions must not be committed");
         }
 
-        void checkStore(LogicalDatastoreType store) {
-            checkArgument(datastoreType.equals(store), "Invalid datastore %s used instead of %s", store, datastoreType);
-        }
-
         @Override
         public Object getIdentifier() {
             return delegate.getIdentifier();
         }
 
         @Override
-        protected T delegate() {
+        protected D delegate() {
             return delegate;
         }
+
+        void checkStore(final LogicalDatastoreType store) {
+            checkArgument(datastoreType.equals(store), "Invalid datastore %s used instead of %s", store, datastoreType);
+        }
     }
 
-    private static final class ReadWriteTransactionAdapter<D extends Datastore>
-            extends WriteTransactionAdapter<D, TypedReadWriteTransaction<D>> implements ReadWriteTransaction {
-        private ReadWriteTransactionAdapter(LogicalDatastoreType datastoreType, TypedReadWriteTransaction<D> delegate) {
+    private static final class ReadWriteTransactionAdapter<S extends Datastore>
+            extends WriteTransactionAdapter<S, TypedReadWriteTransaction<S>> implements ReadWriteTransaction {
+        ReadWriteTransactionAdapter(final LogicalDatastoreType datastoreType,
+                final TypedReadWriteTransaction<S> delegate) {
             super(datastoreType, delegate);
         }
 
         @Override
-        public <T extends DataObject> FluentFuture<Optional<T>> read(LogicalDatastoreType store,
-                InstanceIdentifier<T> path) {
+        public <T extends DataObject> FluentFuture<Optional<T>> read(final LogicalDatastoreType store,
+                final InstanceIdentifier<T> path) {
             checkStore(store);
             return delegate().read(path);
         }