Code Review
/
yangtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Separate out {Identity,Equality}QueuedNotificationManager
[yangtools.git]
/
common
/
util
/
src
/
main
/
java
/
org
/
opendaylight
/
yangtools
/
util
/
SingletonSet.java
diff --git
a/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java
b/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java
index af024857da5c39de2437a13ab4169ec6ac512ca0..914268a45a21c74b3f4db06a05ce7561067d6128 100644
(file)
--- a/
common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java
+++ b/
common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java
@@
-7,14
+7,18
@@
*/
package org.opendaylight.yangtools.util;
*/
package org.opendaylight.yangtools.util;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import com.google.common.collect.Iterators;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
-import javax.annotation.Nonnull;
+import java.util.Spliterator;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
/**
import org.opendaylight.yangtools.concepts.Immutable;
/**
@@
-41,12
+45,17
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
}
@Override
}
@Override
- public Object getElement() {
+ public
@Nullable
Object getElement() {
return null;
}
@Override
return null;
}
@Override
- public String toString() {
+ public @NonNull Spliterator<Object> spliterator() {
+ return SingletonSpliterators.immutableOfNull();
+ }
+
+ @Override
+ public @NonNull String toString() {
return "[null]";
}
return "[null]";
}
@@
-56,14
+65,11
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
};
@SuppressWarnings("unchecked")
};
@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 int size() {
@@
-76,20
+82,21
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
}
@Override
}
@Override
- public final Iterator<E> iterator() {
+ public final
@NonNull
Iterator<E> iterator() {
return Iterators.singletonIterator(getElement());
}
return Iterators.singletonIterator(getElement());
}
- @Nonnull
@Override
@Override
- public final Object[] toArray() {
+ public abstract @NonNull Spliterator<E> spliterator();
+
+ @Override
+ public final @NonNull Object[] toArray() {
return new Object[] { getElement() };
}
return new Object[] { getElement() };
}
- @Nonnull
@SuppressWarnings({ "unchecked", "checkstyle:parameterName" })
@Override
@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;
if (a.length > 0) {
a[0] = (T)getElement();
return a;
@@
-112,32
+119,25
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
@Override
@SuppressWarnings("checkstyle:parameterName")
@Override
@SuppressWarnings("checkstyle:parameterName")
- public final boolean containsAll(@Nonnull final Collection<?> c) {
- if (c.isEmpty()) {
- return true;
- }
- if (c.size() != 1) {
- return false;
- }
-
- return otherContains(c);
+ public final boolean containsAll(final Collection<?> c) {
+ return c.isEmpty() || c.size() == 1 && otherContains(c);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
}
@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")
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")
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();
}
throw new UnsupportedOperationException();
}
@@
-163,7
+163,7
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
return s.size() == 1 && otherContains(s);
}
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) {
try {
return other.contains(getElement());
} catch (ClassCastException | NullPointerException e) {
@@
-171,17
+171,19
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
}
}
}
}
+ @NonNullByDefault
private static final class RegularSingletonSet<E> extends SingletonSet<E> {
private static final long serialVersionUID = 1L;
private static final class RegularSingletonSet<E> extends SingletonSet<E> {
private static final long serialVersionUID = 1L;
+
private final E element;
RegularSingletonSet(final E element) {
private final E element;
RegularSingletonSet(final E element) {
- this.element =
Preconditions.checkNot
Null(element);
+ this.element =
requireNon
Null(element);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public boolean contains(final Object o) {
+ public boolean contains(final
@Nullable
Object o) {
return element.equals(o);
}
return element.equals(o);
}
@@
-200,5
+202,10
@@
public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
public String toString() {
return "[" + element + ']';
}
public String toString() {
return "[" + element + ']';
}
+
+ @Override
+ public Spliterator<E> spliterator() {
+ return SingletonSpliterators.immutableOf(element);
+ }
}
}
}
}