From 45ca5f802b5da339b906e2ccb96b898e731e985c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 11 Oct 2018 14:20:03 +0200 Subject: [PATCH] Enable checkstyle in mdsal-binding-util This fixes a few violations and flips enforcement on. Change-Id: I6b0de1511bda6ad509991f343c2a456ba67866d7 Signed-off-by: Robert Varga --- binding/mdsal-binding-util/pom.xml | 7 ++++ .../util/ManagedNewTransactionRunnerImpl.java | 19 ++++++----- .../util/ManagedTransactionFactory.java | 7 ++-- .../util/ManagedTransactionFactoryImpl.java | 32 ++++++++++--------- .../binding/util/TransactionAdapter.java | 32 ++++++++++--------- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/binding/mdsal-binding-util/pom.xml b/binding/mdsal-binding-util/pom.xml index 2de9710bc9..9d8c7d666a 100644 --- a/binding/mdsal-binding-util/pom.xml +++ b/binding/mdsal-binding-util/pom.xml @@ -51,6 +51,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + diff --git a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedNewTransactionRunnerImpl.java b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedNewTransactionRunnerImpl.java index 955cf2a4a8..4d95eea463 100644 --- a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedNewTransactionRunnerImpl.java +++ b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedNewTransactionRunnerImpl.java @@ -36,7 +36,7 @@ public class ManagedNewTransactionRunnerImpl extends ManagedTransactionFactoryIm private static final Logger LOG = LoggerFactory.getLogger(ManagedNewTransactionRunnerImpl.class); @Inject - public ManagedNewTransactionRunnerImpl(DataBroker broker) { + public ManagedNewTransactionRunnerImpl(final DataBroker broker) { // Early check to ensure the error message is understandable for the caller super(requireNonNull(broker, "broker must not be null")); } @@ -45,13 +45,14 @@ public class ManagedNewTransactionRunnerImpl extends ManagedTransactionFactoryIm @Override @CheckReturnValue public FluentFuture applyWithNewReadWriteTransactionAndSubmit( - Class datastoreType, InterruptibleCheckedFunction, R, E> txFunction) { + final Class datastoreType, + final InterruptibleCheckedFunction, R, E> txFunction) { return super.applyWithNewTransactionAndSubmit(datastoreType, getTransactionFactory()::newReadWriteTransaction, WriteTrackingTypedReadWriteTransactionImpl::new, txFunction::apply, this::commit); } @Override - public R applyWithNewTransactionChainAndClose(Function chainConsumer) { + public R applyWithNewTransactionChainAndClose(final Function chainConsumer) { try (TransactionChain realTxChain = getTransactionFactory().createTransactionChain( new TransactionChainListener() { @Override @@ -72,8 +73,8 @@ public class ManagedNewTransactionRunnerImpl extends ManagedTransactionFactoryIm @Override @CheckReturnValue public FluentFuture - callWithNewReadWriteTransactionAndSubmit(Class datastoreType, - InterruptibleCheckedConsumer, E> txConsumer) { + callWithNewReadWriteTransactionAndSubmit(final Class datastoreType, + final InterruptibleCheckedConsumer, E> txConsumer) { return callWithNewTransactionAndSubmit(datastoreType, getTransactionFactory()::newReadWriteTransaction, WriteTrackingTypedReadWriteTransactionImpl::new, txConsumer::accept, this::commit); } @@ -81,14 +82,16 @@ public class ManagedNewTransactionRunnerImpl extends ManagedTransactionFactoryIm // This is overridden to use this class’s commit method @Override @CheckReturnValue - public FluentFuture callWithNewWriteOnlyTransactionAndSubmit( - Class datastoreType, InterruptibleCheckedConsumer, E> txConsumer) { + public FluentFuture + callWithNewWriteOnlyTransactionAndSubmit(final Class datastoreType, + final InterruptibleCheckedConsumer, E> txConsumer) { return super.callWithNewTransactionAndSubmit(datastoreType, getTransactionFactory()::newWriteOnlyTransaction, WriteTrackingTypedWriteTransactionImpl::new, txConsumer::accept, this::commit); } @CheckReturnValue - private FluentFuture commit(WriteTransaction realTx, WriteTrackingTransaction wrappedTx) { + private FluentFuture commit(final WriteTransaction realTx, + final WriteTrackingTransaction wrappedTx) { if (wrappedTx.isWritten()) { // The transaction contains changes, commit it return realTx.commit(); diff --git a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactory.java b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactory.java index 4a27344038..2d8d5efccf 100644 --- a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactory.java +++ b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactory.java @@ -20,6 +20,7 @@ import org.opendaylight.mdsal.binding.api.WriteTransaction; /** * Managed transaction factories provide managed transactions, i.e. transactions which are automatically * submitted or cancelled (write) or closed (read). + * *

* This is a common interface for broker- and chain-based transaction managers, and should not be used directly. */ @@ -88,7 +89,7 @@ public interface ManagedTransactionFactory { * @param datastoreType the {@link Datastore} type that will be accessed * @param txFunction the {@link InterruptibleCheckedFunction} that needs a new read-write transaction * @return the {@link FluentFuture} returned by {@link ReadWriteTransaction#commit()}, or a failed future with an - * application specific exception (not from submit()) + * application specific exception (not from submit()) */ @CheckReturnValue @@ -157,7 +158,7 @@ public interface ManagedTransactionFactory { * @param datastoreType the {@link Datastore} type that will be accessed * @param txConsumer the {@link InterruptibleCheckedConsumer} that needs a new read-write transaction * @return the {@link FluentFuture} returned by {@link ReadWriteTransaction#commit()}, or a failed future with an - * application specific exception (not from submit()) + * application specific exception (not from submit()) */ @CheckReturnValue @@ -188,7 +189,7 @@ public interface ManagedTransactionFactory { * @param datastoreType the {@link Datastore} type that will be accessed * @param txConsumer the {@link InterruptibleCheckedConsumer} that needs a new write only transaction * @return the {@link FluentFuture} returned by {@link WriteTransaction#commit()}, or a failed future with an - * application specific exception (not from submit()) + * application specific exception (not from submit()) */ @CheckReturnValue diff --git a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactoryImpl.java b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactoryImpl.java index 299ef158a3..64a54b7f8b 100644 --- a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactoryImpl.java +++ b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/ManagedTransactionFactoryImpl.java @@ -29,13 +29,13 @@ class ManagedTransactionFactoryImpl implements Man private final T transactionFactory; - ManagedTransactionFactoryImpl(T transactionFactory) { + ManagedTransactionFactoryImpl(final T transactionFactory) { this.transactionFactory = requireNonNull(transactionFactory, "transactionFactory must not be null"); } @Override public R applyInterruptiblyWithNewReadOnlyTransactionAndClose( - Class datastoreType, InterruptibleCheckedFunction, R, E> txFunction) + final Class datastoreType, final InterruptibleCheckedFunction, R, E> txFunction) throws E, InterruptedException { try (ReadTransaction realTx = transactionFactory.newReadOnlyTransaction()) { TypedReadTransaction @@ -46,7 +46,7 @@ class ManagedTransactionFactoryImpl implements Man @Override public R applyWithNewReadOnlyTransactionAndClose( - Class datastoreType, CheckedFunction, R, E> txFunction) throws E { + final Class datastoreType, final CheckedFunction, R, E> txFunction) throws E { try (ReadTransaction realTx = transactionFactory.newReadOnlyTransaction()) { TypedReadTransaction wrappedTx = new TypedReadTransactionImpl<>(datastoreType, realTx); @@ -57,15 +57,15 @@ class ManagedTransactionFactoryImpl implements Man @Override @CheckReturnValue public - FluentFuture applyWithNewReadWriteTransactionAndSubmit(Class datastoreType, - InterruptibleCheckedFunction, R, E> txFunction) { + FluentFuture applyWithNewReadWriteTransactionAndSubmit(final Class datastoreType, + final InterruptibleCheckedFunction, R, E> txFunction) { return applyWithNewTransactionAndSubmit(datastoreType, transactionFactory::newReadWriteTransaction, TypedReadWriteTransactionImpl::new, txFunction, (realTx, wrappedTx) -> realTx.commit()); } @Override public void callInterruptiblyWithNewReadOnlyTransactionAndClose( - Class datastoreType, InterruptibleCheckedConsumer, E> txConsumer) + final Class datastoreType, final InterruptibleCheckedConsumer, E> txConsumer) throws E, InterruptedException { try (ReadTransaction realTx = transactionFactory.newReadOnlyTransaction()) { TypedReadTransaction wrappedTx = new TypedReadTransactionImpl<>(datastoreType, realTx); @@ -75,7 +75,7 @@ class ManagedTransactionFactoryImpl implements Man @Override public void callWithNewReadOnlyTransactionAndClose( - Class datastoreType, CheckedConsumer, E> txConsumer) throws E { + final Class datastoreType, final CheckedConsumer, E> txConsumer) throws E { try (ReadTransaction realTx = transactionFactory.newReadOnlyTransaction()) { TypedReadTransaction wrappedTx = new TypedReadTransactionImpl<>(datastoreType, realTx); txConsumer.accept(wrappedTx); @@ -85,16 +85,17 @@ class ManagedTransactionFactoryImpl implements Man @Override @CheckReturnValue public - FluentFuture callWithNewReadWriteTransactionAndSubmit(Class datastoreType, - InterruptibleCheckedConsumer, E> txConsumer) { + FluentFuture callWithNewReadWriteTransactionAndSubmit(final Class datastoreType, + final InterruptibleCheckedConsumer, E> txConsumer) { return callWithNewTransactionAndSubmit(datastoreType, transactionFactory::newReadWriteTransaction, TypedReadWriteTransactionImpl::new, txConsumer, (realTx, wrappedTx) -> realTx.commit()); } @Override @CheckReturnValue - public FluentFuture callWithNewWriteOnlyTransactionAndSubmit( - Class datastoreType, InterruptibleCheckedConsumer, E> txConsumer) { + public FluentFuture + callWithNewWriteOnlyTransactionAndSubmit(final Class datastoreType, + final InterruptibleCheckedConsumer, E> txConsumer) { return callWithNewTransactionAndSubmit(datastoreType, transactionFactory::newWriteOnlyTransaction, TypedWriteTransactionImpl::new, txConsumer, (realTx, wrappedTx) -> realTx.commit()); } @@ -102,8 +103,8 @@ class ManagedTransactionFactoryImpl implements Man @CheckReturnValue protected FluentFuture callWithNewTransactionAndSubmit( - Class datastoreType, Supplier txSupplier, BiFunction, T, W> txWrapper, - InterruptibleCheckedConsumer txConsumer, BiFunction> txSubmitter) { + final Class datastoreType, final Supplier txSupplier, final BiFunction, T, W> txWrapper, + final InterruptibleCheckedConsumer txConsumer, final BiFunction> txSubmitter) { return applyWithNewTransactionAndSubmit(datastoreType, txSupplier, txWrapper, tx -> { txConsumer.accept(tx); return null; @@ -114,8 +115,9 @@ class ManagedTransactionFactoryImpl implements Man @SuppressWarnings("checkstyle:IllegalCatch") protected FluentFuture applyWithNewTransactionAndSubmit( - Class datastoreType, Supplier txSupplier, BiFunction, T, W> txWrapper, - InterruptibleCheckedFunction txFunction, BiFunction> txSubmitter) { + final Class datastoreType, final Supplier txSupplier, final BiFunction, T, W> txWrapper, + final InterruptibleCheckedFunction txFunction, + final BiFunction> txSubmitter) { T realTx = txSupplier.get(); W wrappedTx = txWrapper.apply(datastoreType, realTx); R result; diff --git a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/TransactionAdapter.java b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/TransactionAdapter.java index 35110027b5..f3e4c466c5 100644 --- a/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/TransactionAdapter.java +++ b/binding/mdsal-binding-util/src/main/java/org/opendaylight/mdsal/binding/util/TransactionAdapter.java @@ -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,7 +44,7 @@ public final class TransactionAdapter { * @throws NullPointerException if the provided transaction is {@code null}. */ public static ReadWriteTransaction toReadWriteTransaction( - TypedReadWriteTransaction datastoreTx) { + final TypedReadWriteTransaction datastoreTx) { if (datastoreTx instanceof TypedReadWriteTransactionImpl) { TypedReadWriteTransactionImpl nonSubmitCancelableDatastoreReadWriteTransaction = (TypedReadWriteTransactionImpl) datastoreTx; @@ -63,7 +62,7 @@ public final class TransactionAdapter { * @param datastoreTx The transaction to adapt. * @return The adapted transaction. */ - public static WriteTransaction toWriteTransaction(TypedWriteTransaction datastoreTx) { + public static WriteTransaction toWriteTransaction(final TypedWriteTransaction datastoreTx) { if (datastoreTx instanceof TypedWriteTransactionImpl) { TypedWriteTransactionImpl nonSubmitCancelableDatastoreWriteTransaction = (TypedWriteTransactionImpl) datastoreTx; @@ -81,33 +80,35 @@ public final class TransactionAdapter { private final LogicalDatastoreType datastoreType; private final T delegate; - private WriteTransactionAdapter(LogicalDatastoreType datastoreType, T delegate) { + private WriteTransactionAdapter(final LogicalDatastoreType datastoreType, final T delegate) { this.datastoreType = datastoreType; this.delegate = delegate; } @Override - public void put(LogicalDatastoreType store, InstanceIdentifier path, T data) { + public void put(final LogicalDatastoreType store, final InstanceIdentifier path, + final T data) { checkStore(store); delegate.put(path, data); } @Override - public void put(LogicalDatastoreType store, InstanceIdentifier path, T data, - boolean createMissingParents) { + public void put(final LogicalDatastoreType store, final InstanceIdentifier path, + final T data, final boolean createMissingParents) { checkStore(store); delegate.put(path, data, createMissingParents); } @Override - public void merge(LogicalDatastoreType store, InstanceIdentifier path, T data) { + public void merge(final LogicalDatastoreType store, final InstanceIdentifier path, + final T data) { checkStore(store); delegate.merge(path, data); } @Override - public void merge(LogicalDatastoreType store, InstanceIdentifier path, T data, - boolean createMissingParents) { + public void merge(final LogicalDatastoreType store, final InstanceIdentifier path, + final T data, final boolean createMissingParents) { checkStore(store); delegate.merge(path, data, createMissingParents); } @@ -118,7 +119,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,7 +129,7 @@ public final class TransactionAdapter { throw new UnsupportedOperationException("Managed transactions must not be committed"); } - void checkStore(LogicalDatastoreType store) { + void checkStore(final LogicalDatastoreType store) { checkArgument(datastoreType.equals(store), "Invalid datastore %s used instead of %s", store, datastoreType); } @@ -145,13 +146,14 @@ public final class TransactionAdapter { private static final class ReadWriteTransactionAdapter extends WriteTransactionAdapter> implements ReadWriteTransaction { - private ReadWriteTransactionAdapter(LogicalDatastoreType datastoreType, TypedReadWriteTransaction delegate) { + private ReadWriteTransactionAdapter(final LogicalDatastoreType datastoreType, + final TypedReadWriteTransaction delegate) { super(datastoreType, delegate); } @Override - public FluentFuture> read(LogicalDatastoreType store, - InstanceIdentifier path) { + public FluentFuture> read(final LogicalDatastoreType store, + final InstanceIdentifier path) { checkStore(store); return delegate().read(path); } -- 2.36.6