Interface DataStream<V>

Type Parameters:
V - the type of each value
All Superinterfaces:
Displayable, Formattable<V>, Iterable<V>
All Known Implementing Classes:
ImmutableDataStream, Samples

public interface DataStream<V> extends Formattable<V>, Iterable<V>
A stream of values.
  • Method Details

    • size

      int size()
      Returns the number of values in this data stream.
      Returns:
      the number of values
    • stream

      Stream<V> stream()
      Returns a Stream of the values in this data stream.
      Returns:
      the stream
    • isEmpty

      default boolean isEmpty()
      Returns true if this data stream is empty.
      Returns:
      true if this data stream is empty; false otherwise
    • values

      default List<V> values()
      Returns the values in this stream as a list.
      Returns:
      the list of values
    • values

      default V[] values(IntFunction<V[]> generator)
      Returns the values in this stream as an array.
      Parameters:
      generator - generator for creating the array
      Returns:
      the array of values
    • map

      default <R> Partition<V,R> map(Function<V,R> map)
      Applies a function to each value in the stream, returning a partition of the results.
      Type Parameters:
      R - the result type
      Parameters:
      map - the mapping function
      Returns:
      the partition of results
    • sorted

      default DataStream<V> sorted()
      Sorts the stream using the natural ordering of values.
      Returns:
      the sorted stream
      Throws:
      ClassCastException - if the value type is not Comparable
    • sorted

      default DataStream<V> sorted(Comparator<V> comparator)
      Sorts the stream.
      Parameters:
      comparator - the comparator used to sort values
      Returns:
      the sorted stream
    • first

      default V first()
      Returns the first value from this stream.
      Returns:
      the selected value
      Throws:
      NoSuchElementException - if the stream is empty
    • any

      default V any()
      Returns any value from this stream.
      Returns:
      the selected value
      Throws:
      NoSuchElementException - if the stream is empty
    • singleOrDefault

      default V singleOrDefault(V defaultValue)
      Returns the singular value contained in this stream, or if empty, returns the given default value.
      Parameters:
      defaultValue - the default value
      Returns:
      the single value or default value
    • single

      default V single()
      Asserts this stream contains exactly one value, returning said value.
      Returns:
      the value
      Throws:
      NoSuchElementException - if the stream was empty or contained more than one value
    • skip

      default DataStream<V> skip(int n)
      Skips the first n values in the stream.
      Parameters:
      n - the number of values to skip
      Returns:
      the resulting data stream
    • filter

      default DataStream<V> filter(Predicate<V> predicate)
      Filters this stream, keeping only those values evaluating to true.
      Parameters:
      predicate - the predicate function
      Returns:
      the resulting data stream
    • groupBy

      default <K> Groups<K,K,V> groupBy(Function<V,K> group)
      Applies a grouping function to the values in this data stream. Values with the same grouping key are grouped together.
      Type Parameters:
      K - the type of the grouping key
      Parameters:
      group - the grouping function
      Returns:
      the resulting groups
    • keyedOn

      default <K> Partition<K,V> keyedOn(Function<V,K> key)
      Converts this data stream into a Partition by assigning a key to each value.
      Type Parameters:
      K - the type of the key
      Parameters:
      key - the function mapping values to their key
      Returns:
      the partition
    • reduce

      default V reduce(BinaryOperator<V> op)
      Applies a binary reduction operator to the values in this stream. See Stream.reduce(BinaryOperator) for more details.
      Parameters:
      op - the binary reduction operator
      Returns:
      the final result from the reduction operator
      Throws:
      NoSuchElementException - if the stream is empty
    • reduce

      default V reduce(V identity, BinaryOperator<V> op)
      Applies a binary reduction operator to the values in this stream. See Stream.reduce(Object, BinaryOperator) for more details.
      Parameters:
      identity - the initial value supplied to the binary operator
      op - the binary reduction operator
      Returns:
      the final result from the reduction operator
    • distinct

      default DataStream<V> distinct()
      Retains only the unique values in this stream.
      Returns:
      the resulting data stream
    • measure

      default <R> R measure(Function<Stream<V>,R> measure)
      Applies a measurement function to this stream.
      Type Parameters:
      R - the return value
      Parameters:
      measure - the measurement function
      Returns:
      the measured value
    • enumerate

      default void enumerate(BiConsumer<Integer,V> consumer)
      Similar to Iterable.forEach(Consumer) except the index is included.
      Parameters:
      consumer - the method to invoke
    • asTabularData

      default TabularData<V> asTabularData()
      Description copied from interface: Formattable
      Returns the contents of this object as a TabularData instance, which can be used to save, print, or format the data in various ways.
      Specified by:
      asTabularData in interface Formattable<V>
      Returns:
      the TabularData instance
    • of

      static <V> DataStream<V> of()
      Creates an empty data stream.
      Type Parameters:
      V - the type of the stream
      Returns:
      the constructed data stream
    • of

      static <V> DataStream<V> of(Stream<V> stream)
      Creates a data stream with the contents of a Stream.
      Type Parameters:
      V - the type of the stream
      Parameters:
      stream - the source stream
      Returns:
      the constructed data stream
    • of

      static DataStream<Integer> of(IntStream stream)
      Creates a data stream with the contents of a IntStream.
      Parameters:
      stream - the source stream
      Returns:
      the constructed data stream
    • of

      static DataStream<Double> of(DoubleStream stream)
      Creates a data stream with the contents of a DoubleStream.
      Parameters:
      stream - the source stream
      Returns:
      the constructed data stream
    • of

      static <V> DataStream<V> of(Iterable<V> iterable)
      Creates a data stream with the contents of an Iterable.
      Type Parameters:
      V - the type of the iterable
      Parameters:
      iterable - the iterable
      Returns:
      the constructed data stream
    • of

      static <V> DataStream<V> of(V[] array)
      Creates a data stream with the contents of an array.
      Type Parameters:
      V - the type of the array
      Parameters:
      array - the array
      Returns:
      the constructed data stream
    • range

      static DataStream<Integer> range(int count)
      Constructs a data stream containing the integer values [0, ..., count-1].
      Parameters:
      count - the size of the returned stream
      Returns:
      the constructed data stream
    • range

      static DataStream<Integer> range(int startInclusive, int endExclusive)
      Constructs a data stream containing the integer values between the given start (inclusive) and end (exclusive).
      Parameters:
      startInclusive - the starting value
      endExclusive - the ending value (exclusive)
      Returns:
      the constructed data stream
    • repeat

      static <V> DataStream<V> repeat(int count, Supplier<V> supplier)
      Constructs a data stream generated by invoking a Supplier a fixed number of times.
      Type Parameters:
      V - the type returned by the supplier
      Parameters:
      count - the number of invocations of the supplier
      supplier - the supplier
      Returns:
      the constructed data stream
    • enumerate

      static <V> DataStream<V> enumerate(int count, IntFunction<V> function)
      Similar to repeat(int, Supplier) except the index from [0, ..., count-1] is passed as an argument to the function.
      Type Parameters:
      V - the type returned by the function
      Parameters:
      count - the number of invocations of the function
      function - the function taking the index as the first argument
      Returns:
      the constructed data stream