Class Collectors

java.lang.Object
com.persequor.helpers.Collectors

public class Collectors extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <X> X
    throwOnMerge(X a, X b)
    Helper method to be used as merge function, when duplicate keys are not expected.
    static <T, K> Collector<T,?,LinkedHashMap<K,T>>
    toOrderedMap(Function<T,K> keyMapper)
    Returns a Collector that accumulates elements into a LinkedHashMap whose keys are the result of applying the provided keyMapper function to the input elements, and whose values are the input elements.
    static <T, K, U> Collector<T,?,LinkedHashMap<K,U>>
    toOrderedMap(Function<T,K> keyMapper, Function<T,U> valueMapper)
    Returns a Collector that accumulates elements into a LinkedHashMap whose keys and values are the result of applying the provided mapping functions to the input elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Collectors

      public Collectors()
  • Method Details

    • toOrderedMap

      public static <T, K> Collector<T,?,LinkedHashMap<K,T>> toOrderedMap(Function<T,K> keyMapper)
      Returns a Collector that accumulates elements into a LinkedHashMap whose keys are the result of applying the provided keyMapper function to the input elements, and whose values are the input elements.
      Type Parameters:
      T - the type of the input elements and map values
      K - the type of the map keys
      Parameters:
      keyMapper - A function that returns a key for an element
      Returns:
      a Collector which collects elements into a LinkedHashMap, in encounter order
    • toOrderedMap

      public static <T, K, U> Collector<T,?,LinkedHashMap<K,U>> toOrderedMap(Function<T,K> keyMapper, Function<T,U> valueMapper)
      Returns a Collector that accumulates elements into a LinkedHashMap whose keys and values are the result of applying the provided mapping functions to the input elements.
      Type Parameters:
      T - the type of the input elements
      K - the type of the map keys
      U - the type of the map values
      Parameters:
      keyMapper - a mapping function to produce keys
      valueMapper - a mapping function to produce values
      Returns:
      a Collector which collects elements into a LinkedHashMap, in encounter order
    • throwOnMerge

      public static <X> X throwOnMerge(X a, X b)
      Helper method to be used as merge function, when duplicate keys are not expected.
      Parameters:
      a - ignored
      b - ignored
      Throws:
      IllegalStateException - always