Skip to content

Commit

Permalink
Add an overload of spliterator() to the Android flavor of one of ou…
Browse files Browse the repository at this point in the history
…r classes.

This is a further attempt to shake out any problems in advance of exposing "real" Java 8 APIs (google#6567). If something goes wrong with `spliterator()`, I think we could remove it without breaking callers: Either it's an override (in which case calls to it will continue to work after it's removed) or it's not (in which case Java 8 APIs aren't available, so calls to it would never have worked.)

RELNOTES=n/a
PiperOrigin-RevId: 603812702
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 3, 2024
1 parent 7e0e6ed commit 6e2d0d8
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -176,13 +178,26 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple
* These are properties of the collection as a whole; SIZED and SUBSIZED are more properties of
* the spliterator implementation.
*/
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
// @IgnoreJRERequirement is not necessary because this compiles down to a constant.
// (which is fortunate because Animal Sniffer doesn't look for @IgnoreJRERequirement on fields)
static final int SPLITERATOR_CHARACTERISTICS =
Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED;

ImmutableCollection() {}

/** Returns an unmodifiable iterator across the elements in this collection. */
@Override
public abstract UnmodifiableIterator<E> iterator();

@Override
@SuppressWarnings({"AndroidJdkLibsChecker", "Java7ApiChecker"})
@IgnoreJRERequirement // used only from APIs with Java 8 types in them
// (not used within guava-android as of this writing, but we include it in the jar as a test)
public Spliterator<E> spliterator() {
return Spliterators.spliterator(this, SPLITERATOR_CHARACTERISTICS);
}

private static final Object[] EMPTY_ARRAY = {};

@Override
Expand Down

0 comments on commit 6e2d0d8

Please sign in to comment.