Top Description Inners Constructors Methods
com.google.common.collect

pack-priv final Class CollectSpliterators

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT, java.lang.Math.max

Spliterator utilities for common.collect internals.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract static class
CollectSpliterators.FlatMapSpliterator<
the element type of the input spliterator
InElementT extends @Nullable Object
,
the element type of the output spliterators
OutElementT extends @Nullable Object
,
the type of the output spliterators
OutSpliteratorT extends Spliterator<OutElementT>
>

Implements the Stream#flatMap operation on spliterators.

pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
CollectSpliterators.FlatMapSpliteratorOfObject<
the element type of the input spliterator
InElementT extends @Nullable Object
,
the element type of the output spliterators
OutElementT extends @Nullable Object
>

Implementation of Stream#flatMap with an object spliterator output type.

pack-priv abstract static class
CollectSpliterators.FlatMapSpliteratorOfPrimitive<
the element type of the input spliterator
InElementT extends @Nullable Object
,
the (boxed) element type of the output spliterators
OutElementT extends @Nullable Object
,
the specialized consumer type for the primitive output type
OutConsumerT
,
the primitive spliterator type associated with OutElementT
OutSpliteratorT extends Spliterator.OfPrimitive<OutElementT, OutConsumerT, OutSpliteratorT>
>

Implementation of Stream#flatMap with a primitive spliterator output type.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <T extends @Nullable Object> Spliterator<T>
filter(Spliterator<T> fromSpliterator, Predicate<? super T> predicate)

Returns a Spliterator filtered by the specified predicate.

pack-priv static <InElementT extends @Nullable Object, OutElementT extends @Nullable Object> Spliterator<OutElementT>
flatMap(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator<OutElementT>> function, int topCharacteristics, long topSize)

Returns a Spliterator that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator.

