Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [SequencedCollection](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html) methods to ImmutableSortedSet. #6796

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -715,6 +793,16 @@ public ImmutableSortedSet<E> 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<E> reversed() {
return descendingSet();
}

// Most classes should implement this as new DescendingImmutableSortedSet<E>(this),
// but we push down that implementation because ProGuard can't eliminate it even when it's always
// overridden.
Expand Down
88 changes: 88 additions & 0 deletions guava/src/com/google/common/collect/ImmutableSortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -783,6 +861,16 @@ public ImmutableSortedSet<E> 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<E> reversed() {
return descendingSet();
}

// Most classes should implement this as new DescendingImmutableSortedSet<E>(this),
// but we push down that implementation because ProGuard can't eliminate it even when it's always
// overridden.
Expand Down
Loading