程序包 amo.lib.linq

接口 Stream<T>

类型参数:
T - the type of the wrapped Iterable<T>
所有超级接口:
Iterable<T>
所有已知子接口:
OrderedStream<T>
所有已知实现类:
AbstractStream, MapStream

public interface Stream<T>
extends Iterable<T>
Decorates Iterable<T> objects to enable use of Linq like expressions.
  • 方法概要

    修饰符和类型 方法 说明
    <TAccumulate>
    TAccumulate
    aggregate​(TAccumulate seed, Aggregator<T,​TAccumulate> aggregator)
    Applies an accumulator function over a sequence.
    int count()
    Returns the number of elements in a sequence.
    Stream<T> distinct()
    Returns distinct elements from a sequence by using the object equals() to compare values.
    T find​(Predicate<T> predicate)
    find目前使用的where,可以为find添加独立的Stream支持,找到一个equ时就终止next,修改where,在next时记录是否已经有匹配的,如果有了,hasnext返回 false,反正find就只返回一个
    List<T> findAll​(Predicate<T> predicate)  
    T first()
    Returns the first element of a sequence; this method throws an exception if the sequence is empty.
    T first​(Predicate<T> predicate)
    Returns the first element in a sequence that satisfies the specified condition; this method throws an exception if no element in the sequence satisfies the condition.
    <TKey> Stream<Grouping<TKey,​T>> groupBy​(Selector<T,​TKey> keySelector)
    Groups the elements of a sequence according to a specified key selector function.
    <TKey,​ TElement>
    Stream<Grouping<TKey,​TElement>>
    groupBy​(Selector<T,​TKey> keySelector, Selector<T,​TElement> elementSelector)
    Groups the elements of a sequence according to a specified key selector function.
    <TKey extends Comparable<TKey>>
    OrderedStream<T>
    orderBy​(Selector<T,​TKey> keySelector)
    Sorts the elements of a sequence in ascending order according to a key.
    <TKey> OrderedStream<T> orderBy​(Selector<T,​TKey> keySelector, Comparator<TKey> comparator)
    Sorts the elements of a sequence in ascending order according to a key.
    <TKey extends Comparable<TKey>>
    OrderedStream<T>
    orderByDescending​(Selector<T,​TKey> keySelector)
    Sorts the elements of a sequence in descending order according to a key.
    <TKey> OrderedStream<T> orderByDescending​(Selector<T,​TKey> keySelector, Comparator<TKey> comparator)
    Sorts the elements of a sequence in descending order according to a key.
    <TResult> Stream<TResult> select​(Selector<T,​TResult> selector)
    Projects each element of a sequence into a new form.
    Stream<T> skip​(int count)
    Skips a specified number of contiguous elements from the start of a sequence then returns remaining elements.
    Stream<T> take​(int count)
    Returns a specified number of contiguous elements from the start of a sequence.
    List<T> toList()
    Creates a List from a Stream.
    Stream<T> where​(Predicate<T> predicate)
    Filters a sequence of values based on a predicate.

    从接口继承的方法 java.lang.Iterable

    forEach, iterator, spliterator
  • 方法详细资料

    • where

      Stream<T> where​(Predicate<T> predicate)
      Filters a sequence of values based on a predicate.
      参数:
      predicate - A function to test each element for a condition.
      返回:
      An Stream of type T that contains elements from the input sequence that satisfy the condition.
    • select

      <TResult> Stream<TResult> select​(Selector<T,​TResult> selector)
      Projects each element of a sequence into a new form.
      类型参数:
      TResult - The type of the value returned by selector.
      参数:
      selector - A transform function to apply to each element.
      返回:
      An Stream of type TResult whose elements are the result of invoking the transform function on each element of source.
    • find

      T find​(Predicate<T> predicate)
      find目前使用的where,可以为find添加独立的Stream支持,找到一个equ时就终止next,修改where,在next时记录是否已经有匹配的,如果有了,hasnext返回 false,反正find就只返回一个
      参数:
      predicate - predicate
      返回:
      An Stream of type T that equal elements from the input sequence that satisfy the condition.
    • findAll

      List<T> findAll​(Predicate<T> predicate)
    • groupBy

      <TKey,​ TElement> Stream<Grouping<TKey,​TElement>> groupBy​(Selector<T,​TKey> keySelector, Selector<T,​TElement> elementSelector)
      Groups the elements of a sequence according to a specified key selector function.
      类型参数:
      TKey - The type of the key returned by keySelector.
      TElement - The type of the element returned by elementSelector.
      参数:
      keySelector - A function to extract the key for each source element.
      elementSelector - A function to map each source element to an element into a Grouping.
      返回:
      An Stream of type Grouping where each Grouping object contains a sequence of objects and a key (TKey, TResult respectively).
    • groupBy

      <TKey> Stream<Grouping<TKey,​T>> groupBy​(Selector<T,​TKey> keySelector)
      Groups the elements of a sequence according to a specified key selector function.
      类型参数:
      TKey - The type of the key returned by keySelector.
      参数:
      keySelector - A function to extract the key for each source element.
      返回:
      An Stream of type Grouping where each Grouping object contains a sequence of objects and a key (TKey, TResult respectively).
    • orderBy

      <TKey> OrderedStream<T> orderBy​(Selector<T,​TKey> keySelector, Comparator<TKey> comparator)
      Sorts the elements of a sequence in ascending order according to a key.
      类型参数:
      TKey - The type of the key returned by keySelector.
      参数:
      keySelector - A function to extract a key from an element.
      comparator - An Comparator to compare keys.
      返回:
      An Stream of type T whose elements are sorted according to a key.
    • orderBy

      <TKey extends Comparable<TKey>> OrderedStream<T> orderBy​(Selector<T,​TKey> keySelector)
      Sorts the elements of a sequence in ascending order according to a key.
      类型参数:
      TKey - The type of the key returned by keySelector.
      参数:
      keySelector - A function to extract a key from an element.
      返回:
      An Stream of type T whose elements are sorted according to a key.
    • orderByDescending

      <TKey> OrderedStream<T> orderByDescending​(Selector<T,​TKey> keySelector, Comparator<TKey> comparator)
      Sorts the elements of a sequence in descending order according to a key.
      类型参数:
      TKey - The type of the key returned by keySelector.
      参数:
      keySelector - A function to extract a key from an element.
      comparator - An Comparator to compare keys.
      返回:
      An Stream of type T whose elements are sorted according to a key.
    • orderByDescending

      <TKey extends Comparable<TKey>> OrderedStream<T> orderByDescending​(Selector<T,​TKey> keySelector)
      Sorts the elements of a sequence in descending order according to a key.
      类型参数:
      TKey - The type of the key returned by keySelector.
      参数:
      keySelector - A function to extract a key from an element.
      返回:
      An Stream of type T whose elements are sorted according to a key.
    • aggregate

      <TAccumulate> TAccumulate aggregate​(TAccumulate seed, Aggregator<T,​TAccumulate> aggregator)
      Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
      类型参数:
      TAccumulate - The type of the accumulator value.
      参数:
      seed - The initial accumulator value.
      aggregator - An accumulator function to be invoked on each element.
      返回:
      The transformed final accumulator value.
    • take

      Stream<T> take​(int count)
      Returns a specified number of contiguous elements from the start of a sequence.
      参数:
      count - The number of elements to return.
      返回:
      An Stream of type T that contains the specified number of elements from the start of the input sequence.
    • skip

      Stream<T> skip​(int count)
      Skips a specified number of contiguous elements from the start of a sequence then returns remaining elements.
      参数:
      count - The number of elements to skip.
      返回:
      An Stream of type T that contains the elements after the number of elements skipped from the start of the input sequence.
    • distinct

      Stream<T> distinct()
      Returns distinct elements from a sequence by using the object equals() to compare values.
      返回:
      An Stream of type T that contains distinct elements from the source sequence.
    • count

      int count()
      Returns the number of elements in a sequence.
      返回:
      The number of elements in the input sequence.
    • toList

      List<T> toList()
      Creates a List from a Stream.
      返回:
      A List of type T that contains elements from the input sequence.
    • first

      T first()
      Returns the first element of a sequence; this method throws an exception if the sequence is empty.
      返回:
      The first element in the specified sequence.
      抛出:
      NoSuchElementException - if the sequence is empty.
    • first

      T first​(Predicate<T> predicate)
      Returns the first element in a sequence that satisfies the specified condition; this method throws an exception if no element in the sequence satisfies the condition.
      参数:
      predicate - A function to test each element for a condition.
      返回:
      The first element in the sequence that passes the test in the specified predicate function.
      抛出:
      NoSuchElementException - if no element in the sequence satisfies the condition.