This removes run-time reliance on javax.annotation package.
Change-Id: I59193dbe7fcf472fbab29099b685df669c3b301a
JIRA: YANGTOOLS-907
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifier;
/**
public abstract class AbstractIdentifier<T> implements Identifier {
private static final long serialVersionUID = 1L;
- private final T value;
+ private final @NonNull T value;
- public AbstractIdentifier(final T value) {
+ public AbstractIdentifier(final @NonNull T value) {
this.value = requireNonNull(value);
}
- public final T getValue() {
+ public final @NonNull T getValue() {
return value;
}
}
@Override
- public final String toString() {
+ public final @NonNull String toString() {
return MoreObjects.toStringHelper(this).add("value", value).toString();
}
}
import com.google.common.annotations.Beta;
import java.util.UUID;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifier;
/**
extends AbstractIdentifier<String> implements Comparable<T> {
private static final long serialVersionUID = 1L;
- protected AbstractStringIdentifier(final String string) {
+ protected AbstractStringIdentifier(final @NonNull String string) {
super(string);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final int compareTo(@Nonnull final T o) {
+ public final int compareTo(final T o) {
return getValue().compareTo(o.getValue());
}
}
import com.google.common.annotations.Beta;
import java.util.UUID;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifier;
/**
implements Comparable<T> {
private static final long serialVersionUID = 1L;
- protected AbstractUUIDIdentifier(final UUID uuid) {
+ protected AbstractUUIDIdentifier(final @NonNull UUID uuid) {
super(uuid);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final int compareTo(@Nonnull final T o) {
+ public final int compareTo(final T o) {
return getValue().compareTo(o.getValue());
}
}
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
/**
* Internal array-backed {@link List}. It assumes the array does not contain nulls and it does not get modified
*/
final class ConstantArrayCollection<E> implements Collection<E>, Serializable {
private static final long serialVersionUID = 1L;
- private final E[] array;
+ private final E @NonNull[] array;
- ConstantArrayCollection(final E[] array) {
+ ConstantArrayCollection(final E @NonNull[] array) {
this.array = requireNonNull(array);
}
return false;
}
- @Nonnull
@Override
- public Iterator<E> iterator() {
+ public @NonNull Iterator<E> iterator() {
return new UnmodifiableIterator<E>() {
private int offset = 0;
};
}
- @Nonnull
@Override
- public Object[] toArray() {
+ public @NonNull Object[] toArray() {
return array.clone();
}
- @Nonnull
@SuppressWarnings({ "unchecked", "checkstyle:parameterName" })
@Override
- public <T> T[] toArray(@Nonnull final T[] a) {
+ public <T> T[] toArray(final T[] a) {
if (a.length < array.length) {
return Arrays.copyOf(array, array.length, (Class<T[]>)a.getClass().getComponentType());
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean containsAll(@Nonnull final Collection<?> c) {
+ public boolean containsAll(final Collection<?> c) {
for (Object o : c) {
if (!contains(o)) {
return false;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean addAll(@Nonnull final Collection<? extends E> c) {
+ public boolean addAll(final Collection<? extends E> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean removeAll(@Nonnull final Collection<?> c) {
+ public boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean retainAll(@Nonnull final Collection<?> c) {
+ public boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
}
@Override
- public String toString() {
+ public @NonNull String toString() {
if (array.length == 0) {
return "[]";
}
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private static final Logger LOG = LoggerFactory.getLogger(ExecutorServiceUtil.class);
- private static final RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler();
+ private static final @NonNull RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler();
private ExecutorServiceUtil() {
throw new UnsupportedOperationException("Utility class");
* @param delegate Backing blocking queue.
* @return A new blocking queue backed by the delegate
*/
- public static <E> BlockingQueue<E> offerFailingBlockingQueue(final BlockingQueue<E> delegate) {
+ public static <E> @NonNull BlockingQueue<E> offerFailingBlockingQueue(final BlockingQueue<E> delegate) {
return new ForwardingBlockingQueue<E>() {
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean offer(@Nonnull final E o) {
+ public boolean offer(final E o) {
return false;
}
*
* @return A shared RejectedExecutionHandler instance.
*/
- public static RejectedExecutionHandler waitInQueueExecutionHandler() {
+ public static @NonNull RejectedExecutionHandler waitInQueueExecutionHandler() {
return WAIT_IN_QUEUE_HANDLER;
}
* timeout period. If the timeout elapses before termination, the executor is forcefully
* shutdown.
*/
- public static void tryGracefulShutdown(final ExecutorService executor, final long timeout, final TimeUnit unit) {
-
+ public static void tryGracefulShutdown(final @NonNull ExecutorService executor, final long timeout,
+ final @NonNull TimeUnit unit) {
executor.shutdown();
try {
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
/**
static final class Ordered<K, V> extends ImmutableOffsetMap<K, V> {
private static final long serialVersionUID = 1L;
- Ordered(final Map<K, Integer> offsets, final V[] objects) {
+ Ordered(final @NonNull Map<K, Integer> offsets, final @NonNull V[] objects) {
super(offsets, objects);
}
- @Nonnull
@Override
- public MutableOffsetMap<K, V> toModifiableMap() {
+ public @NonNull MutableOffsetMap<K, V> toModifiableMap() {
return MutableOffsetMap.orderedCopyOf(this);
}
super(offsets, objects);
}
- @Nonnull
@Override
- public MutableOffsetMap<K, V> toModifiableMap() {
+ public @NonNull MutableOffsetMap<K, V> toModifiableMap() {
return MutableOffsetMap.unorderedCopyOf(this);
}
private static final long serialVersionUID = 1L;
- private final transient Map<K, Integer> offsets;
- private final transient V[] objects;
+ private final transient @NonNull Map<K, Integer> offsets;
+ private final transient @NonNull V[] objects;
private transient int hashCode;
/**
* @param objects Array of value object, may not be null. The array is stored as is, the caller
* is responsible for ensuring its contents remain unmodified.
*/
- ImmutableOffsetMap(@Nonnull final Map<K, Integer> offsets, @Nonnull final V[] objects) {
+ ImmutableOffsetMap(final @NonNull Map<K, Integer> offsets, final @NonNull V[] objects) {
this.offsets = requireNonNull(offsets);
this.objects = requireNonNull(objects);
checkArgument(offsets.size() == objects.length);
}
- @Nonnull
@Override
- public abstract MutableOffsetMap<K, V> toModifiableMap();
+ public abstract @NonNull MutableOffsetMap<K, V> toModifiableMap();
abstract void setFields(List<K> keys, V[] values) throws IOException;
* Input map, may not be null.
* @return An isolated, immutable copy of the input map
*/
- @Nonnull public static <K, V> Map<K, V> orderedCopyOf(@Nonnull final Map<K, V> map) {
+ public static <K, V> @NonNull Map<K, V> orderedCopyOf(final @NonNull Map<K, V> map) {
final Map<K, V> common = commonCopy(map);
if (common != null) {
return common;
* Input map, may not be null.
* @return An isolated, immutable copy of the input map
*/
- @Nonnull public static <K, V> Map<K, V> unorderedCopyOf(@Nonnull final Map<K, V> map) {
+ public static <K, V> @NonNull Map<K, V> unorderedCopyOf(final @NonNull Map<K, V> map) {
final Map<K, V> common = commonCopy(map);
if (common != null) {
return common;
return new Unordered<>(offsets, array);
}
- private static <K, V> @Nullable Map<K, V> commonCopy(@Nonnull final Map<K, V> map) {
+ private static <K, V> @Nullable Map<K, V> commonCopy(final @NonNull Map<K, V> map) {
// Prevent a copy. Note that ImmutableMap is not listed here because of its potentially larger keySet overhead.
if (map instanceof ImmutableOffsetMap || map instanceof SharedSingletonMap) {
return map;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+ public final void putAll(final Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
return offsets.keySet();
}
- @Nonnull
@Override
- public final Collection<V> values() {
+ public final @NonNull Collection<V> values() {
return new ConstantArrayCollection<>(objects);
}
- @Nonnull
@Override
- public final Set<Entry<K, V>> entrySet() {
+ public final @NonNull Set<Entry<K, V>> entrySet() {
return new EntrySet();
}
return sb.append('}').toString();
}
- final Map<K, Integer> offsets() {
+ final @NonNull Map<K, Integer> offsets() {
return offsets;
}
- final V[] objects() {
+ final @NonNull V[] objects() {
return objects;
}
private final class EntrySet extends AbstractSet<Entry<K, V>> {
- @Nonnull
@Override
- public Iterator<Entry<K, V>> iterator() {
+ public @NonNull Iterator<Entry<K, V>> iterator() {
final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator();
-
return new UnmodifiableIterator<Entry<K, V>>() {
@Override
public boolean hasNext() {
private static final Field OFFSETS_FIELD = fieldFor("offsets");
private static final Field ARRAY_FIELD = fieldFor("objects");
- private static Field fieldFor(final String name) {
+ private static @NonNull Field fieldFor(final @NonNull String name) {
final Field f;
try {
f = ImmutableOffsetMap.class.getDeclaredField(name);
return f;
}
- private static void setField(final ImmutableOffsetMap<?, ?> map, final Field field, final Object value)
- throws IOException {
+ private static void setField(final @NonNull ImmutableOffsetMap<?, ?> map, final @NonNull Field field,
+ final Object value) throws IOException {
try {
field.set(map, value);
} catch (IllegalArgumentException | IllegalAccessException e) {
}
@SuppressWarnings("unchecked")
- private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
+ private void readObject(final @NonNull ObjectInputStream in) throws IOException, ClassNotFoundException {
final int s = in.readInt();
final List<K> keys = new ArrayList<>(s);
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Mutable;
/**
*
* @return An unmodifiable version of this map.
*/
- @Nonnull Map<K, V> toUnmodifiableMap();
+ @NonNull Map<K, V> toUnmodifiableMap();
}
*/
package org.opendaylight.yangtools.util;
+import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
import static java.util.Objects.requireNonNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
/**
* A mutable version of {@link ImmutableOffsetMap}. It inherits the set of mappings from the immutable version and
}
}
- @Nonnull
@Override
- public final Set<Entry<K, V>> entrySet() {
+ public final @NonNull Set<Entry<K, V>> entrySet() {
return new EntrySet();
}
- @Nonnull
@Override
- public Map<K, V> toUnmodifiableMap() {
+ public @NonNull Map<K, V> toUnmodifiableMap() {
if (removed == 0 && newKeys.isEmpty()) {
// Make sure next modification clones the array, as we leak it to the map we return.
needClone = true;
return true;
}
- @Nonnull
@Override
- public final Set<K> keySet() {
+ public final @NonNull Set<K> keySet() {
return new KeySet();
}
}
private final class EntrySet extends AbstractSet<Entry<K, V>> {
- @Nonnull
@Override
- public Iterator<Entry<K, V>> iterator() {
+ public @NonNull Iterator<Entry<K, V>> iterator() {
return new AbstractSetIterator<Entry<K, V>>() {
@Override
public Entry<K, V> next() {
}
private final class KeySet extends AbstractSet<K> {
- @Nonnull
@Override
- public Iterator<K> iterator() {
+ public @NonNull Iterator<K> iterator() {
return new AbstractSetIterator<K>() {
@Override
public K next() {
private final Iterator<Entry<K, Integer>> oldIterator = offsets.entrySet().iterator();
private final Iterator<K> newIterator = newKeys.keySet().iterator();
private int expectedModCount = modCount;
- private K currentKey;
- private K nextKey;
+ private @Nullable K currentKey = null;
+ private @Nullable K nextKey;
AbstractSetIterator() {
updateNextKey();
@Override
public final void remove() {
- requireNonNull(currentKey != null);
-
checkModCount();
+ checkState(currentKey != null);
final Integer offset = offsets.get(currentKey);
if (offset != null) {
cloneArray();
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
private final Set<ObjectRegistration<? extends T>> unmodifiableView;
private final String name;
- private ObjectRegistry(final String name, Set<ObjectRegistration<? extends T>> objects) {
+ private ObjectRegistry(final String name, final Set<ObjectRegistration<? extends T>> objects) {
this.name = requireNonNull(name);
this.objects = requireNonNull(objects);
this.unmodifiableView = Collections.unmodifiableSet(objects);
}
private static final class Reg<T> extends AbstractObjectRegistration<T> {
- private @Nullable @javax.annotation.Nullable Consumer<ObjectRegistration<? super T>> removeCall;
+ private @Nullable Consumer<ObjectRegistration<? super T>> removeCall;
Reg(final T instance, final Consumer<ObjectRegistration<? super T>> removeCall) {
super(instance);
}
@Override
+ @SuppressFBWarnings("NP_STORE_INTO_NONNULL_FIELD")
protected void removeRegistration() {
removeCall.accept(this);
// Do not retail reference to that state
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nonnull;
final class OffsetMapCache {
/*
private static final LoadingCache<List<?>, Map<?, Integer>> ORDERED_CACHE =
CacheBuilder.newBuilder().weakValues().build(new CacheLoader<List<?>, Map<?, Integer>>() {
@Override
- public Map<?, Integer> load(@Nonnull final List<?> key) {
+ public Map<?, Integer> load(final List<?> key) {
return createMap(key);
}
});
package org.opendaylight.yangtools.util;
import com.google.common.annotations.Beta;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
/**
* Utility class for storing an optional boolean in a single byte value. This cuts down the memory requirement quite
/**
* Convert a field value to a nullable {@link Boolean}. Similar to {@code Optional.orElse(null)}.
*
- * @param value Fied value.
+ * @param value Field value.
* @return Nullable Boolean.
*/
+ @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
public static @Nullable Boolean toNullable(final byte value) {
switch (value) {
case ABSENT:
* @return Optional {@link Boolean}.
* @throws IllegalArgumentException if value is invalid.
*/
- public static Optional<Boolean> toOptional(final byte value) {
+ public static @NonNull Optional<Boolean> toOptional(final byte value) {
switch (value) {
case ABSENT:
return Optional.empty();
* @return Boolean-compatible string, or "absent".
* @throws IllegalArgumentException if value is invalid.
*/
- public static String toString(final byte value) {
+ public static @NonNull String toString(final byte value) {
switch (value) {
case ABSENT:
return "absent";
import java.util.Collections;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.pantheon.triemap.MutableTrieMap;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+ public void putAll(final Map<? extends K, ? extends V> m) {
for (Entry<? extends K, ? extends V> e : m.entrySet()) {
put(e.getKey(), e.getValue());
}
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Map.Entry;
-import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
+import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// BEWARE: this method returns incpmpletely-initialized objects (that is the purpose of this class).
//
// BE VERY CAREFUL WHAT OBJECT STATE YOU TOUCH
- public static @Nullable <T> T lookup(final Object key, final Class<T> requiredClass) {
+ public static <T> @Nullable T lookup(final Object key, final Class<T> requiredClass) {
final Deque<Entry<?, Object>> stack = STACK.get();
if (stack != null) {
for (Entry<?, Object> e : stack) {
import java.io.Serializable;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
/**
* Implementation of the {@link Map} interface which stores a single mapping. The key set is shared among all instances
super(key, value);
}
- @Nonnull
@Override
- public ModifiableMapPhase<K, V> toModifiableMap() {
+ public @NonNull ModifiableMapPhase<K, V> toModifiableMap() {
return MutableOffsetMap.orderedCopyOf(this);
}
}
super(key, value);
}
- @Nonnull
@Override
- public ModifiableMapPhase<K, V> toModifiableMap() {
+ public @NonNull ModifiableMapPhase<K, V> toModifiableMap() {
return MutableOffsetMap.unorderedCopyOf(this);
}
}
private static final LoadingCache<Object, SingletonSet<Object>> CACHE = CacheBuilder.newBuilder().weakValues()
.build(new CacheLoader<Object, SingletonSet<Object>>() {
@Override
- public SingletonSet<Object> load(@Nonnull final Object key) {
+ public SingletonSet<Object> load(final Object key) {
return SingletonSet.of(key);
}
});
return new Unordered<>(e.getKey(), e.getValue());
}
- @Nonnull
@Override
- public final SingletonSet<Entry<K, V>> entrySet() {
+ public final @NonNull SingletonSet<Entry<K, V>> entrySet() {
return SingletonSet.of(new SimpleImmutableEntry<>(keySet.getElement(), value));
}
- @Nonnull
@Override
- public final SingletonSet<K> keySet() {
+ public final @NonNull SingletonSet<K> keySet() {
return keySet;
}
- @Nonnull
@Override
- public final SingletonSet<V> values() {
+ public final @NonNull SingletonSet<V> values() {
return SingletonSet.of(value);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final void putAll(@Nonnull final Map<? extends K, ? extends V> m) {
+ public final void putAll(final Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
import java.util.Iterator;
import java.util.Set;
import java.util.Spliterator;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
/**
}
@Override
- public Object getElement() {
+ public @Nullable Object getElement() {
return null;
}
@Override
- public Spliterator<Object> spliterator() {
+ public @NonNull Spliterator<Object> spliterator() {
return SingletonSpliterators.immutableOfNull();
}
@Override
- public String toString() {
+ public @NonNull String toString() {
return "[null]";
}
};
@SuppressWarnings("unchecked")
- public static <E> SingletonSet<E> of(@Nonnull final E element) {
- if (element == null) {
- return (SingletonSet<E>) NULL_SINGLETON;
- }
- return new RegularSingletonSet<>(element);
+ public static <E> @NonNull SingletonSet<E> of(final @Nullable E element) {
+ return element == null ? (SingletonSet<E>) NULL_SINGLETON : new RegularSingletonSet<>(element);
}
- public abstract E getElement();
+ public abstract @Nullable E getElement();
@Override
public final int size() {
}
@Override
- public final Iterator<E> iterator() {
+ public final @NonNull Iterator<E> iterator() {
return Iterators.singletonIterator(getElement());
}
@Override
- public abstract Spliterator<E> spliterator();
+ public abstract @NonNull Spliterator<E> spliterator();
- @Nonnull
@Override
- public final Object[] toArray() {
+ public final @NonNull Object[] toArray() {
return new Object[] { getElement() };
}
- @Nonnull
@SuppressWarnings({ "unchecked", "checkstyle:parameterName" })
@Override
- public final <T> T[] toArray(@Nonnull final T[] a) {
+ public final <T> @NonNull T[] toArray(final T[] a) {
if (a.length > 0) {
a[0] = (T)getElement();
return a;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final boolean containsAll(@Nonnull final Collection<?> c) {
+ public final boolean containsAll(final Collection<?> c) {
if (c.isEmpty()) {
return true;
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final boolean addAll(@Nonnull final Collection<? extends E> c) {
+ public final boolean addAll(final Collection<? extends E> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final boolean retainAll(@Nonnull final Collection<?> c) {
+ public final boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final boolean removeAll(@Nonnull final Collection<?> c) {
+ public final boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
return s.size() == 1 && otherContains(s);
}
- private boolean otherContains(final Collection<?> other) {
+ private boolean otherContains(final @NonNull Collection<?> other) {
try {
return other.contains(getElement());
} catch (ClassCastException | NullPointerException e) {
}
}
+ @NonNullByDefault
private static final class RegularSingletonSet<E> extends SingletonSet<E> {
private static final long serialVersionUID = 1L;
+
private final E element;
RegularSingletonSet(final E element) {
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean contains(final Object o) {
+ public boolean contains(final @Nullable Object o) {
return element.equals(o);
}
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
/**
* An unmodifiable view over a {@link Collection}. Unlike the view returned via
*/
public final class UnmodifiableCollection<E> implements Collection<E>, Serializable {
private static final long serialVersionUID = 1L;
- private static final Class<?> UNMODIFIABLE_COLLECTION_CLASS;
- private static final Collection<Class<?>> SINGLETON_CLASSES;
+ private static final @NonNull Class<?> UNMODIFIABLE_COLLECTION_CLASS;
+ private static final @NonNull Collection<Class<?>> SINGLETON_CLASSES;
static {
UNMODIFIABLE_COLLECTION_CLASS = Collections.unmodifiableCollection(new ArrayList<>()).getClass();
SINGLETON_CLASSES = b.build();
}
- private final Collection<E> delegate;
+ private final @NonNull Collection<E> delegate;
- private UnmodifiableCollection(final Collection<E> delegate) {
+ private UnmodifiableCollection(final @NonNull Collection<E> delegate) {
this.delegate = requireNonNull(delegate);
}
*
* @param collection Target collection
* @return An unmodifiable view of the collection
+ * @throws NullPointerException if {@code collection} is null
*/
- public static <T> Collection<T> create(@Nonnull final Collection<T> collection) {
+ public static <T> @NonNull Collection<T> create(final @NonNull Collection<T> collection) {
if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection
|| Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection
|| UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection)
return new UnmodifiableCollection<>(collection);
}
- @Nonnull
@Override
- public Iterator<E> iterator() {
+ public @NonNull Iterator<E> iterator() {
return Iterators.unmodifiableIterator(delegate.iterator());
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public <T> T[] toArray(@Nonnull final T[] a) {
+ public <T> T[] toArray(final T[] a) {
return delegate.toArray(a);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean containsAll(@Nonnull final Collection<?> c) {
+ public boolean containsAll(final Collection<?> c) {
return delegate.containsAll(c);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean addAll(@Nonnull final Collection<? extends E> c) {
+ public boolean addAll(final Collection<? extends E> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean removeAll(@Nonnull final Collection<?> c) {
+ public boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean retainAll(@Nonnull final Collection<?> c) {
+ public boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
}
@Override
- public String toString() {
+ public @NonNull String toString() {
return "UnmodifiableCollection{" + delegate + "}";
}
}
import com.google.common.annotations.Beta;
import java.util.Map;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Immutable;
/**
*
* @return An modifiable version of this map.
*/
- @Nonnull ModifiableMapPhase<K, V> toModifiableMap();
+ @NonNull ModifiableMapPhase<K, V> toModifiableMap();
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static java.util.Objects.requireNonNull;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The executor used to run listener callbacks.
*/
- private final Executor listenerExecutor;
+ private final @NonNull Executor listenerExecutor;
private DelegatingAsyncNotifyingListenableFutureTask(final Callable<V> callable,
- final Executor listenerExecutor) {
+ final @NonNull Executor listenerExecutor) {
super(callable);
this.listenerExecutor = requireNonNull(listenerExecutor);
}
private DelegatingAsyncNotifyingListenableFutureTask(final Runnable runnable, @Nullable final V result,
- final Executor listenerExecutor) {
+ final @NonNull Executor listenerExecutor) {
super(runnable, result);
this.listenerExecutor = requireNonNull(listenerExecutor);
}
@Override
- public void addListener(@Nonnull final Runnable listener, @Nonnull final Executor executor) {
+ public void addListener(final Runnable listener, final Executor executor) {
// Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that
// runs tasks in the same thread as the caller submitting the task
// (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the
*/
private final ExecutionList executionList = new ExecutionList();
- private AsyncNotifyingListenableFutureTask(final Callable<V> callable) {
+ private AsyncNotifyingListenableFutureTask(final @NonNull Callable<V> callable) {
super(callable);
}
- private AsyncNotifyingListenableFutureTask(final Runnable runnable, final V result) {
+ private AsyncNotifyingListenableFutureTask(final @NonNull Runnable runnable, final @Nullable V result) {
super(runnable, result);
}
* @param listenerExecutor the executor used to run listener callbacks asynchronously.
* If null, no executor is used.
*/
- public static <V> AsyncNotifyingListenableFutureTask<V> create(final Callable<V> callable,
+ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Callable<V> callable,
@Nullable final Executor listenerExecutor) {
if (listenerExecutor == null) {
return new AsyncNotifyingListenableFutureTask<>(callable);
* @param listenerExecutor the executor used to run listener callbacks asynchronously.
* If null, no executor is used.
*/
- public static <V> AsyncNotifyingListenableFutureTask<V> create(final Runnable runnable, @Nullable final V result,
- @Nullable final Executor listenerExecutor) {
+ public static <V> @NonNull AsyncNotifyingListenableFutureTask<V> create(final @NonNull Runnable runnable,
+ @Nullable final V result, @Nullable final Executor listenerExecutor) {
if (listenerExecutor == null) {
return new AsyncNotifyingListenableFutureTask<>(runnable, result);
}
}
@Override
- public void addListener(@Nonnull final Runnable listener, @Nonnull final Executor executor) {
+ public void addListener(final Runnable listener, final Executor executor) {
executionList.add(listener, executor);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static java.util.Objects.requireNonNull;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.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
- * <code>MoreExecutors#sameThreadExecutor</code>}) to
- * {@link ListenableFuture#addListener}.
+ * 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 (i.e. {@code MoreExecutors#sameThreadExecutor}) to {@link ListenableFuture#addListener}.
*
* <p>
- * Most commonly, this class would be used in lieu of
- * <code>MoreExecutors#listeningDecorator</code> 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 {@code MoreExecutors#listeningDecorator} when the underlying
+ * delegate Executor is single-threaded, in which case, you may not want ListenableFuture callbacks to block the single
+ * thread.
*
* <p>
- * 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
*/
public class AsyncNotifyingListeningExecutorService extends AbstractListeningExecutorService {
-
- private final ExecutorService delegate;
- private final Executor listenableFutureExecutor;
+ private final @NonNull ExecutorService delegate;
+ private final @Nullable Executor listenableFutureExecutor;
/**
* Constructor.
* @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
* If null, no executor is used.
*/
- public AsyncNotifyingListeningExecutorService(final ExecutorService delegate,
+ public AsyncNotifyingListeningExecutorService(final @NonNull ExecutorService delegate,
@Nullable final Executor listenableFutureExecutor) {
this.delegate = requireNonNull(delegate);
this.listenableFutureExecutor = listenableFutureExecutor;
}
- /**
- * Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor.
- *
- * @param task the Callable to execute
- */
- private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask(final Callable<T> task) {
- return AsyncNotifyingListenableFutureTask.create(task, listenableFutureExecutor);
- }
-
/**
* Creates an {@link AsyncNotifyingListenableFutureTask} instance with the listener Executor.
*
* @param task the Runnable to execute
*/
- private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask(final Runnable task, final T result) {
+ private <T> @NonNull AsyncNotifyingListenableFutureTask<T> newFutureTask(final @NonNull Runnable task,
+ final T result) {
return AsyncNotifyingListenableFutureTask.create(task, result, listenableFutureExecutor);
}
/**
* Returns the delegate ExecutorService.
*/
- protected ExecutorService getDelegate() {
+ protected @NonNull ExecutorService getDelegate() {
return delegate;
}
@Override
- public boolean awaitTermination(final long timeout, @Nonnull final TimeUnit unit) throws InterruptedException {
+ public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException {
return delegate.awaitTermination(timeout, unit);
}
delegate.shutdown();
}
- @Nonnull
@Override
public List<Runnable> shutdownNow() {
return delegate.shutdownNow();
}
@Override
- public void execute(@Nonnull final Runnable command) {
+ public void execute(final Runnable command) {
delegate.execute(command);
}
- @Nonnull
@Override
public <T> ListenableFuture<T> submit(final Callable<T> task) {
- AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(task);
+ final AsyncNotifyingListenableFutureTask<T> futureTask = AsyncNotifyingListenableFutureTask.create(
+ requireNonNull(task), listenableFutureExecutor);
delegate.execute(futureTask);
return futureTask;
}
- @Nonnull
@Override
public ListenableFuture<?> submit(final Runnable task) {
- AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask(task, null);
+ final AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask(requireNonNull(task), null);
delegate.execute(futureTask);
return futureTask;
}
- @Nonnull
@Override
public <T> ListenableFuture<T> submit(final Runnable task, final T result) {
- AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(task, result);
+ final AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask(requireNonNull(task), result);
delegate.execute(futureTask);
return futureTask;
}
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ protected @NonNull ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
return toStringHelper;
}
@Override
public final String toString() {
- return addToStringAttributes(MoreObjects.toStringHelper(this)
- .add("delegate", delegate)).toString();
+ return addToStringAttributes(MoreObjects.toStringHelper(this).add("delegate", delegate)).toString();
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
-import com.google.common.util.concurrent.ForwardingListenableFuture;
+import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
/**
- * An implementation of ListeningExecutorService that attempts to detect deadlock scenarios that
- * could occur if clients invoke the returned Future's <code>get</code> methods synchronously.
+ * An implementation of ListeningExecutorService that attempts to detect deadlock scenarios that could occur if clients
+ * invoke the returned Future's <code>get</code> methods synchronously.
*
- * <p>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:
+ * <p>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:
* <ul>
* <li>Client code is currently executing in an executor's single thread.</li>
* <li>The client submits another task to the same executor.</li>
* <li>The client calls <code>get()</code> synchronously on the returned Future</li>
* </ul>
- * 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.
+ * 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.
*
- * <p>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 <code>get</code> methods to check if the ThreadLocal is set. If it is,
- * an ExecutionException is thrown with a custom cause.
+ * <p>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 {@code get} methods to check if the ThreadLocal is set. If it is, an ExecutionException is thrown with a custom
+ * cause.
*
- * <p>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()}.
+ * <p>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()}.
*
* @author Thomas Pantelis
* @author Robert Varga
* tasks may be submitted to underlay and some to overlay service -- and the two cases need to
* be discerned reliably.
*/
- private final SettableBooleanThreadLocal deadlockDetector = new SettableBooleanThreadLocal();
- private final Supplier<Exception> deadlockExceptionFunction;
+ private final @NonNull SettableBooleanThreadLocal deadlockDetector = new SettableBooleanThreadLocal();
+ private final @NonNull Supplier<Exception> deadlockExceptionFunction;
/**
* Constructor.
* @param deadlockExceptionSupplier Supplier that returns an Exception instance to set as the
* cause of the ExecutionException when a deadlock is detected.
*/
- public DeadlockDetectingListeningExecutorService(final ExecutorService delegate,
- @Nonnull final Supplier<Exception> deadlockExceptionSupplier) {
+ public DeadlockDetectingListeningExecutorService(final @NonNull ExecutorService delegate,
+ final @NonNull Supplier<Exception> deadlockExceptionSupplier) {
this(delegate, deadlockExceptionSupplier, null);
}
* @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
* If null, no executor is used.
*/
- public DeadlockDetectingListeningExecutorService(final ExecutorService delegate,
- @Nonnull final Supplier<Exception> deadlockExceptionSupplier,
+ public DeadlockDetectingListeningExecutorService(final @NonNull ExecutorService delegate,
+ @NonNull final Supplier<Exception> deadlockExceptionSupplier,
@Nullable final Executor listenableFutureExecutor) {
super(delegate, listenableFutureExecutor);
this.deadlockExceptionFunction = requireNonNull(deadlockExceptionSupplier);
}
@Override
- public void execute(@Nonnull final Runnable command) {
+ public void execute(final Runnable command) {
getDelegate().execute(wrapRunnable(command));
}
- @Nonnull
@Override
public <T> ListenableFuture<T> submit(final Callable<T> task) {
return wrapListenableFuture(super.submit(wrapCallable(task)));
}
- @Nonnull
@Override
public ListenableFuture<?> submit(final Runnable task) {
return wrapListenableFuture(super.submit(wrapRunnable(task)));
}
- @Nonnull
@Override
public <T> ListenableFuture<T> submit(final Runnable task, final T result) {
return wrapListenableFuture(super.submit(wrapRunnable(task), result));
deadlockDetector.remove();
}
- private SettableBoolean primeDetector() {
+ private @NonNull SettableBoolean primeDetector() {
final SettableBoolean b = deadlockDetector.get();
checkState(!b.isSet(), "Detector for {} has already been primed", this);
b.set();
return b;
}
- private Runnable wrapRunnable(final Runnable task) {
+ private @NonNull Runnable wrapRunnable(final @Nullable Runnable task) {
+ requireNonNull(task);
return () -> {
final SettableBoolean b = primeDetector();
try {
};
}
- private <T> Callable<T> wrapCallable(final Callable<T> delagate) {
+ private <T> @NonNull Callable<T> wrapCallable(final @NonNull Callable<T> task) {
+ requireNonNull(task);
return () -> {
final SettableBoolean b = primeDetector();
try {
- return delagate.call();
+ return task.call();
} finally {
b.reset();
}
};
}
- private <T> ListenableFuture<T> wrapListenableFuture(final ListenableFuture<T> delegate) {
+ private <T> @NonNull ListenableFuture<T> wrapListenableFuture(final @NonNull ListenableFuture<T> delegate) {
/*
* This creates a forwarding Future that overrides calls to get(...) to check, via the
* ThreadLocal, if the caller is doing a blocking call on a thread from this executor. If
* practice somewhere, either on the client side for doing a blocking call or in the
* framework's threading model.
*/
- return new ForwardingListenableFuture.SimpleForwardingListenableFuture<T>(delegate) {
+ return new SimpleForwardingListenableFuture<T>(delegate) {
@Override
public T get() throws InterruptedException, ExecutionException {
checkDeadLockDetectorTL();
}
@Override
- public T get(final long timeout, @Nonnull final TimeUnit unit)
- throws InterruptedException, ExecutionException, TimeoutException {
+ public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException,
+ TimeoutException {
checkDeadLockDetectorTL();
return super.get(timeout, unit);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param listener the listener to invoke
* @param notifications notifications to send
*/
- void invokeListener(@Nonnull L listener, @Nonnull Collection<? extends N> notifications);
+ void invokeListener(@NonNull L listener, @NonNull Collection<? extends N> notifications);
}
private static final Logger LOG = LoggerFactory.getLogger(QueuedNotificationManager.class);
private static final long TASK_WAIT_NANOS = TimeUnit.MILLISECONDS.toNanos(10);
private final ConcurrentMap<ListenerKey<L>, NotificationTask> listenerCache = new ConcurrentHashMap<>();
- private final BatchedInvoker<L, N> listenerInvoker;
- private final Executor executor;
- private final String name;
+ private final @NonNull BatchedInvoker<L, N> listenerInvoker;
+ private final @NonNull Executor executor;
+ private final @NonNull String name;
private final int maxQueueCapacity;
- private QueuedNotificationManager(final Executor executor, final BatchedInvoker<L, N> listenerInvoker,
- final int maxQueueCapacity, final String name) {
+ private QueuedNotificationManager(final @NonNull Executor executor,
+ final @NonNull BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity,
+ final @NonNull String name) {
checkArgument(maxQueueCapacity > 0, "Invalid maxQueueCapacity %s must be > 0", maxQueueCapacity);
this.executor = requireNonNull(executor);
this.listenerInvoker = requireNonNull(listenerInvoker);
*/
@Deprecated
@SuppressWarnings("checkstyle:illegalCatch")
- public QueuedNotificationManager(final Executor executor, final Invoker<L, N> listenerInvoker,
- final int maxQueueCapacity, final String name) {
+ public QueuedNotificationManager(final @NonNull Executor executor, final @NonNull Invoker<L, N> listenerInvoker,
+ final int maxQueueCapacity, final @NonNull String name) {
this(executor, (BatchedInvoker<L, N>)(listener, notifications) -> notifications.forEach(n -> {
try {
listenerInvoker.invokeListener(listener, n);
* @param maxQueueCapacity the capacity of each listener queue
* @param name the name of this instance for logging info
*/
- public static <L, N> QueuedNotificationManager<L, N> create(final Executor executor,
- final BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity, final String name) {
+ public static <L, N> QueuedNotificationManager<L, N> create(final @NonNull Executor executor,
+ final@NonNull BatchedInvoker<L, N> listenerInvoker, final int maxQueueCapacity,
+ final @NonNull String name) {
return new QueuedNotificationManager<>(executor, listenerInvoker, maxQueueCapacity, name);
}
/**
* Returns the {@link Executor} to used for notification tasks.
*/
- public Executor getExecutor() {
+ public @NonNull Executor getExecutor() {
return executor;
}
* for instanceof.
*/
private static final class ListenerKey<L> {
- private final L listener;
+ private final @NonNull L listener;
ListenerKey(final L listener) {
this.listener = requireNonNull(listener);
}
- L getListener() {
+ @NonNull L getListener() {
return listener;
}
@Override
public boolean equals(final Object obj) {
- if (obj == this) {
- return true;
- }
- return obj instanceof ListenerKey<?> && listener == ((ListenerKey<?>) obj).listener;
+ return obj == this || obj instanceof ListenerKey<?> && listener == ((ListenerKey<?>) obj).listener;
}
@Override
* listener.
*/
private class NotificationTask implements Runnable {
-
private final Lock lock = new ReentrantLock();
private final Condition notEmpty = lock.newCondition();
private final Condition notFull = lock.newCondition();
- private final ListenerKey<L> listenerKey;
+ private final @NonNull ListenerKey<L> listenerKey;
@GuardedBy("lock")
private final Queue<N> queue = new ArrayDeque<>();
@GuardedBy("lock")
private boolean exiting;
- NotificationTask(final ListenerKey<L> listenerKey, final Iterator<N> notifications) {
+ NotificationTask(final @NonNull ListenerKey<L> listenerKey, final @NonNull Iterator<N> notifications) {
this.listenerKey = requireNonNull(listenerKey);
while (notifications.hasNext()) {
queue.add(notifications.next());
}
}
- Iterator<N> recoverItems() {
+ @NonNull Iterator<N> recoverItems() {
// This violates @GuardedBy annotation, but is invoked only when the task is not started and will never
// get started, hence this is safe.
return queue.iterator();
}
}
- boolean submitNotifications(final Iterator<N> notifications) throws InterruptedException {
+ boolean submitNotifications(final @NonNull Iterator<N> notifications) throws InterruptedException {
final long start = System.nanoTime();
final long deadline = start + GIVE_UP_NANOS;
try {
// Loop until we've dispatched all the notifications in the queue.
while (true) {
- final Collection<N> notifications;
+ final @NonNull Collection<N> notifications;
lock.lock();
try {
}
@SuppressWarnings("checkstyle:illegalCatch")
- private void invokeListener(final Collection<N> notifications) {
+ private void invokeListener(final @NonNull Collection<N> notifications) {
LOG.debug("{}: Invoking listener {} with notification: {}", name, listenerKey, notifications);
try {
listenerInvoker.invokeListener(listenerKey.getListener(), notifications);
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import com.google.common.annotations.Beta;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
/**
* A {@link LinkedBlockingQueue} that tracks the largest queue size for debugging.
* See {@link LinkedBlockingQueue#LinkedBlockingQueue(Collection)}.
*/
@SuppressWarnings("checkstyle:parameterName")
- public TrackingLinkedBlockingQueue(final Collection<? extends E> c) {
+ public TrackingLinkedBlockingQueue(final @NonNull Collection<? extends E> c) {
super(c);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean offer(@Nonnull final E e) {
+ public boolean offer(final E e) {
if (super.offer(e)) {
updateLargestQueueSize();
return true;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.Charset;
-import javax.annotation.Nonnull;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.eclipse.jdt.annotation.NonNull;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
*/
@Beta
public final class UntrustedXML {
- private static final DocumentBuilderFactory DBF;
+ private static final @NonNull DocumentBuilderFactory DBF;
static {
final DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
* @return A new DocumentBuilder
* @throws UnsupportedOperationException if the runtime fails to instantiate a good enough builder
*/
- public static @Nonnull DocumentBuilder newDocumentBuilder() {
+ public static @NonNull DocumentBuilder newDocumentBuilder() {
try {
return DBF.newDocumentBuilder();
} catch (ParserConfigurationException e) {
* @return A new SAXParser
* @throws UnsupportedOperationException if the runtime fails to instantiate a good enough builder
*/
- public static @Nonnull SAXParser newSAXParser() {
+ public static @NonNull SAXParser newSAXParser() {
try {
return SPF.newSAXParser();
} catch (ParserConfigurationException | SAXException e) {
* @return A new XMLStreamReader
* @throws XMLStreamException when the underlying factory throws it
*/
- public static @Nonnull XMLStreamReader createXMLStreamReader(final InputStream stream) throws XMLStreamException {
+ public static @NonNull XMLStreamReader createXMLStreamReader(final InputStream stream) throws XMLStreamException {
return XIF.createXMLStreamReader(stream);
}
* @return A new XMLStreamReader
* @throws XMLStreamException when the underlying factory throws it
*/
- public static @Nonnull XMLStreamReader createXMLStreamReader(final InputStream stream, final Charset charset)
+ public static @NonNull XMLStreamReader createXMLStreamReader(final InputStream stream, final Charset charset)
throws XMLStreamException {
return XIF.createXMLStreamReader(stream, charset.name());
}
* @return A new XMLStreamReader
* @throws XMLStreamException when the underlying factory throws it
*/
- public static @Nonnull XMLStreamReader createXMLStreamReader(final Reader reader) throws XMLStreamException {
+ public static @NonNull XMLStreamReader createXMLStreamReader(final Reader reader) throws XMLStreamException {
return XIF.createXMLStreamReader(reader);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static org.junit.Assert.assertSame;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Nonnull;
import org.junit.After;
import org.junit.Test;
import org.opendaylight.yangtools.util.concurrent.CommonTestUtils.Invoker;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public void onFailure(@Nonnull final Throwable t) {
+ public void onFailure(final Throwable t) {
// Shouldn't happen
fail("Unexpected failure " + t);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.util.concurrent;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
-import javax.annotation.Nonnull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@Override
@SuppressWarnings("checkstyle:parameterName")
- public void onFailure(@Nonnull final Throwable t) {
+ public void onFailure(final Throwable t) {
caughtEx.set(t);
futureCompletedLatch.countDown();
}