diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java index 15963e4d9d05..53aa84b77a48 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java @@ -663,6 +663,22 @@ public E last() { return descendingIterator().next(); } + /** + * @since NEXT. Note, however, that Java 21 users can call this method with any version of Guava. + */ + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final E getFirst() { + return first(); + } + + /** + * @since NEXT. Note, however, that Java 21 users can call this method with any version of Guava. + */ + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final E getLast() { + return last(); + } + /** * Guaranteed to throw an exception and leave the set unmodified. * @@ -697,6 +713,68 @@ public final E pollLast() { throw new UnsupportedOperationException(); } + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @CanIgnoreReturnValue + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final E removeFirst() { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @CanIgnoreReturnValue + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final E removeLast() { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final void addFirst(E e) { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final void addLast(E e) { + throw new UnsupportedOperationException(); + } + @GwtIncompatible // NavigableSet @LazyInit @CheckForNull @@ -715,6 +793,16 @@ public ImmutableSortedSet descendingSet() { return result; } + /** + * @since NEXT. Note, however, that a variant of this method with return type {@link NavigableSet} + * is available to Java 21 users with any version of Guava. + */ + @GwtIncompatible // NavigableSet + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final ImmutableSortedSet reversed() { + return descendingSet(); + } + // Most classes should implement this as new DescendingImmutableSortedSet(this), // but we push down that implementation because ProGuard can't eliminate it even when it's always // overridden. diff --git a/guava/src/com/google/common/collect/ImmutableSortedSet.java b/guava/src/com/google/common/collect/ImmutableSortedSet.java index b06de212bbb7..3ec7e0f4d9ed 100644 --- a/guava/src/com/google/common/collect/ImmutableSortedSet.java +++ b/guava/src/com/google/common/collect/ImmutableSortedSet.java @@ -731,6 +731,22 @@ public E last() { return descendingIterator().next(); } + /** + * @since NEXT. Note, however, that Java 21 users can call this method with any version of Guava. + */ + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final E getFirst() { + return first(); + } + + /** + * @since NEXT. Note, however, that Java 21 users can call this method with any version of Guava. + */ + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final E getLast() { + return last(); + } + /** * Guaranteed to throw an exception and leave the set unmodified. * @@ -765,6 +781,68 @@ public final E pollLast() { throw new UnsupportedOperationException(); } + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @CanIgnoreReturnValue + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final E removeFirst() { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @CanIgnoreReturnValue + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final E removeLast() { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final void addFirst(E e) { + throw new UnsupportedOperationException(); + } + + /** + * Guaranteed to throw an exception and leave the set unmodified. + * + * @since NEXT + * @throws UnsupportedOperationException always + * @deprecated Unsupported operation. + */ + @Deprecated + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull + public final void addLast(E e) { + throw new UnsupportedOperationException(); + } + @GwtIncompatible // NavigableSet @LazyInit @CheckForNull @@ -783,6 +861,16 @@ public ImmutableSortedSet descendingSet() { return result; } + /** + * @since NEXT. Note, however, that a variant of this method with return type {@link NavigableSet} + * is available to Java 21 users with any version of Guava. + */ + @GwtIncompatible // NavigableSet + @SuppressWarnings("MissingOverride") // only an override under JDK 21+ + public final ImmutableSortedSet reversed() { + return descendingSet(); + } + // Most classes should implement this as new DescendingImmutableSortedSet(this), // but we push down that implementation because ProGuard can't eliminate it even when it's always // overridden.