diff options
Diffstat (limited to 'guava/src/com/google')
8 files changed, 92 insertions, 38 deletions
diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java index 635437837..88c7d6b5c 100644 --- a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java @@ -17,7 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; -import org.checkerframework.checker.nullness.qual.Nullable; +import javax.annotation.CheckForNull; /** * Skeletal implementation of {@link ImmutableSortedSet#descendingSet()}. @@ -25,6 +25,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * @author Louis Wasserman */ @GwtIncompatible +@ElementTypesAreNonnullByDefault final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { private final ImmutableSortedSet<E> forward; @@ -34,7 +35,7 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean contains(@Nullable Object object) { + public boolean contains(@CheckForNull Object object) { return forward.contains(object); } @@ -83,27 +84,31 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull public E lower(E element) { return forward.higher(element); } @Override + @CheckForNull public E floor(E element) { return forward.ceiling(element); } @Override + @CheckForNull public E ceiling(E element) { return forward.floor(element); } @Override + @CheckForNull public E higher(E element) { return forward.lower(element); } @Override - int indexOf(@Nullable Object target) { + int indexOf(@CheckForNull Object target) { int index = forward.indexOf(target); if (index == -1) { return index; diff --git a/guava/src/com/google/common/collect/ImmutableSortedAsList.java b/guava/src/com/google/common/collect/ImmutableSortedAsList.java index 91f700ece..30f19a02e 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedAsList.java +++ b/guava/src/com/google/common/collect/ImmutableSortedAsList.java @@ -18,7 +18,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.Comparator; import java.util.Spliterator; -import org.checkerframework.checker.nullness.qual.Nullable; +import javax.annotation.CheckForNull; /** * List returned by {@code ImmutableSortedSet.asList()} when the set isn't empty. @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ @GwtCompatible(emulated = true) @SuppressWarnings("serial") +@ElementTypesAreNonnullByDefault final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E> implements SortedIterable<E> { ImmutableSortedAsList(ImmutableSortedSet<E> backingSet, ImmutableList<E> backingList) { @@ -49,7 +50,7 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E> @GwtIncompatible // ImmutableSortedSet.indexOf // TODO(cpovirk): consider manual binary search under GWT to preserve O(log N) lookup @Override - public int indexOf(@Nullable Object target) { + public int indexOf(@CheckForNull Object target) { int index = delegateCollection().indexOf(target); // TODO(kevinb): reconsider if it's really worth making feeble attempts at @@ -62,12 +63,12 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E> @GwtIncompatible // ImmutableSortedSet.indexOf @Override - public int lastIndexOf(@Nullable Object target) { + public int lastIndexOf(@CheckForNull Object target) { return indexOf(target); } @Override - public boolean contains(Object target) { + public boolean contains(@CheckForNull Object target) { // Necessary for ISS's with comparators inconsistent with equals. return indexOf(target) >= 0; } diff --git a/guava/src/com/google/common/collect/ImmutableSortedMap.java b/guava/src/com/google/common/collect/ImmutableSortedMap.java index 74b4e2879..3c5c07265 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedMap.java +++ b/guava/src/com/google/common/collect/ImmutableSortedMap.java @@ -60,6 +60,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; * @since 2.0 (implements {@code NavigableMap} since 12.0) */ @GwtCompatible(serializable = true, emulated = true) +@ElementTypesAreNonnullByDefault public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxverideShim<K, V> implements NavigableMap<K, V> { /** @@ -74,10 +75,11 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride * * @since 21.0 */ - public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap( - Comparator<? super K> comparator, - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction) { + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap( + Comparator<? super K> comparator, + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction) { return CollectCollectors.toImmutableSortedMap(comparator, keyFunction, valueFunction); } @@ -92,11 +94,12 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride * * @since 21.0 */ - public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap( - Comparator<? super K> comparator, - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction, - BinaryOperator<V> mergeFunction) { + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap( + Comparator<? super K> comparator, + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction, + BinaryOperator<V> mergeFunction) { return CollectCollectors.toImmutableSortedMap( comparator, keyFunction, valueFunction, mergeFunction); } @@ -558,7 +561,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride private final transient RegularImmutableSortedSet<K> keySet; private final transient ImmutableList<V> valueList; - private transient ImmutableSortedMap<K, V> descendingMap; + @CheckForNull private transient ImmutableSortedMap<K, V> descendingMap; ImmutableSortedMap(RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { this(keySet, valueList, null); @@ -567,7 +570,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride ImmutableSortedMap( RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList, - ImmutableSortedMap<K, V> descendingMap) { + @CheckForNull ImmutableSortedMap<K, V> descendingMap) { this.keySet = keySet; this.valueList = valueList; this.descendingMap = descendingMap; @@ -589,7 +592,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Override @CheckForNull - public V get(@Nullable Object key) { + public V get(@CheckForNull Object key) { int index = keySet.indexOf(key); return (index == -1) ? null : valueList.get(index); } @@ -880,6 +883,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final Entry<K, V> pollFirstEntry() { throw new UnsupportedOperationException(); } @@ -894,6 +898,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final Entry<K, V> pollLastEntry() { throw new UnsupportedOperationException(); } diff --git a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java index 87b83519e..9ccf02c65 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java +++ b/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java @@ -17,9 +17,11 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.DoNotCall; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collector; +import org.checkerframework.checker.nullness.qual.Nullable; /** * "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableSortedMap} @@ -29,6 +31,7 @@ import java.util.stream.Collector; * @author Chris Povirk */ @GwtIncompatible +@ElementTypesAreNonnullByDefault abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> { /** * Not supported. Use {@link ImmutableSortedMap#toImmutableSortedMap}, which offers better @@ -38,10 +41,12 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. */ + @DoNotCall("Use toImmutableSortedMap") @Deprecated - public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction) { + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction) { throw new UnsupportedOperationException(); } @@ -53,11 +58,13 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}. */ + @DoNotCall("Use toImmutableSortedMap") @Deprecated - public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( - Function<? super T, ? extends K> keyFunction, - Function<? super T, ? extends V> valueFunction, - BinaryOperator<V> mergeFunction) { + public static <T extends @Nullable Object, K, V> + Collector<T, ?, ImmutableMap<K, V>> toImmutableMap( + Function<? super T, ? extends K> keyFunction, + Function<? super T, ? extends V> valueFunction, + BinaryOperator<V> mergeFunction) { throw new UnsupportedOperationException(); } @@ -69,6 +76,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety. */ + @DoNotCall("Use naturalOrder") @Deprecated public static <K, V> ImmutableSortedMap.Builder<K, V> builder() { throw new UnsupportedOperationException(); @@ -80,6 +88,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Not supported for ImmutableSortedMap. */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") @Deprecated public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) { throw new UnsupportedOperationException(); @@ -94,6 +103,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass a key of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object)}.</b> */ + @DoNotCall("Pass a key of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) { throw new UnsupportedOperationException(); @@ -108,6 +118,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass keys of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) { throw new UnsupportedOperationException(); @@ -122,6 +133,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass keys of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { throw new UnsupportedOperationException(); @@ -137,6 +149,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, * Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { throw new UnsupportedOperationException(); @@ -152,6 +165,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, * Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of( K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { diff --git a/guava/src/com/google/common/collect/ImmutableSortedSet.java b/guava/src/com/google/common/collect/ImmutableSortedSet.java index 7e74eecd4..8a7aec16c 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/ImmutableSortedSet.java @@ -39,6 +39,7 @@ import java.util.Spliterator; import java.util.Spliterators; import java.util.function.Consumer; import java.util.stream.Collector; +import javax.annotation.CheckForNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -61,6 +62,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; // TODO(benyu): benchmark and optimize all creation paths, which are a mess now @GwtCompatible(serializable = true, emulated = true) @SuppressWarnings("serial") // we're overriding default serialization +@ElementTypesAreNonnullByDefault public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E> implements NavigableSet<E>, SortedIterable<E> { static final int SPLITERATOR_CHARACTERISTICS = @@ -575,16 +577,16 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride } } - int unsafeCompare(Object a, Object b) { + int unsafeCompare(Object a, @CheckForNull Object b) { return unsafeCompare(comparator, a, b); } - static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { + static int unsafeCompare(Comparator<?> comparator, Object a, @CheckForNull Object b) { // Pretend the comparator can compare anything. If it turns out it can't - // compare a and b, we should get a CCE on the subsequent line. Only methods - // that are spec'd to throw CCE should call this. - @SuppressWarnings("unchecked") - Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; + // compare a and b, we should get a CCE or NPE on the subsequent line. Only methods + // that are spec'd to throw CCE and NPE should call this. + @SuppressWarnings({"unchecked", "nullness"}) + Comparator<@Nullable Object> unsafeComparator = (Comparator<@Nullable Object>) comparator; return unsafeComparator.compare(a, b); } @@ -691,18 +693,21 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride /** @since 12.0 */ @GwtIncompatible // NavigableSet @Override + @CheckForNull public E lower(E e) { return Iterators.getNext(headSet(e, false).descendingIterator(), null); } /** @since 12.0 */ @Override + @CheckForNull public E floor(E e) { return Iterators.getNext(headSet(e, true).descendingIterator(), null); } /** @since 12.0 */ @Override + @CheckForNull public E ceiling(E e) { return Iterables.getFirst(tailSet(e, true), null); } @@ -710,6 +715,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride /** @since 12.0 */ @GwtIncompatible // NavigableSet @Override + @CheckForNull public E higher(E e) { return Iterables.getFirst(tailSet(e, false), null); } @@ -736,6 +742,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride @GwtIncompatible // NavigableSet @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final E pollFirst() { throw new UnsupportedOperationException(); } @@ -752,12 +759,14 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride @GwtIncompatible // NavigableSet @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final E pollLast() { throw new UnsupportedOperationException(); } @GwtIncompatible // NavigableSet @LazyInit + @CheckForNull transient ImmutableSortedSet<E> descendingSet; /** @since 12.0 */ @@ -808,7 +817,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride public abstract UnmodifiableIterator<E> descendingIterator(); /** Returns the position of an element within the set, or -1 if not present. */ - abstract int indexOf(@Nullable Object target); + abstract int indexOf(@CheckForNull Object target); /* * This class is used to serialize all ImmutableSortedSet instances, diff --git a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java index 9a49fcbe2..d563506ee 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java +++ b/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.DoNotCall; import java.util.stream.Collector; /** @@ -37,6 +38,7 @@ import java.util.stream.Collector; * @author Chris Povirk */ @GwtIncompatible +@ElementTypesAreNonnullByDefault abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { /** * Not supported. Use {@link ImmutableSortedSet#toImmutableSortedSet} instead. This method exists @@ -46,6 +48,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated Use {@link ImmutableSortedSet#toImmutableSortedSet}. * @since 21.0 */ + @DoNotCall("Use toImmutableSortedSet") @Deprecated public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() { throw new UnsupportedOperationException(); @@ -59,6 +62,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety. */ + @DoNotCall("Use naturalOrder") @Deprecated public static <E> ImmutableSortedSet.Builder<E> builder() { throw new UnsupportedOperationException(); @@ -71,6 +75,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @throws UnsupportedOperationException always * @deprecated Not supported by ImmutableSortedSet. */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") @Deprecated public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) { throw new UnsupportedOperationException(); @@ -85,6 +90,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable)}.</b> */ + @DoNotCall("Pass a parameter of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E element) { throw new UnsupportedOperationException(); @@ -99,6 +105,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable)}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2) { throw new UnsupportedOperationException(); @@ -113,6 +120,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) { throw new UnsupportedOperationException(); @@ -127,6 +135,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) { throw new UnsupportedOperationException(); @@ -141,6 +150,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) { throw new UnsupportedOperationException(); @@ -156,6 +166,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable, * Comparable, Comparable...)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { throw new UnsupportedOperationException(); @@ -170,6 +181,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#copyOf(Comparable[])}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> copyOf(E[] elements) { throw new UnsupportedOperationException(); diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java index c659adad7..fcb683f56 100644 --- a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java @@ -28,7 +28,7 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.Spliterator; import java.util.function.Consumer; -import org.checkerframework.checker.nullness.qual.Nullable; +import javax.annotation.CheckForNull; /** * An immutable sorted set with one or more elements. TODO(jlevy): Consider separate class for a @@ -39,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ @GwtCompatible(serializable = true, emulated = true) @SuppressWarnings({"serial", "rawtypes"}) +@ElementTypesAreNonnullByDefault final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET = new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural()); @@ -51,6 +52,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull Object[] internalArray() { return elements.internalArray(); } @@ -92,7 +94,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean contains(@Nullable Object o) { + public boolean contains(@CheckForNull Object o) { try { return o != null && unsafeBinarySearch(o) >= 0; } catch (ClassCastException e) { @@ -167,7 +169,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean equals(@Nullable Object object) { + public boolean equals(@CheckForNull Object object) { if (object == this) { return true; } @@ -220,24 +222,28 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull public E lower(E element) { int index = headIndex(element, false) - 1; return (index == -1) ? null : elements.get(index); } @Override + @CheckForNull public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); } @Override + @CheckForNull public E ceiling(E element) { int index = tailIndex(element, true); return (index == size()) ? null : elements.get(index); } @Override + @CheckForNull public E higher(E element) { int index = tailIndex(element, false); return (index == size()) ? null : elements.get(index); @@ -297,7 +303,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - int indexOf(@Nullable Object target) { + int indexOf(@CheckForNull Object target) { if (target == null) { return -1; } diff --git a/guava/src/com/google/common/collect/SortedIterable.java b/guava/src/com/google/common/collect/SortedIterable.java index d46e8afcd..64ec08ef3 100644 --- a/guava/src/com/google/common/collect/SortedIterable.java +++ b/guava/src/com/google/common/collect/SortedIterable.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import java.util.Comparator; import java.util.Iterator; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An {@code Iterable} whose elements are sorted relative to a {@code Comparator}, typically @@ -25,7 +26,8 @@ import java.util.Iterator; * @author Louis Wasserman */ @GwtCompatible -interface SortedIterable<T> extends Iterable<T> { +@ElementTypesAreNonnullByDefault +interface SortedIterable<T extends @Nullable Object> extends Iterable<T> { /** * Returns the {@code Comparator} by which the elements of this iterable are ordered, or {@code * Ordering.natural()} if the elements are ordered by their natural ordering. |