接口 FastStream<T>

所有超级接口:
Iterable<T>
所有已知实现类:
FastStream.Concatenated, FastStream.ConcatenatedN, FastStream.Distinct, FastStream.Filtered, FastStream.FlatMapped, FastStream.Group, FastStream.Grouped, FastStream.Mapped, FastStream.OfN, FastStream.OfSingle, FastStream.Peeked, FastStream.Reversed, FastStream.Sliced, FastStream.Sorted, FastStream.Wrapped, FastStream.WrappedSpl

public interface FastStream<T> extends Iterable<T>
FastStream
  • 字段详细资料

    • EMPTY

      static final FastStream<?> EMPTY
      Static empty instance. You want empty() for return type inference.
  • 方法详细资料

    • empty

      static <T> FastStream<T> empty()
      Returns an empty FastStream singleton.
      返回:
      An empty FastStream.
    • of

      static <T> FastStream<T> of()
      Overload of empty() for convenience.
      返回:
      An empty FastStream.
    • of

      static <T> FastStream<T> of(Iterable<? extends T> itr)
      Wraps the provided Iterable to a FastStream

      This method may return the same object if it's already a FastStream, the empty singleton if it's a Collection and provably empty, or a new Wrapped instance.

      The Wrapped instance is careful to expose the underlying iterator of the provided Iterable, as well as forward calls to Iterable.forEach(java.util.function.Consumer<? super T>)

      参数:
      itr - The Iterable to wrap.
      返回:
      The wrapped Iterable.
    • of

      static <T> FastStream<T> of(Spliterator<? extends T> itr)
      Wraps the provided Spliterator to a FastStream.
      参数:
      itr - The Spliterator.
      返回:
      The FastStream
    • of

      static <T> FastStream<T> of(Stream<? extends T> stream)
      Wrap the provided Java Stream to a FastStream.

      This method is provided to support wrapping API's which only provide Stream outputs, into FastStream. This implicitly uses the of(Spliterator).

      Where possible, raw Spliterator or Iterator inputs should be used.

      NOTE: Using Java Stream operations combined with FastStream operations may result in poor performance.

      参数:
      stream - The stream.
      返回:
      The FastStream
    • of

      static <T> FastStream<T> of(T thing)
      Returns a FastStream for a single object.
      参数:
      thing - The thing.
      返回:
      The FastStream for the single object.
    • ofNullable

      static <T> FastStream<T> ofNullable(@Nullable T thing)
      Returns a FastStream for a single object.

      If the provided object is null, an empty FastStream is returned.

      参数:
      thing - The thing.
      返回:
      The FastStream for the single object or empty.
    • of

      static <T> FastStream<T> of(Optional<? extends T> opt)
      Returns a FastStream for an Optional.

      If the provided Optional is not Optional.isPresent(), an empty FastStream is returned.

      参数:
      opt - The Optional.
      返回:
      The FastStream for the Optional or empty.
    • of

      @SafeVarargs static <T> FastStream<T> of(T... things)
      Returns a FastStream for an array of objects.

      This method is preferred over a wrapper such as Arrays.asList(T...) due to fewer allocations and virtual/interface calls.

      参数:
      things - The thing.
      返回:
      The FastStream for the objects.
    • concat

      @SafeVarargs static <T> FastStream<T> concat(Iterable<? extends T>... iterables)
      Returns a concatenated FastStream containing the elements from the provided Iterable array.
      参数:
      iterables - The Iterables to concatenate.
      返回:
      The concatenated FastStream.
    • concatMany

      static <T> FastStream<T> concatMany(Iterable<? extends Iterable<? extends T>> iterables)
      Returns a concatenated FastStream containing the elements from the provided Iterables Iterable.
      参数:
      iterables - The Iterables to concatenate.
      返回:
      The concatenated FastStream.
    • infer

      static <T> FastStream.TypeCheck<T,T> infer()
      Used to nudge Javac to perform looser inference on return types of some collecting functions provided in here.
    • concat

      default FastStream<T> concat(Iterable<? extends T> other)
      Returns a FastStream with the provided Iterable concatenated after.
      参数:
      other - The other
      返回:
      THe concatenated FastStream.
    • filter

      default FastStream<T> filter(Predicate<? super T> pred)
      Returns a FastStream containing all elements that pass the provided Predicate filter.
      参数:
      pred - The Predicate to apply.
      返回:
      The filtered FastStream.
    • filterNot

      default FastStream<T> filterNot(Predicate<? super T> pred)
      Returns a FastStream containing all elements that fail the provided Predicate filter.
      参数:
      pred - The Predicate to apply.
      返回:
      The filtered FastStream.
    • map

      default <R> FastStream<R> map(Function<? super T,? extends R> func)
      Returns a FastStream with each element transformed by the provided Function.
      参数:
      func - The Function to apply.
      返回:
      The transformed FastStream.
    • flatMap

      default <R> FastStream<R> flatMap(Function<? super T,? extends Iterable<? extends R>> func)
      Returns a FastStream with each element transformed by the provided Function concatenated together.
      参数:
      func - The Function to apply producing the Iterable for concatenation.
      返回:
      The flat mapped FastStream.
    • distinct

      default FastStream<T> distinct()
      Returns a FastStream containing all elements that are unique according to their Object.hashCode()/Object.equals(java.lang.Object) identity.
      返回:
      The distinct filtered FastStream.
    • groupBy

      default <K> FastStream<FastStream.Group<K,T>> groupBy(Function<? super T,? extends K> keyFunc)
      Returns a FastStream containing all elements grouped by a key. The provided Function is used to extract the key from the element.
      参数:
      keyFunc - The key Function.
      返回:
      The Grouped FastStream
    • groupBy

      default <K, V> FastStream<FastStream.Group<K,V>> groupBy(Function<? super T,? extends K> keyFunc, Function<? super T,? extends V> valueFunc)
      Returns a FastStream containing all elements grouped by a key. The provided Function is used to extract the key from the element.
      参数:
      keyFunc - The key Function.
      valueFunc - The value Function.
      返回:
      The Grouped FastStream
    • sorted

      default FastStream<T> sorted()
      Returns a FastStream sorted based on the elements natural sort order.

      This requires that T implements Comparable.

      返回:
      The sorted FastStream.
    • sorted

      default FastStream<T> sorted(Comparator<? super T> comparator)
      Returns a FastStream sorted based on the provided comparator.
      参数:
      comparator - The Comparator to apply.
      返回:
      The sorted FastStream.
    • reversed

      default FastStream<T> reversed()
      Returns a FastStream in reverse order.
      返回:
      The reversed FastStream.
    • peek

      default FastStream<T> peek(Consumer<? super T> cons)
      Returns a FastStream which listens to all the elements which pass to the next operation.
      参数:
      cons - The listener Consumer.
      返回:
      The FastStream.
    • limit

      default FastStream<T> limit(@org.jetbrains.annotations.Range(from=-1L, to=2147483647L) int max)
      Returns a FastStream which will let at most max elements pass.

      A special case of -1 is provided to indicate no max limit.

      参数:
      max - The maximum amount of elements to pass through, or -1.
      返回:
      The limited FastStream.
    • skip

      default FastStream<T> skip(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int n)
      Returns a FastStream which will skip n number of elements.
      参数:
      n - The number of elements to skip.
      返回:
      The skipping FastStream.
    • anyMatch

      default boolean anyMatch(Predicate<? super T> pred)
      Tests if any element in the FastStream matches the provided Predicate.
      参数:
      pred - The Predicate to apply.
      返回:
      If any element matches the Predicate.
    • allMatch

      default boolean allMatch(Predicate<? super T> pred)
      Tests if all elements in the FastStream match the provided Predicate.
      参数:
      pred - The Predicate to apply.
      返回:
      If all elements match the Predicate.
    • noneMatch

      default boolean noneMatch(Predicate<? super T> pred)
      Tests if no elements in the FastStream match the provided Predicate.
      参数:
      pred - The Predicate to apply.
      返回:
      If no elements match the Predicate.
    • isEmpty

      default boolean isEmpty()
      Tests if the stream is empty.

      This method is provided for convenience. Generally, using knownLength() or a collecting operation would achieve greater performance.

      返回:
      If the stream is empty.
    • knownLength

      default int knownLength()
      Returns the known length for the stream.

      This may return -1 if the stream contains operations that can't know their length before computing (filter operations).

      返回:
      The known length, or -1
    • knownLength

      default int knownLength(boolean consumeToCalculate)
      Returns the known length for the stream.

      If true is specified to consumeToCalculate causes operations which would not normally know their length prior to a terminal operation being applied, to cache their result under the assumption that the stream is about to be fully consumed.

      参数:
      consumeToCalculate - If the caller intends to consume the entire stream via Iterable.forEach(java.util.function.Consumer<? super T>) after calling.
      返回:
      The known length for the stream. {code -1} if the length is not known.
    • count

      default int count()
      Evaluates the stream, counting the number of elements contained within.
      返回:
      The number of elements in the stream.
    • fold

      @Nullable @Contract("!null,_ -> !null") default <U> U fold(@Nullable U identity, BiFunction<? super @Nullable U,? super T,? extends U> accumulator)
      Returns the result of a folding operation applied to the FastStream contents.
      参数:
      identity - The initial value.
      accumulator - The Function responsible for merging elements in the stream together.
      返回:
      The result of the fold operation. May be null if identity is null and the stream is empty.
    • fold

      default Optional<T> fold(BinaryOperator<T> accumulator)
      Returns the result of a folding operation applied to the FastStream contents.
      参数:
      accumulator - The Function responsible for merging elements in the stream together.
      返回:
      Optionally, the result of the fold operation. Will be empty if the FastStream contained no elements.
    • intSum

      default int intSum(ToIntFunction<? super T> func)
      Sum all elements in the stream to an integer, using the provided ToIntFunction to convert each element to an integer.
      参数:
      func - The ToIntFunction to apply.
      返回:
      The sum of the elements.
    • longSum

      default long longSum(ToLongFunction<? super T> func)
      Sum all elements in the stream to a long, using the provided ToLongFunction to convert each element to a long.
      参数:
      func - The ToLongFunction to apply.
      返回:
      The sum of the elements.
    • doubleSum

      default double doubleSum(ToDoubleFunction<? super T> func)
      Sum all elements in the stream to a double, using the provided ToDoubleFunction to convert each element to a double.
      参数:
      func - The ToDoubleFunction to apply.
      返回:
      The sum of the elements.
    • findFirst

      default Optional<T> findFirst()
      返回:
      Optionally, the first element in the stream.
    • first

      default T first()
      返回:
      The first element in the stream.
    • firstOrDefault

      @Nullable default T firstOrDefault()
      返回:
      The first element in the stream, or null.
    • firstOrDefault

      @Nullable @Contract("!null -> !null") default T firstOrDefault(@Nullable T _default)
      参数:
      _default - The default value to return if the stream is empty.
      返回:
      The first element in the stream, or _default.
    • findLast

      default Optional<T> findLast()
      返回:
      Optionally, the last element in the stream.
    • last

      default T last()
      返回:
      The last element in the stream.
    • lastOrDefault

      @Nullable default T lastOrDefault()
      返回:
      The last element in the stream, or null.
    • lastOrDefault

      @Nullable @Contract("!null -> !null") default T lastOrDefault(@Nullable T _default)
      参数:
      _default - The default value to return if the stream is empty.
      返回:
      The last element in the stream, or _default.
    • only

      default T only()
      返回:
      Returns the only element in the stream.
    • onlyOrDefault

      @Nullable default T onlyOrDefault()
      返回:
      Returns the only element in the steam. null if the stream is empty or contains more than one element.
    • onlyOrDefault

      @Nullable @Contract("!null->!null") default T onlyOrDefault(@Nullable T _default)
      参数:
      _default - The default value to return if the stream is empty or contains more than one element.
      返回:
      Returns the only element in the stream. _default if the stream is empty or contains more than one element.
    • maxBy

      default T maxBy(ToIntFunction<T> func)
      Returns the element in the stream with the highest value returned by the provided ToIntFunction.
      参数:
      func - The ToIntFunction.
      返回:
      The maximum value.
    • maxByOrDefault

      @Nullable default T maxByOrDefault(ToIntFunction<T> func)
      Returns the element in the stream with the highest value returned by the provided ToIntFunction.
      参数:
      func - The ToIntFunction.
      返回:
      The maximum value or null if the stream is empty.
    • maxByOrDefault

      @Nullable @Contract("_,!null->!null") default T maxByOrDefault(ToIntFunction<T> func, @Nullable T _default)
      Returns the element in the stream with the highest value returned by the provided ToIntFunction.
      参数:
      func - The ToIntFunction.
      _default - The default value to return if the stream is empty.
      返回:
      The maximum value or _default if the stream is empty.
    • toList

      default ArrayList<T> toList()
      Collects this stream into an ArrayList.
      返回:
      The ArrayList.
    • toList

      default <R> List<R> toList(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into an ArrayList.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The ArrayList.
    • toLinkedList

      default LinkedList<T> toLinkedList()
      Collects this stream into a LinkedList.
      返回:
      The LinkedList.
    • toLinkedList

      default <R> LinkedList<R> toLinkedList(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into a LinkedList.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The LinkedList.
    • toImmutableList

      default com.google.common.collect.ImmutableList<T> toImmutableList()
      Collects this stream into a ImmutableList.
      返回:
      The ImmutableList.
    • toImmutableList

      default <R> com.google.common.collect.ImmutableList<R> toImmutableList(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into a ImmutableList.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The ImmutableList.
    • toSet

      default HashSet<T> toSet()
      Collects this stream into a HashSet.
      返回:
      The HashSet.
    • toSet

      default <R> HashSet<R> toSet(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into a HashSet.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The HashSet.
    • toLinkedHashSet

      default LinkedHashSet<T> toLinkedHashSet()
      Collects this stream into a LinkedHashSet.
      返回:
      The LinkedHashSet.
    • toLinkedHashSet

      default <R> LinkedHashSet<R> toLinkedHashSet(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into a LinkedHashSet.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The LinkedHashSet.
    • toImmutableSet

      default com.google.common.collect.ImmutableSet<T> toImmutableSet()
      Collects this stream into a ImmutableSet.
      返回:
      The ImmutableSet.
    • toImmutableSet

      default <R> com.google.common.collect.ImmutableSet<R> toImmutableSet(FastStream.TypeCheck<R,? super T> check)
      Collects this stream into a ImmutableSet.
      参数:
      check - Call infer() in this argument for flexible return inference.
      返回:
      The ImmutableSet.
    • toArray

      default Object[] toArray()
      Collects this stream into an Object[].
      返回:
      The Object[].
    • toArray

      default T[] toArray(T[] arr)
      Collects the stream into a T[].
      参数:
      arr - The template array to use. If the array is large enough to fit all elements in the stream, this will be used with a single null element after the last element.
      返回:
      The T[].
    • toMap

      default <K, V> HashMap<K,V> toMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc)
      Collects this stream into a HashMap.

      In the event of a collision, the first value will be used.

      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      返回:
      The HashMap.
    • toMap

      default <K, V> HashMap<K,V> toMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc, BinaryOperator<V> mergeFunc)
      Collects this stream into a HashMap.
      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      mergeFunc - The BinaryOperator to resolve merge conflicts.
      返回:
      The HashMap.
    • toLinkedHashMap

      default <K, V> LinkedHashMap<K,V> toLinkedHashMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc)
      Collects this stream into a LinkedHashMap.

      In the event of a collision, the first value will be used.

      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      返回:
      The LinkedHashMap.
    • toLinkedHashMap

      default <K, V> LinkedHashMap<K,V> toLinkedHashMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc, BinaryOperator<V> mergeFunc)
      Collects this stream into a LinkedHashMap.
      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      mergeFunc - The BinaryOperator to resolve merge conflicts.
      返回:
      The LinkedHashMap.
    • toImmutableMap

      default <K, V> com.google.common.collect.ImmutableMap<K,V> toImmutableMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc)
      Collects this stream into an ImmutableMap.

      In the event of a collision, the first value will be used.

      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      返回:
      The ImmutableMap.
    • toImmutableMap

      default <K, V> com.google.common.collect.ImmutableMap<K,V> toImmutableMap(Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc, BinaryOperator<V> mergeFunc)
      Collects this stream into an ImmutableMap.
      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      mergeFunc - The BinaryOperator to resolve merge conflicts.
      返回:
      The ImmutableMap.
    • toMap

      default <K, V, M extends Map<K, V>> M toMap(M map, Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc)
      Collects this stream into the provided Map.

      In the event of a collision, the first value will be used.

      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      返回:
      The Map.
    • toMap

      default <K, V, M extends Map<K, V>> M toMap(M map, Function<? super T,? extends K> kFunc, Function<? super T,? extends V> vFunc, BinaryOperator<V> mergeFunc)
      Collects this stream into the provided Map.
      参数:
      kFunc - The Function to extracting the key.
      vFunc - The Function to extracting the value.
      mergeFunc - The BinaryOperator to resolve merge conflicts.
      返回:
      The Map.
    • join

      default String join(String sep)
      Join all elements of this stream together into a String, separated by sep.

      This function will use the element's Object.toString().

      参数:
      sep - The seperator.
      返回:
      The joined String.