pack-priv static <InElementT extends @Nullable Object> Spliterator.OfDouble
flatMapToDouble(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfDouble> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfDouble that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator.

pack-priv static <InElementT extends @Nullable Object> Spliterator.OfInt
flatMapToInt(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfInt> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfInt that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator.

pack-priv static <InElementT extends @Nullable Object> Spliterator.OfLong
flatMapToLong(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfLong> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfLong that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator.

pack-priv static <T extends @Nullable Object> Spliterator<T>
indexed(int size, int extraCharacteristics, IntFunction<T> function)

pack-priv static <T extends @Nullable Object> Spliterator<T>
indexed(int size, int extraCharacteristics, IntFunction<T> function, Comparator<? super T> comparator)

pack-priv static <InElementT extends @Nullable Object, OutElementT extends @Nullable Object> Spliterator<OutElementT>
map(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, ? extends OutElementT> function)

Returns a Spliterator over the elements of fromSpliterator mapped by function.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CollectSpliteratorsback to summary
private CollectSpliterators()

Method Detail

filterback to summary
pack-priv static <T extends @Nullable Object> Spliterator<T> filter(Spliterator<T> fromSpliterator, Predicate<? super T> predicate)

Returns a Spliterator filtered by the specified predicate.

flatMapback to summary
pack-priv static <InElementT extends @Nullable Object, OutElementT extends @Nullable Object> Spliterator<OutElementT> flatMap(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator<OutElementT>> function, int topCharacteristics, long topSize)

Returns a Spliterator that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator.

flatMapToDoubleback to summary
pack-priv static <InElementT extends @Nullable Object> Spliterator.OfDouble flatMapToDouble(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfDouble> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfDouble that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator. (If function returns null for an input, it is replaced with an empty stream.)

flatMapToIntback to summary
pack-priv static <InElementT extends @Nullable Object> Spliterator.OfInt flatMapToInt(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfInt> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfInt that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator. (If function returns null for an input, it is replaced with an empty stream.)

flatMapToLongback to summary
pack-priv static <InElementT extends @Nullable Object> Spliterator.OfLong flatMapToLong(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, Spliterator.OfLong> function, int topCharacteristics, long topSize)

Returns a Spliterator.OfLong that iterates over the elements of the spliterators generated by applying function to the elements of fromSpliterator. (If function returns null for an input, it is replaced with an empty stream.)

indexedback to summary
pack-priv static <T extends @Nullable Object> Spliterator<T> indexed(int size, int extraCharacteristics, IntFunction<T> function)
indexedback to summary
pack-priv static <T extends @Nullable Object> Spliterator<T> indexed(int size, int extraCharacteristics, IntFunction<T> function, Comparator<? super T> comparator)
mapback to summary
pack-priv static <InElementT extends @Nullable Object, OutElementT extends @Nullable Object> Spliterator<OutElementT> map(Spliterator<InElementT> fromSpliterator, Function<? super InElementT, ? extends OutElementT> function)

Returns a Spliterator over the elements of fromSpliterator mapped by function.

com.google.common.collect back to summary

pack-priv abstract Class CollectSpliterators.FlatMapSpliterator<InElementT extends @Nullable Object, OutElementT extends @Nullable Object, OutSpliteratorT extends java.util.Spliterator<OutElementT>>

extends Object
implements Spliterator<OutElementT extends @Nullable Object>
Class Inheritance
  • java.lang.Object
  • com.google.common.collect.CollectSpliterators.FlatMapSpliterator
All Implemented Interfaces
java.util.Spliterator
Known Direct Subclasses
com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfObject, com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfPrimitive
Type Parameters
<InElementT>
the element type of the input spliterator
<OutElementT>
the element type of the output spliterators
<OutSpliteratorT>
the type of the output spliterators

Implements the Stream#flatMap operation on spliterators.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
CollectSpliterators.FlatMapSpliterator.Factory<InElementT extends @Nullable Object, OutSpliteratorT extends Spliterator<?>>

Factory for constructing FlatMapSpliterator instances.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv long
pack-priv final CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT>
pack-priv final Spliterator<InElementT>
pack-priv final Function<? super InElementT, OutSpliteratorT>
pack-priv OutSpliteratorT

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliterator(OutSpliteratorT prefix, Spliterator<InElementT> from, Function<? super InElementT, OutSpliteratorT> function, CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT> factory, int characteristics, long estimatedSize)

Method Summary

Modifier and TypeMethod and Description
public final int
characteristics()

Implements java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements.
public final long
estimateSize()

Implements java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.
public final void
forEachRemaining(Consumer<? super OutElementT>
The action
action
)

Overrides default java.util.Spliterator.forEachRemaining.

Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
public final boolean
tryAdvance(Consumer<? super OutElementT>
The action whose operation is performed at-most once
action
)

Implements java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false.
public final OutSpliteratorT
trySplit()

Implements java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

characteristicsback to summary
pack-priv int characteristics
estimatedSizeback to summary
pack-priv long estimatedSize
factoryback to summary
pack-priv final CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT> factory
fromback to summary
pack-priv final Spliterator<InElementT> from
functionback to summary
pack-priv final Function<? super InElementT, OutSpliteratorT> function
prefixback to summary
pack-priv OutSpliteratorT prefix
Annotations
@Weak
@CheckForNull

Constructor Detail

FlatMapSpliteratorback to summary
pack-priv FlatMapSpliterator(OutSpliteratorT prefix, Spliterator<InElementT> from, Function<? super InElementT, OutSpliteratorT> function, CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT> factory, int characteristics, long estimatedSize)

Method Detail

characteristicsback to summary
public final int characteristics()

Implements java.util.Spliterator.characteristics.

Doc from java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements. The result is represented as ORed values from ORDERED, DISTINCT, SORTED, SIZED, NONNULL, IMMUTABLE, CONCURRENT, SUBSIZED. Repeated calls to characteristics() on a given spliterator, prior to or in-between calls to trySplit, should always return the same result.

If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.

Returns:int

a representation of characteristics

Annotations
@Override
estimateSizeback to summary
public final long estimateSize()

Implements java.util.Spliterator.estimateSize.

Doc from java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

If this Spliterator is SIZED and has not yet been partially traversed or split, or this Spliterator is SUBSIZED and has not yet been partially traversed, this estimate must be an accurate count of elements that would be encountered by a complete traversal. Otherwise, this estimate may be arbitrarily inaccurate, but must decrease as specified across invocations of trySplit.

Returns:long

the estimated size, or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

Annotations
@Override
forEachRemainingback to summary
public final void forEachRemaining(Consumer<? super OutElementT> action)

Overrides default java.util.Spliterator.forEachRemaining.

Doc from java.util.Spliterator.forEachRemaining.

Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception. If this Spliterator is ORDERED, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:Consumer<? super OutElementT>

The action

Annotations
@Override
tryAdvanceback to summary
public final boolean tryAdvance(Consumer<? super OutElementT> action)

Implements java.util.Spliterator.tryAdvance.

Doc from java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false. If this Spliterator is ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:Consumer<? super OutElementT>

The action whose operation is performed at-most once

Returns:boolean

false if no remaining elements existed upon entry to this method, else true.

Annotations
@Override
trySplitback to summary
public final OutSpliteratorT trySplit()

Implements java.util.Spliterator.trySplit.

Doc from java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

If this Spliterator is ORDERED, the returned Spliterator must cover a strict prefix of the elements.

Unless this Spliterator covers an infinite number of elements, repeated calls to trySplit() must eventually return null. Upon non-null return:

  • the value reported for estimateSize() before splitting, must, after splitting, be greater than or equal to estimateSize() for this and the returned Spliterator; and
  • if this Spliterator is SUBSIZED, then estimateSize() for this spliterator before splitting must be equal to the sum of estimateSize() for this and the returned Spliterator after splitting.

This method may return null for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.

Returns:OutSpliteratorT

a Spliterator covering some portion of the elements, or null if this spliterator cannot be split

Annotations
@Override
@CheckForNull
com.google.common.collect back to summary

pack-priv Interface CollectSpliterators.FlatMapSpliterator.Factory<InElementT extends @Nullable Object, OutSpliteratorT extends java.util.Spliterator<?>>

Annotations
@FunctionalInterface

Factory for constructing FlatMapSpliterator instances.

Method Summary

Modifier and TypeMethod and Description
public OutSpliteratorT
newFlatMapSpliterator(OutSpliteratorT prefix, Spliterator<InElementT> fromSplit, Function<? super InElementT, OutSpliteratorT> function, int splitCharacteristics, long estSplitSize)

Method Detail

newFlatMapSpliteratorback to summary
public OutSpliteratorT newFlatMapSpliterator(OutSpliteratorT prefix, Spliterator<InElementT> fromSplit, Function<? super InElementT, OutSpliteratorT> function, int splitCharacteristics, long estSplitSize)
com.google.common.collect back to summary

pack-priv final Class CollectSpliterators.FlatMapSpliteratorOfDouble<InElementT extends @Nullable Object>

extends CollectSpliterators.FlatMapSpliteratorOfPrimitive<InElementT extends @Nullable Object, Double, DoubleConsumer, Spliterator.OfDouble>
implements OfDouble
Class Inheritance
All Implemented Interfaces
java.util.Spliterator.OfDouble, java.util.Spliterator.OfPrimitive, java.util.Spliterator

Implementation of flatMapToDouble.

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliteratorOfDouble(Spliterator.OfDouble prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfDouble> function, int characteristics, long estimatedSize)

Method Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfPrimitive:
forEachRemainingtryAdvance

Constructor Detail

FlatMapSpliteratorOfDoubleback to summary
pack-priv FlatMapSpliteratorOfDouble(Spliterator.OfDouble prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfDouble> function, int characteristics, long estimatedSize)
com.google.common.collect back to summary

pack-priv final Class CollectSpliterators.FlatMapSpliteratorOfInt<InElementT extends @Nullable Object>

extends CollectSpliterators.FlatMapSpliteratorOfPrimitive<InElementT extends @Nullable Object, Integer, IntConsumer, Spliterator.OfInt>
implements OfInt
Class Inheritance
All Implemented Interfaces
java.util.Spliterator.OfInt, java.util.Spliterator.OfPrimitive, java.util.Spliterator

Implementation of flatMapToInt.

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliteratorOfInt(Spliterator.OfInt prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfInt> function, int characteristics, long estimatedSize)

Method Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfPrimitive:
forEachRemainingtryAdvance

Constructor Detail

FlatMapSpliteratorOfIntback to summary
pack-priv FlatMapSpliteratorOfInt(Spliterator.OfInt prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfInt> function, int characteristics, long estimatedSize)
com.google.common.collect back to summary

pack-priv final Class CollectSpliterators.FlatMapSpliteratorOfLong<InElementT extends @Nullable Object>

extends CollectSpliterators.FlatMapSpliteratorOfPrimitive<InElementT extends @Nullable Object, Long, LongConsumer, Spliterator.OfLong>
implements OfLong
Class Inheritance
All Implemented Interfaces
java.util.Spliterator.OfLong, java.util.Spliterator.OfPrimitive, java.util.Spliterator

Implementation of flatMapToLong.

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliteratorOfLong(Spliterator.OfLong prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfLong> function, int characteristics, long estimatedSize)

Method Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfPrimitive:
forEachRemainingtryAdvance

Constructor Detail

FlatMapSpliteratorOfLongback to summary
pack-priv FlatMapSpliteratorOfLong(Spliterator.OfLong prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator.OfLong> function, int characteristics, long estimatedSize)
com.google.common.collect back to summary

pack-priv final Class CollectSpliterators.FlatMapSpliteratorOfObject<InElementT extends @Nullable Object, OutElementT extends @Nullable Object>

extends CollectSpliterators.FlatMapSpliterator<InElementT extends @Nullable Object, OutElementT extends @Nullable Object, Spliterator<OutElementT extends @Nullable Object>>
Class Inheritance
Type Parameters
<InElementT>
the element type of the input spliterator
<OutElementT>
the element type of the output spliterators

Implementation of Stream#flatMap with an object spliterator output type.

To avoid having this type, we could use FlatMapSpliterator directly. The main advantages to having the type are the ability to use its constructor reference below and the parallelism with the primitive version. In short, it makes its caller (flatMap) simpler.

Field Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliterator:
characteristicsestimatedSizefactoryfromfunctionprefix

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliteratorOfObject(Spliterator<OutElementT> prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator<OutElementT>> function, int characteristics, long estimatedSize)

Method Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliterator:
characteristicsestimateSizeforEachRemainingtryAdvancetrySplit

Constructor Detail

FlatMapSpliteratorOfObjectback to summary
pack-priv FlatMapSpliteratorOfObject(Spliterator<OutElementT> prefix, Spliterator<InElementT> from, Function<? super InElementT, Spliterator<OutElementT>> function, int characteristics, long estimatedSize)
com.google.common.collect back to summary

pack-priv abstract Class CollectSpliterators.FlatMapSpliteratorOfPrimitive<InElementT extends @Nullable Object, OutElementT extends @Nullable Object, OutConsumerT, OutSpliteratorT extends Spliterator.OfPrimitive<OutElementT, OutConsumerT, OutSpliteratorT>>

extends CollectSpliterators.FlatMapSpliterator<InElementT extends @Nullable Object, OutElementT extends @Nullable Object, OutSpliteratorT extends Spliterator.OfPrimitive<OutElementT, OutConsumerT, OutSpliteratorT>>
implements Spliterator.OfPrimitive<OutElementT extends @Nullable Object, OutConsumerT, OutSpliteratorT extends Spliterator.OfPrimitive<OutElementT, OutConsumerT, OutSpliteratorT>>
Class Inheritance
All Implemented Interfaces
java.util.Spliterator.OfPrimitive, java.util.Spliterator
Known Direct Subclasses
com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfInt, com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfLong, com.google.common.collect.CollectSpliterators.FlatMapSpliteratorOfDouble
Type Parameters
<InElementT>
the element type of the input spliterator
<OutElementT>
the (boxed) element type of the output spliterators
<OutConsumerT>
the specialized consumer type for the primitive output type
<OutSpliteratorT>
the primitive spliterator type associated with OutElementT

Implementation of Stream#flatMap with a primitive spliterator output type.

Field Summary

Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliterator:
characteristicsestimatedSizefactoryfromfunctionprefix

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapSpliteratorOfPrimitive(OutSpliteratorT prefix, Spliterator<InElementT> from, Function<? super InElementT, OutSpliteratorT> function, CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT> factory, int characteristics, long estimatedSize)

Method Summary

Modifier and TypeMethod and Description
public final void
forEachRemaining(OutConsumerT
The action
action
)

Overrides default java.util.Spliterator.OfPrimitive.forEachRemaining.

Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
public final boolean
tryAdvance(OutConsumerT
The action
action
)

Implements java.util.Spliterator.OfPrimitive.tryAdvance.

If a remaining element exists, performs the given action on it, returning true; else returns false.
Inherited from com.google.common.collect.CollectSpliterators.FlatMapSpliterator:
characteristicsestimateSizeforEachRemainingtryAdvancetrySplit

Constructor Detail

FlatMapSpliteratorOfPrimitiveback to summary
pack-priv FlatMapSpliteratorOfPrimitive(OutSpliteratorT prefix, Spliterator<InElementT> from, Function<? super InElementT, OutSpliteratorT> function, CollectSpliterators.FlatMapSpliterator.Factory<InElementT, OutSpliteratorT> factory, int characteristics, long estimatedSize)

Method Detail

forEachRemainingback to summary
public final void forEachRemaining(OutConsumerT action)

Overrides default java.util.Spliterator.OfPrimitive.forEachRemaining.

Doc from java.util.Spliterator.OfPrimitive.forEachRemaining.

Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception. If this Spliterator is ORDERED, actions are performed in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:OutConsumerT

The action

Annotations
@Override
tryAdvanceback to summary
public final boolean tryAdvance(OutConsumerT action)

Implements java.util.Spliterator.OfPrimitive.tryAdvance.

Doc from java.util.Spliterator.OfPrimitive.tryAdvance.

If a remaining element exists, performs the given action on it, returning true; else returns false. If this Spliterator is ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:OutConsumerT

The action

Returns:boolean

false if no remaining elements existed upon entry to this method, else true.

Annotations
@Override