Class Groups<G,K,V>

java.lang.Object
org.moeaframework.analysis.stream.ImmutablePartition<G,Partition<K,V>>
org.moeaframework.analysis.stream.Groups<G,K,V>
Type Parameters:
G - the type of the grouping key
K - the original key type
V - the type of each value
All Implemented Interfaces:
Partition<G,Partition<K,V>>, Displayable, Formattable<org.apache.commons.lang3.tuple.Pair<G,Partition<K,V>>>

public class Groups<G,K,V> extends ImmutablePartition<G,Partition<K,V>>
Groups items together using a "grouping key". This grouping key can be the same as, or different from, the key found in the Partition.
  • Constructor Details

    • Groups

      public Groups(List<org.apache.commons.lang3.tuple.Pair<G,Partition<K,V>>> content)
      Constructs a new grouping with the given content.
      Parameters:
      content - the content of this grouping
    • Groups

      public Groups(Stream<org.apache.commons.lang3.tuple.Pair<G,Partition<K,V>>> stream)
      Constructs a new grouping with the given content.
      Parameters:
      stream - a stream of the content
  • Method Details

    • get

      public Partition<K,V> get(G key)
      Returns the group with the given grouping key.
      Parameters:
      key - the grouping key
      Returns:
      the contents of the group
    • sorted

      public Groups<G,K,V> sorted()
      Description copied from interface: Partition
      Sorts the partition using the natural ordering of keys.
      Returns:
      the sorted stream
    • sorted

      public Groups<G,K,V> sorted(Comparator<G> comparator)
      Description copied from interface: Partition
      Sorts the partition based on their keys.
      Parameters:
      comparator - the comparator used to sort keys
      Returns:
      the sorted partition
    • mapEach

      public <R> Groups<G,K,R> mapEach(Function<V,R> map)
      Equivalent to calling Partition.map(Function) on each group, keeping the grouping intact.
      Type Parameters:
      R - the result type
      Parameters:
      map - the map function
      Returns:
      the groups after applying the map function
    • measureEach

      public <R> Partition<G,R> measureEach(Function<Stream<V>,R> measure)
      Equivalent to calling Partition.measure(Function) on each group, keeping the grouping intact.
      Type Parameters:
      R - the result type
      Parameters:
      measure - the measurement function
      Returns:
      the groups after applying the measurement function
    • reduceEach

      public Partition<G,V> reduceEach(BinaryOperator<V> op)
      Equivalent to calling Partition.reduce(BinaryOperator) on each group, keeping the grouping intact.
      Parameters:
      op - the reduction operator
      Returns:
      the groups after applying the reduction operator
    • reduceEach

      public Partition<G,V> reduceEach(V identity, BinaryOperator<V> op)
      Equivalent to calling Partition.reduce(Object, BinaryOperator) on each group, keeping the grouping intact.
      Parameters:
      identity - the initial value supplied to the reduction operator
      op - the reduction operator
      Returns:
      the groups after applying the reduction operator
    • groupEachBy

      public <R> Groups<G,R,Partition<K,V>> groupEachBy(Function<K,R> grouping)
      Equivalent to calling Partition.groupBy(Function) on each group, keeping the grouping intact.
      Type Parameters:
      R - the return type of the grouping function
      Parameters:
      grouping - the grouping function
      Returns:
      the groups after applying the grouping function