From: Michael Vorburger Date: Mon, 25 Jul 2016 23:12:40 +0000 (+0200) Subject: Checkstyle clean up about 200 trivial violation X-Git-Tag: release/boron~44 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=178b951cbabbc81d3bcf00749a7c97964ed20296;hp=41c159ad750e969516f9b5fb4b7edeb5633eff7e;p=yangtools.git Checkstyle clean up about 200 trivial violation I've intentionally started with the very simple formatting type changes here. This does not take care of everything yet, but it's a start. Hopefully sending a few batches also makes it easier (AssertionError e) {to review. Change-Id: Ibf328746c6880138a56eb36837bc8e789647b9bd Signed-off-by: Michael Vorburger --- diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java index 1ddd53df23..1cabaf4e3f 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java @@ -33,7 +33,7 @@ public final class ClassLoaderUtils { /** * Runs {@link Supplier} with provided {@link ClassLoader}. * - * Invokes supplies function and makes sure that original {@link ClassLoader} + *

Invokes supplies function and makes sure that original {@link ClassLoader} * is context {@link ClassLoader} after execution. * * @param cls {@link ClassLoader} to be used. @@ -85,14 +85,9 @@ public final class ClassLoaderUtils { } /** - * * Loads class using this supplied classloader. * - * - * @param cls * @param name String name of class. - * @return - * @throws ClassNotFoundException */ public static Class loadClass(final ClassLoader cls, final String name) throws ClassNotFoundException { if ("byte[]".equals(name)) { @@ -148,10 +143,12 @@ public final class ClassLoaderUtils { } public static Class

findFirstGenericArgument(final Class scannedClass, final Class genericType) { - return withClassLoader(scannedClass.getClassLoader(), ClassLoaderUtils.findFirstGenericArgumentTask(scannedClass, genericType)); + return withClassLoader(scannedClass.getClassLoader(), + ClassLoaderUtils.findFirstGenericArgumentTask(scannedClass, genericType)); } - private static Supplier> findFirstGenericArgumentTask(final Class scannedClass, final Class genericType) { + private static Supplier> findFirstGenericArgumentTask(final Class scannedClass, + final Class genericType) { return new Supplier>() { @Override @SuppressWarnings("unchecked") diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ConcurrentDurationStatisticsTracker.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ConcurrentDurationStatisticsTracker.java index a06abbe257..085805af73 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ConcurrentDurationStatisticsTracker.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ConcurrentDurationStatisticsTracker.java @@ -16,10 +16,15 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; */ // TODO: once DurationStatsTracker is gone make this class final class ConcurrentDurationStatisticsTracker extends DurationStatisticsTracker { - private static final AtomicReferenceFieldUpdater LONGEST_UPDATER = - AtomicReferenceFieldUpdater.newUpdater(ConcurrentDurationStatisticsTracker.class, DurationWithTime.class, "longest"); - private static final AtomicReferenceFieldUpdater SHORTEST_UPDATER = - AtomicReferenceFieldUpdater.newUpdater(ConcurrentDurationStatisticsTracker.class, DurationWithTime.class, "shortest"); + + private static final AtomicReferenceFieldUpdater + LONGEST_UPDATER = AtomicReferenceFieldUpdater.newUpdater(ConcurrentDurationStatisticsTracker.class, + DurationWithTime.class, "longest"); + + private static final AtomicReferenceFieldUpdater + SHORTEST_UPDATER = AtomicReferenceFieldUpdater.newUpdater(ConcurrentDurationStatisticsTracker.class, + DurationWithTime.class, "shortest"); + private static final AtomicLongFieldUpdater COUNT_UPDATER = AtomicLongFieldUpdater.newUpdater(ConcurrentDurationStatisticsTracker.class, "count"); private static final AtomicLongFieldUpdater SUM_UPDATER = diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/DurationStatisticsTracker.java b/common/util/src/main/java/org/opendaylight/yangtools/util/DurationStatisticsTracker.java index 810111d86b..a551642e39 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/DurationStatisticsTracker.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/DurationStatisticsTracker.java @@ -205,23 +205,23 @@ public abstract class DurationStatisticsTracker { private static String abbreviate(final TimeUnit unit) { switch (unit) { - case NANOSECONDS: - return "ns"; - case MICROSECONDS: - return "\u03bcs"; // μs - case MILLISECONDS: - return "ms"; - case SECONDS: - return "s"; - case MINUTES: - return "m"; - case HOURS: - return "h"; - case DAYS: - return "d"; - default: - LOG.warn("Unhandled time unit {}", unit); - return ""; + case NANOSECONDS: + return "ns"; + case MICROSECONDS: + return "\u03bcs"; // μs + case MILLISECONDS: + return "ms"; + case SECONDS: + return "s"; + case MINUTES: + return "m"; + case HOURS: + return "h"; + case DAYS: + return "d"; + default: + LOG.warn("Unhandled time unit {}", unit); + return ""; } } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java index 429bb0bd0c..cc5c38cbb1 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java @@ -91,7 +91,7 @@ public final class ExecutorServiceUtil { if (!executor.awaitTermination(timeout, unit)) { executor.shutdownNow(); } - } catch( InterruptedException e ) { + } catch (InterruptedException e) { executor.shutdownNow(); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/HashCodeBuilder.java b/common/util/src/main/java/org/opendaylight/yangtools/util/HashCodeBuilder.java index f629ee53a9..541ae5540c 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/HashCodeBuilder.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/HashCodeBuilder.java @@ -17,14 +17,13 @@ import org.opendaylight.yangtools.concepts.Builder; */ public final class HashCodeBuilder implements Builder { /** - * * The value 31 was chosen because it is an odd prime. If it were even and the multiplication * overflowed, information would be lost, as multiplication by 2 is equivalent to shifting. The * advantage of using a prime is less clear, but it is traditional. A nice property of 31 is * that the multiplication can be replaced by a shift and a subtraction for better performance: * 31 * i == (i << 5) - i. Modern VMs do this sort of optimization automatically. * - * (from Joshua Bloch's Effective Java, Chapter 3, Item 9: Always override hashcode when you + *

(from Joshua Bloch's Effective Java, Chapter 3, Item 9: Always override hashcode when you * override equals, page 48) */ private static final int PRIME = 31; diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/Identifiables.java b/common/util/src/main/java/org/opendaylight/yangtools/util/Identifiables.java index 313cffb0d4..dbeee9bd2e 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/Identifiables.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/Identifiables.java @@ -13,7 +13,9 @@ import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Identifiable; public final class Identifiables { - private static final Function, Object> EXTRACT_IDENTIFIER = new Function, Object>() { + + private static final Function, Object> EXTRACT_IDENTIFIER = + new Function, Object>() { @Override public Object apply(@Nonnull final Identifiable input) { Preconditions.checkNotNull(input); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java index 7f923d6bb3..909ab55833 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java @@ -102,14 +102,18 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase keys, V[] values) throws IOException; /** - * Create an {@link ImmutableOffsetMap} as a copy of an existing map. This is actually not completely true, - * as this method returns an {@link ImmutableMap} for empty and singleton inputs, as those are more memory-efficient. - * This method also recognizes {@link ImmutableOffsetMap} on input, and returns it back without doing anything else. - * It also recognizes {@link MutableOffsetMap} (as returned by {@link #toModifiableMap()}) and makes an efficient - * copy of its contents. All other maps are converted to an {@link ImmutableOffsetMap} with the same iteration - * order as input. + * Create an {@link ImmutableOffsetMap} as a copy of an existing map. This + * is actually not completely true, as this method returns an + * {@link ImmutableMap} for empty and singleton inputs, as those are more + * memory-efficient. This method also recognizes {@link ImmutableOffsetMap} + * on input, and returns it back without doing anything else. It also + * recognizes {@link MutableOffsetMap} (as returned by + * {@link #toModifiableMap()}) and makes an efficient copy of its contents. + * All other maps are converted to an {@link ImmutableOffsetMap} with the + * same iteration order as input. * - * @param m Input map, may not be null. + * @param m + * Input map, may not be null. * @return An isolated, immutable copy of the input map */ @Nonnull public static Map orderedCopyOf(@Nonnull final Map m) { @@ -145,14 +149,18 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase Map unorderedCopyOf(@Nonnull final Map m) { @@ -385,7 +393,8 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase map, final Field field, final Object value) throws IOException { + private static void setField(final ImmutableOffsetMap map, final Field field, final Object value) + throws IOException { try { field.set(map, value); } catch (IllegalArgumentException | IllegalAccessException e) { diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java b/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java index 73e254abe7..da5521f742 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java @@ -28,7 +28,7 @@ public final class Immutables { /** * Determines if object is known to be immutable * - * Note: This method may return false to immutable objects which + *

Note: This method may return false to immutable objects which * immutability is not known, was defined not using concepts term. * * @param o diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java b/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java index e5c21c4161..1aa2c24960 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/LazyCollections.java @@ -33,14 +33,14 @@ public final class LazyCollections { final List ret; switch (list.size()) { - case 0: - return Collections.singletonList(obj); - case 1: - ret = new ArrayList<>(2); - ret.addAll(list); - break; - default: - ret = list; + case 0: + return Collections.singletonList(obj); + case 1: + ret = new ArrayList<>(2); + ret.addAll(list); + break; + default: + ret = list; } ret.add(obj); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java b/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java index 37a780c080..df404a079e 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java @@ -80,10 +80,12 @@ public final class MapAdaptor { return DEFAULT_INSTANCE; } - public static MapAdaptor getInstance(final boolean useSingleton, final int copyMaxItems, final int persistMinItems) { + public static MapAdaptor getInstance(final boolean useSingleton, final int copyMaxItems, + final int persistMinItems) { Preconditions.checkArgument(copyMaxItems >= 0, "copyMaxItems has to be a non-negative integer"); Preconditions.checkArgument(persistMinItems >= 0, "persistMinItems has to be a positive integer"); - Preconditions.checkArgument(persistMinItems <= copyMaxItems, "persistMinItems must be less than or equal to copyMaxItems"); + Preconditions.checkArgument(persistMinItems <= copyMaxItems, + "persistMinItems must be less than or equal to copyMaxItems"); return new MapAdaptor(useSingleton, copyMaxItems, persistMinItems); } @@ -111,9 +113,6 @@ public final class MapAdaptor { /** * Input is treated is supposed to be left unmodified, result must be mutable. - * - * @param input - * @return */ @SuppressWarnings("static-method") public Map takeSnapshot(final Map input) { @@ -134,18 +133,18 @@ public final class MapAdaptor { if (size <= 6) { final int target; switch (size) { - case 0: - case 1: - target = 1; - break; - case 2: - target = 2; - break; - case 3: - target = 4; - break; - default: - target = 8; + case 0: + case 1: + target = 1; + break; + case 2: + target = 2; + break; + case 3: + target = 4; + break; + default: + target = 8; } ret = new HashMap<>(target); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ModifiableMapPhase.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ModifiableMapPhase.java index ddafd8d762..dbf3a72010 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ModifiableMapPhase.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ModifiableMapPhase.java @@ -14,13 +14,18 @@ import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Mutable; /** - * A {@link Map} which can be modified and supports efficient conversion to an unmodifiable map. This interface is the - * logical counterpart to {@link UnmodifiableMapPhase}, but it does not require implementations of {@link #toUnmodifiableMap()} - * to return an implementation of that interface. The reason for that empty and singleton mappings are efficiently - * represented as {@link ImmutableMap}, which does not implement {@link UnmodifiableMapPhase}. + * A {@link Map} which can be modified and supports efficient conversion to an + * unmodifiable map. This interface is the logical counterpart to + * {@link UnmodifiableMapPhase}, but it does not require implementations of + * {@link #toUnmodifiableMap()} to return an implementation of that interface. + * The reason for that empty and singleton mappings are efficiently represented + * as {@link ImmutableMap}, which does not implement + * {@link UnmodifiableMapPhase}. * - * @param the type of keys maintained by this map - * @param the type of mapped values + * @param + * the type of keys maintained by this map + * @param + * the type of mapped values */ @Beta public interface ModifiableMapPhase extends Map, Mutable { diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java index dee904fbe7..c9903d4ab0 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java @@ -35,7 +35,7 @@ import java.util.Set; * * results in source and result sharing the backing objects. * - * This map does not support null keys nor values. + *

This map does not support null keys nor values. * * @param the type of keys maintained by this map * @param the type of mapped values @@ -176,8 +176,11 @@ public abstract class MutableOffsetMap extends AbstractMap implement } abstract Object removedObject(); + abstract UnmodifiableMapPhase modifiedMap(List keys, V[] objects); + abstract UnmodifiableMapPhase unmodifiedMap(Map offsets, V[] objects); + abstract SharedSingletonMap singletonMap(); @Override @@ -390,7 +393,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement try { ret = (MutableOffsetMap) super.clone(); } catch (CloneNotSupportedException e) { - throw new IllegalStateException("Clone is expected to work", e); + throw new IllegalStateException("Clone is expected to work", e); } ret.newKeys = (HashMap) newKeys.clone(); @@ -573,7 +576,8 @@ public abstract class MutableOffsetMap extends AbstractMap implement private final Iterator> oldIterator = offsets.entrySet().iterator(); private final Iterator newIterator = newKeys.keySet().iterator(); private int expectedModCount = modCount; - private K currentKey, nextKey; + private K currentKey; + private K nextKey; AbstractSetIterator() { updateNextKey(); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java index b18c218f21..c3f67e9243 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java @@ -35,7 +35,7 @@ final class OffsetMapCache { public Map load(final List key) { return createMap(key); } - }); + }); /* * Cache for offsets where order does not mapper. The key is a Set of elements. We use manual two-stage loading * because of the nature of the objects we store as values, which is ImmutableMaps. An ImmutableMap, when queried diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java index f860a7b464..6250dd3640 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java @@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory; * their size, and determining the size of a TrieMap is expensive, we make sure * to update it as we go. * - * FIXME: this map does not support modification view the keySet()/values()/entrySet() + *

FIXME: this map does not support modification view the keySet()/values()/entrySet() * methods. * * @param Key type diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java b/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java index ca6415f0e3..29ccab5e40 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java @@ -24,10 +24,9 @@ import javax.annotation.Nonnull; * {@link Collections#unmodifiableCollection(Collection)}, this class checks its * argument to ensure multiple encapsulation does not occur. * - * this class checks + *

This class checks * the argument so it prevents multiple encapsulation. Subclasses of * {@link ImmutableCollection} are also recognized and not encapsulated. - * An attempt is also made to identi * * @param the type of elements in this collection */ diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java index bd0919aecf..0e36b74da3 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java @@ -29,13 +29,13 @@ import org.slf4j.LoggerFactory; * to avoid blocking the thread that completed this task, as a common use case is to pass an * executor that runs tasks in the same thread as the caller (ie MoreExecutors#sameThreadExecutor) * to {@link #addListener}. - *

- * Note: the Executor specified on construction does not replace the Executor specified in + * + *

Note: the Executor specified on construction does not replace the Executor specified in * {@link #addListener}. The latter Executor is still used however, if it is detected that the * listener Runnable would execute in the thread that completed this task, the listener * is executed on Executor specified on construction. * - * Also note that the use of this task may attach some (small) amount of state to the threads + *

Also note that the use of this task may attach some (small) amount of state to the threads * interacting with it. That state will not be detached automatically, but you can use * {@link #cleanStateForCurrentThread()} to clean it up. * @@ -45,13 +45,17 @@ import org.slf4j.LoggerFactory; * @param the Future result value type */ public class AsyncNotifyingListenableFutureTask extends FutureTask implements ListenableFuture { - private static final class DelegatingAsyncNotifyingListenableFutureTask extends AsyncNotifyingListenableFutureTask { + + private static final class DelegatingAsyncNotifyingListenableFutureTask + extends AsyncNotifyingListenableFutureTask { + /** * The executor used to run listener callbacks. */ private final Executor listenerExecutor; - private DelegatingAsyncNotifyingListenableFutureTask(final Callable callable, @Nullable final Executor listenerExecutor) { + private DelegatingAsyncNotifyingListenableFutureTask(final Callable callable, + @Nullable final Executor listenerExecutor) { super(callable); this.listenerExecutor = Preconditions.checkNotNull(listenerExecutor); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java index d57ded358f..024594d0f2 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java @@ -21,23 +21,31 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; /** - * An {@link com.google.common.util.concurrent.ListeningExecutorService} implementation that also allows for an {@link Executor} to be - * specified on construction that is used to execute {@link ListenableFuture} callback Runnables, - * registered via {@link com.google.common.util.concurrent.Futures#addCallback} or {@link ListenableFuture#addListener} directly, - * asynchronously when a task that is run on this executor completes. This is useful when you want - * to guarantee listener callback executions are off-loaded onto another thread to avoid blocking - * the thread that completed the task, as a common use case is to pass an executor that runs tasks - * in the same thread as the caller (ie MoreExecutors#sameThreadExecutor}) to + * An {@link com.google.common.util.concurrent.ListeningExecutorService} + * implementation that also allows for an {@link Executor} to be specified on + * construction that is used to execute {@link ListenableFuture} callback + * Runnables, registered via + * {@link com.google.common.util.concurrent.Futures#addCallback} or + * {@link ListenableFuture#addListener} directly, asynchronously when a task + * that is run on this executor completes. This is useful when you want to + * guarantee listener callback executions are off-loaded onto another thread to + * avoid blocking the thread that completed the task, as a common use case is to + * pass an executor that runs tasks in the same thread as the caller (ie + * MoreExecutors#sameThreadExecutor}) to * {@link ListenableFuture#addListener}. + * *

- * Most commonly, this class would be used in lieu of MoreExecutors#listeningDecorator - * when the underlying delegate Executor is single-threaded, in which case, you may not want - * ListenableFuture callbacks to block the single thread. + * Most commonly, this class would be used in lieu of + * MoreExecutors#listeningDecorator when the underlying delegate + * Executor is single-threaded, in which case, you may not want ListenableFuture + * callbacks to block the single thread. + * *

- * Note: the Executor specified on construction does not replace the Executor specified in - * {@link ListenableFuture#addListener}. The latter Executor is still used however, if it is - * detected that the listener Runnable would execute in the thread that completed the task, the - * listener is executed on Executor specified on construction. + * Note: the Executor specified on construction does not replace the Executor + * specified in {@link ListenableFuture#addListener}. The latter Executor is + * still used however, if it is detected that the listener Runnable would + * execute in the thread that completed the task, the listener is executed on + * Executor specified on construction. * * @author Thomas Pantelis * @see AsyncNotifyingListenableFutureTask diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java index 7f2e77f731..2ef1cd8396 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java @@ -22,8 +22,8 @@ import java.util.concurrent.TimeUnit; /** * A ThreadPoolExecutor with a specified bounded queue capacity that favors reusing previously * constructed threads, when they are available, over creating new threads. - *

- * See {@link SpecialExecutors#newBoundedCachedThreadPool} for more details. + * + *

See {@link SpecialExecutors#newBoundedCachedThreadPool} for more details. * * @author Thomas Pantelis */ @@ -50,7 +50,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { * @param threadPrefix * the name prefix for threads created by this executor. */ - public CachedThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix ) { + public CachedThreadPoolExecutor(final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix) { // We're using a custom SynchronousQueue that has a backing bounded LinkedBlockingQueue. // We don't specify any core threads (first parameter) so, when a task is submitted, // the base class will always try to offer to the queue. If there is an existing waiting @@ -204,7 +204,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler; } - RejectedExecutionHandler getDelegateRejectedExecutionHandler(){ + RejectedExecutionHandler getDelegateRejectedExecutionHandler() { return delegateRejectedExecutionHandler; } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java index 2cfdba290f..8cdbc2c413 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java @@ -24,8 +24,8 @@ import javax.annotation.Nullable; /** * An implementation of ListeningExecutorService that attempts to detect deadlock scenarios that * could occur if clients invoke the returned Future's get methods synchronously. - *

- * Deadlock scenarios are most apt to occur with a backing single-threaded executor where setting of + * + *

Deadlock scenarios are most apt to occur with a backing single-threaded executor where setting of * the Future's result is executed on the single thread. Here's a scenario: *

    *
  • Client code is currently executing in an executor's single thread.
  • @@ -35,13 +35,13 @@ import javax.annotation.Nullable; * The second submitted task will never execute since the single thread is currently executing * the client code which is blocked waiting for the submitted task to complete. Thus, deadlock has * occurred. - *

    - * This class prevents this scenario via the use of a ThreadLocal variable. When a task is invoked, + * + *

    This class prevents this scenario via the use of a ThreadLocal variable. When a task is invoked, * the ThreadLocal is set and, when a task completes, the ThreadLocal is cleared. Futures returned * from this class override the get methods to check if the ThreadLocal is set. If it is, * an ExecutionException is thrown with a custom cause. * - * Note that the ThreadLocal is not removed automatically, so some state may be left hanging off of + *

    Note that the ThreadLocal is not removed automatically, so some state may be left hanging off of * threads which have encountered this class. If you need to clean that state up, use * {@link #cleanStateForCurrentThread()}. * diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java index 88cf7537e6..1616cd24aa 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java @@ -14,20 +14,28 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; /** - * Utility exception mapper which translates an Exception to a specified type of Exception. + * Utility exception mapper which translates an Exception to a specified type of + * Exception. * - * This mapper is intended to be used with {@link com.google.common.util.concurrent.Futures#makeChecked(com.google.common.util.concurrent.ListenableFuture, Function)} + *

    + * This mapper is intended to be used with + * {@link com.google.common.util.concurrent.Futures#makeChecked(com.google.common.util.concurrent.ListenableFuture, Function)} *

      - *
    • if exception is the specified type or one of its subclasses, it returns original exception. - *
    • if exception is {@link ExecutionException} and the cause is of the specified type, it returns the cause - *
    • otherwise returns an instance of the specified exception type with original exception as the cause. + *
    • if exception is the specified type or one of its subclasses, it returns + * original exception. + *
    • if exception is {@link ExecutionException} and the cause is of the + * specified type, it returns the cause + *
    • otherwise returns an instance of the specified exception type with + * original exception as the cause. *
    * * @author Thomas Pantelis * - * @param the exception type + * @param + * the exception type */ public abstract class ExceptionMapper implements Function { + private final Class exceptionType; private final String opName; diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/FastThreadPoolExecutor.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/FastThreadPoolExecutor.java index f46dcbcd5c..24fb7b8274 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/FastThreadPoolExecutor.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/FastThreadPoolExecutor.java @@ -17,8 +17,8 @@ import java.util.concurrent.TimeUnit; /** * A ThreadPoolExecutor with a specified bounded queue capacity that favors creating new threads * over queuing, as the former is faster. - *

    - * See {@link SpecialExecutors#newBoundedFastThreadPool} for more details. + * + *

    See {@link SpecialExecutors#newBoundedFastThreadPool} for more details. * * @author Thomas Pantelis */ diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java index 571411d24f..7e89be8199 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java @@ -20,11 +20,11 @@ import java.util.concurrent.TimeoutException; /** * An implementation of CheckedFuture that provides similar behavior for the get methods * that the checkedGet methods provide. - *

    - * For {@link CancellationException} and {@link InterruptedException}, the specified exception mapper + * + *

    For {@link CancellationException} and {@link InterruptedException}, the specified exception mapper * is invoked to translate them to the checked exception type. - *

    - * For {@link ExecutionException}, the mapper is invoked to translate the cause to the checked exception + * + *

    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 @@ -67,12 +67,12 @@ public final class MappingCheckedFuture extends Abstract public V get() throws InterruptedException, ExecutionException { try { return super.get(); - } catch( final InterruptedException e ) { + } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw wrapInExecutionException( "Operation was interrupted", e ); - } catch( final CancellationException e ) { + } catch (final CancellationException e) { throw wrapInExecutionException( "Operation was cancelled", e ); - } catch( final ExecutionException e ) { + } catch (final ExecutionException e) { throw wrapInExecutionException( e.getMessage(), e ); } } @@ -82,12 +82,12 @@ public final class MappingCheckedFuture extends Abstract throws InterruptedException, ExecutionException, TimeoutException { try { return super.get( timeout, unit ); - } catch( final InterruptedException e ) { + } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw wrapInExecutionException( "Operation was interrupted", e ); - } catch( final CancellationException e ) { + } catch (final CancellationException e) { throw wrapInExecutionException( "Operation was cancelled", e ); - } catch( final ExecutionException e ) { + } catch (final ExecutionException e) { throw wrapInExecutionException( e.getMessage(), e ); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/NotificationManager.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/NotificationManager.java index aee3c99676..a184ec6790 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/NotificationManager.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/NotificationManager.java @@ -22,8 +22,8 @@ public interface NotificationManager { /** * Submits a notification to be queued and dispatched to the given listener. - *

    - * Note: This method may block if the listener queue is currently full. + * + *

    Note: This method may block if the listener queue is currently full. * * @param listener the listener to notify * @param notification the notification to dispatch @@ -33,8 +33,8 @@ public interface NotificationManager { /** * Submits notifications to be queued and dispatched to the given listener. - *

    - * Note: This method may block if the listener queue is currently full. + * + *

    Note: This method may block if the listener queue is currently full. * * @param listener the listener to notify * @param notifications the notifications to dispatch @@ -42,4 +42,4 @@ public interface NotificationManager { */ void submitNotifications( final L listener, Iterable notifications); -} \ No newline at end of file +} diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java index 09d867b15c..90783f2cdc 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java @@ -29,8 +29,8 @@ import org.slf4j.LoggerFactory; * This class manages queuing and dispatching notifications for multiple listeners concurrently. * Notifications are queued on a per-listener basis and dispatched serially to each listener via an * {@link Executor}. - *

    - * This class optimizes its memory footprint by only allocating and maintaining a queue and executor + * + *

    This class optimizes its memory footprint by only allocating and maintaining a queue and executor * task for a listener when there are pending notifications. On the first notification(s), a queue * is created and a task is submitted to the executor to dispatch the queue to the associated * listener. Any subsequent notifications that occur before all previous notifications have been @@ -172,7 +172,7 @@ public class QueuedNotificationManager implements NotificationManager break; } } - } catch( InterruptedException e ) { + } catch (InterruptedException e) { // We were interrupted trying to offer to the listener's queue. Somebody's probably // telling us to quit. @@ -204,14 +204,14 @@ public class QueuedNotificationManager implements NotificationManager /** * Returns the maximum listener queue capacity. */ - public int getMaxQueueCapacity(){ + public int getMaxQueueCapacity() { return maxQueueCapacity; } /** * Returns the {@link Executor} to used for notification tasks. */ - public Executor getExecutor(){ + public Executor getExecutor() { return executor; } @@ -226,7 +226,7 @@ public class QueuedNotificationManager implements NotificationManager private final L listener; - public ListenerKey( L listener ) { + ListenerKey( L listener ) { this.listener = listener; } @@ -315,19 +315,18 @@ public class QueuedNotificationManager implements NotificationManager } LOG.warn( - "{}: Timed out trying to offer a notification to the queue for listener {} " + - "on attempt {} of {}. " + - "The queue has reached its capacity of {}", - name, listenerKey.toString(), notificationOfferAttempts, MAX_NOTIFICATION_OFFER_ATTEMPTS, - maxQueueCapacity ); + "{}: Timed out trying to offer a notification to the queue for listener {} " + + "on attempt {} of {}. " + "The queue has reached its capacity of {}", + name, listenerKey.toString(), notificationOfferAttempts, + MAX_NOTIFICATION_OFFER_ATTEMPTS, maxQueueCapacity); } if (!notificationOfferAttemptSuccess) { LOG.warn( - "{}: Failed to offer a notification to the queue for listener {}. " + - "Exceeded max allowable attempts of {} in {} minutes; the listener " + - "is likely in an unrecoverable state (deadlock or endless loop).", - name, listenerKey.toString(), MAX_NOTIFICATION_OFFER_ATTEMPTS, - MAX_NOTIFICATION_OFFER_ATTEMPTS ); + "{}: Failed to offer a notification to the queue for listener {}. " + + "Exceeded max allowable attempts of {} in {} minutes; the listener " + + "is likely in an unrecoverable state (deadlock or endless loop).", + name, listenerKey.toString(), MAX_NOTIFICATION_OFFER_ATTEMPTS, + MAX_NOTIFICATION_OFFER_ATTEMPTS); } } @@ -389,7 +388,7 @@ public class QueuedNotificationManager implements NotificationManager notifyListener( notification ); } - } catch( InterruptedException e ) { + } catch (InterruptedException e) { // The executor is probably shutting down so log as debug. LOG.debug( "{}: Interrupted trying to remove from {} listener's queue", @@ -418,7 +417,7 @@ public class QueuedNotificationManager implements NotificationManager listenerInvoker.invokeListener( listenerKey.getListener(), notification ); - } catch( RuntimeException e ) { + } catch (RuntimeException e ) { // We'll let a RuntimeException from the listener slide and keep sending any // remaining notifications. @@ -426,7 +425,7 @@ public class QueuedNotificationManager implements NotificationManager LOG.error( String.format( "%1$s: Error notifying listener %2$s", name, listenerKey.toString() ), e ); - } catch( Error e ) { + } catch (Error e) { // A JVM Error is severe - best practice is to throw them up the chain. Set done to // true so no new notifications can be added to this task as we're about to bail. diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java index d49f80662d..b00ed4f304 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java @@ -45,7 +45,8 @@ public final class ReflectiveExceptionMapper extends Except * @throws IllegalArgumentException when the supplied exception class does not pass sanity checks * @throws SecurityException when the required constructor is not accessible */ - public static ReflectiveExceptionMapper create(final String opName, final Class exceptionType) throws SecurityException { + public static ReflectiveExceptionMapper create(final String opName, + final Class exceptionType) throws SecurityException { final Constructor c; try { c = exceptionType.getConstructor(String.class, Throwable.class); @@ -55,7 +56,8 @@ public final class ReflectiveExceptionMapper extends Except try { c.newInstance(opName, new Throwable()); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { throw new IllegalArgumentException("Constructor " + c.getName() + " failed to pass instantiation test", e); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java index 110ac1eeda..929ecc0106 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java @@ -26,17 +26,17 @@ public final class SpecialExecutors { * threads over queuing, as the former is faster, so threads will only be reused when the thread * limit is exceeded and tasks are queued. If the maximum queue capacity is reached, subsequent * tasks will be rejected. - *

    - * For example, if the maximum number of threads is 100 and 100 short-lived tasks are submitted + * + *

    For example, if the maximum number of threads is 100 and 100 short-lived tasks are submitted * within say 10 seconds, then 100 threads will be created and used - previously constructed * idle threads will not be reused. This provides the fastest execution of the 100 tasks at the * expense of memory and thread resource overhead. Therefore it is advisable to specify a * relatively small thread limit (probably no more than 50). - *

    - * Threads that have not been used for 15 seconds are terminated and removed from the pool. + * + *

    Threads that have not been used for 15 seconds are terminated and removed from the pool. * Thus, a pool that remains idle for long enough will not consume any resources. - *

    - * If you need an executor with less memory and thread resource overhead where slower execution + * + *

    If you need an executor with less memory and thread resource overhead where slower execution * time is acceptable, consider using {@link #newBoundedCachedThreadPool }. * * @param maximumPoolSize @@ -85,14 +85,14 @@ public final class SpecialExecutors { * thread to execute. If the specified maximum thread limit is reached, subsequent tasks will be * queued and will execute as threads become available. If the maximum queue capacity is * reached, subsequent tasks will be rejected. - *

    - * Threads that have not been used for sixty seconds are terminated and removed from the pool. + * + *

    Threads that have not been used for sixty seconds are terminated and removed from the pool. * Thus, a pool that remains idle for long enough will not consume any resources. - *

    - * By reusing threads when possible, this executor optimizes for reduced memory and thread + * + *

    By reusing threads when possible, this executor optimizes for reduced memory and thread * resource overhead at the expense of execution time. - *

    - * If you need an executor with faster execution time where increased memory and thread resource + * + *

    If you need an executor with faster execution time where increased memory and thread resource * overhead is acceptable, consider using {@link #newBoundedFastThreadPool }. * * @param maximumPoolSize diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java index 0a0f54da50..546dec3d65 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java @@ -22,13 +22,15 @@ import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; * @param the element t.ype */ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { - @SuppressWarnings("rawtypes") - private static final AtomicIntegerFieldUpdater LARGEST_QUEUE_SIZE_UPDATER = AtomicIntegerFieldUpdater.newUpdater(TrackingLinkedBlockingQueue.class, "largestQueueSize"); private static final long serialVersionUID = 1L; + @SuppressWarnings("rawtypes") + private static final AtomicIntegerFieldUpdater LARGEST_QUEUE_SIZE_UPDATER + = AtomicIntegerFieldUpdater.newUpdater(TrackingLinkedBlockingQueue.class, "largestQueueSize"); + /** * Holds largestQueueSize, this long field should be only accessed - * using {@link #LARGEST_QUEUE_SIZE_UPDATER} + * using {@link #LARGEST_QUEUE_SIZE_UPDATER}. */ private volatile int largestQueueSize = 0; @@ -56,7 +58,7 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { /** * Returns the largest queue size. * - * FIXME: the this return will be changed to int in a future release. + *

    FIXME: the this return will be changed to int in a future release. */ @Beta public long getLargestQueueSize() { @@ -64,7 +66,7 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override - public boolean offer( final E e, final long timeout, final TimeUnit unit ) throws InterruptedException { + public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException { if (super.offer( e, timeout, unit ) ) { updateLargestQueueSize(); return true; @@ -74,7 +76,7 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override - public boolean offer( final E e ) { + public boolean offer(final E e) { if (super.offer( e ) ) { updateLargestQueueSize(); return true; @@ -90,14 +92,14 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override - public boolean add( final E e ) { + public boolean add(final E e) { boolean result = super.add( e ); updateLargestQueueSize(); return result; } @Override - public boolean addAll( final Collection c ) { + public boolean addAll(final Collection c) { try { return super.addAll( c ); } finally { diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java index 5cde0d0c70..11aac6ccf0 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java @@ -67,36 +67,42 @@ public class ConstantArrayCollectionTest { c.add(null); fail(); } catch (UnsupportedOperationException e) { + // OK } try { c.remove(null); fail(); } catch (UnsupportedOperationException e) { + // OK } try { c.addAll(null); fail(); } catch (UnsupportedOperationException e) { + // OK } try { c.removeAll(null); fail(); } catch (UnsupportedOperationException e) { + // OK } try { c.retainAll(null); fail(); } catch (UnsupportedOperationException e) { + // OK } try { c.clear(); fail(); } catch (UnsupportedOperationException e) { + // OK } } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java index b5f0f50f6a..fad0f29da7 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java @@ -51,7 +51,7 @@ public class OffsetMapTest { OffsetMapCache.invalidateCache(); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testWrongImmutableConstruction() { new ImmutableOffsetMap.Ordered<>(Collections.emptyMap(), new String[1]); } @@ -127,18 +127,21 @@ public class OffsetMapTest { map.values().add("v1"); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.values().remove("v1"); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.values().clear(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { @@ -147,24 +150,28 @@ public class OffsetMapTest { it.remove(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.keySet().add("k1"); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.keySet().clear(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.keySet().remove("k1"); fail(); } catch (UnsupportedOperationException e) { + // OK } try { @@ -173,24 +180,28 @@ public class OffsetMapTest { it.remove(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.entrySet().clear(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.entrySet().add(new SimpleEntry<>("k1", "v1")); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.entrySet().remove(new SimpleEntry<>("k1", "v1")); fail(); } catch (UnsupportedOperationException e) { + // OK } try { @@ -199,30 +210,35 @@ public class OffsetMapTest { it.remove(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.clear(); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.put("k1", "fail"); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.putAll(ImmutableMap.of("k1", "fail")); fail(); } catch (UnsupportedOperationException e) { + // OK } try { map.remove("k1"); fail(); } catch (UnsupportedOperationException e) { + // OK } } @@ -314,7 +330,8 @@ public class OffsetMapTest { mutable.remove("non-existent"); // Resulting map should be equal, but not the same object - final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable.toUnmodifiableMap(); + final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable + .toUnmodifiableMap(); assertNotSame(source, result); assertEquals(source, result); @@ -331,7 +348,8 @@ public class OffsetMapTest { mutable.remove("k1"); mutable.put("k1", "v1"); - final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable.toUnmodifiableMap(); + final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable + .toUnmodifiableMap(); assertTrue(source.equals(result)); assertTrue(result.equals(source)); @@ -347,7 +365,8 @@ public class OffsetMapTest { mutable.remove("k1"); mutable.put("k1", "v1"); - final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable.toUnmodifiableMap(); + final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable + .toUnmodifiableMap(); assertEquals(source, result); // Only offsets should be shared @@ -461,7 +480,8 @@ public class OffsetMapTest { mutable.put("k1", "replaced"); - final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable.toUnmodifiableMap(); + final ImmutableOffsetMap result = (ImmutableOffsetMap) mutable + .toUnmodifiableMap(); final Map reference = ImmutableMap.of("k1", "replaced", "k2", "v2"); assertEquals(reference, result); @@ -497,7 +517,8 @@ public class OffsetMapTest { assertTrue(result.needClone()); // Forced copy, no cloning needed, but maps are equal - final ImmutableOffsetMap immutable = (ImmutableOffsetMap) source.toUnmodifiableMap(); + final ImmutableOffsetMap immutable = (ImmutableOffsetMap) source + .toUnmodifiableMap(); assertFalse(source.needClone()); assertTrue(source.equals(immutable)); assertTrue(immutable.equals(source)); @@ -531,7 +552,8 @@ public class OffsetMapTest { assertTrue(result.needClone()); // Creates a immutable view, which shares the array - final ImmutableOffsetMap immutable = (ImmutableOffsetMap) source.toUnmodifiableMap(); + final ImmutableOffsetMap immutable = (ImmutableOffsetMap) source + .toUnmodifiableMap(); assertTrue(source.needClone()); assertSame(source.array(), immutable.objects()); } @@ -564,16 +586,19 @@ public class OffsetMapTest { it.hasNext(); fail(); } catch (ConcurrentModificationException e) { + // OK } try { it.next(); fail(); } catch (ConcurrentModificationException e) { + // OK } try { it.remove(); fail(); } catch (ConcurrentModificationException e) { + // OK } } @@ -605,6 +630,7 @@ public class OffsetMapTest { it.remove(); fail(); } catch (IllegalStateException e) { + // OK } assertTrue(it.hasNext()); @@ -618,6 +644,7 @@ public class OffsetMapTest { it.next(); fail(); } catch (NoSuchElementException e) { + // OK } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java index 0ae958ff11..44f90f9884 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java @@ -47,7 +47,7 @@ public class ThreadPoolExecutorTest { 100000, "TestPool", 0 ); } - @Test(expected=RejectedExecutionException.class) + @Test(expected = RejectedExecutionException.class) public void testFastThreadPoolRejectingTask() throws Exception { executor = SpecialExecutors.newBoundedFastThreadPool( 1, 1, "TestPool" ); @@ -75,7 +75,7 @@ public class ThreadPoolExecutorTest { 100000, "TestPool", 0 ); } - @Test(expected=RejectedExecutionException.class) + @Test(expected = RejectedExecutionException.class) public void testCachedThreadRejectingTask() throws Exception { ExecutorService executor = SpecialExecutors.newBoundedCachedThreadPool( 1, 1, "TestPool" ); @@ -99,8 +99,7 @@ public class ThreadPoolExecutorTest { this.executor = executor; - System.out.println( "\nTesting " + executor.getClass().getSimpleName() + " with " + - numTasksToRun + " tasks." ); + System.out.println("\nTesting " + executor.getClass().getSimpleName() + " with " + numTasksToRun + " tasks."); final CountDownLatch tasksRunLatch = new CountDownLatch( numTasksToRun ); final ConcurrentMap taskCountPerThread = new ConcurrentHashMap<>(); @@ -127,8 +126,7 @@ public class ThreadPoolExecutorTest { stopWatch.stop(); if (!done) { - fail( (numTasksToRun - tasksRunLatch.getCount()) + " tasks out of " + - numTasksToRun + " executed" ); + fail((numTasksToRun - tasksRunLatch.getCount()) + " tasks out of " + numTasksToRun + " executed"); } if (threadError.get() != null) { @@ -181,7 +179,8 @@ public class ThreadPoolExecutorTest { } else if (blockLatch != null) { blockLatch.await(); } - } catch( InterruptedException e ) {} + } catch (InterruptedException e) { + } if (expThreadPrefix != null) { assertEquals( "Thread name starts with " + expThreadPrefix, true, @@ -201,7 +200,7 @@ public class ThreadPoolExecutorTest { count.incrementAndGet(); } - } catch( AssertionError e ) { + } catch (AssertionError e) { if (threadError != null) { threadError.set( e ); }