Class TransformCollector<T,U>

java.lang.Object
com.github.martincooper.datatable.TransformCollector<T,U>
Type Parameters:
T - The collection type.
U - The return type.
All Implemented Interfaces:
Collector<T,ArrayList<T>,U>

public class TransformCollector<T,U> extends Object implements Collector<T,ArrayList<T>,U>
TransformCollector. Custom Collector. Used to pass the contents of a collection to a single method, returning a single value.
  • Constructor Details

    • TransformCollector

      public TransformCollector(Function<io.vavr.collection.Stream<T>,U> function)
      TransformCollector constructor.
      Parameters:
      function - The function to run on the collected items.
  • Method Details

    • transform

      public static <T, U> TransformCollector<T,U> transform(Function<io.vavr.collection.Stream<T>,U> function)
      as method. Static helper to return a new instance of the Transform Collector class.
      Type Parameters:
      T - The collection type.
      U - The return type.
      Parameters:
      function - The function to run on the full collection.
      Returns:
      Returns a new instance of the collector.
    • supplier

      public Supplier<ArrayList<T>> supplier()
      The supplier. Returns a new ArrayList which builds up the final item list.
      Specified by:
      supplier in interface Collector<T,ArrayList<T>,U>
      Returns:
      Returns the ArrayList.
    • accumulator

      public BiConsumer<ArrayList<T>,T> accumulator()
      The accumulator. In this case, just append the item to the list.
      Specified by:
      accumulator in interface Collector<T,ArrayList<T>,U>
      Returns:
      Return the ArrayList
    • combiner

      public BinaryOperator<ArrayList<T>> combiner()
      Specified by:
      combiner in interface Collector<T,ArrayList<T>,U>
    • finisher

      public Function<ArrayList<T>,U> finisher()
      The finisher has all the items in the list. Now we just need to run the requested transform function on it to get the final results.
      Specified by:
      finisher in interface Collector<T,ArrayList<T>,U>
      Returns:
      Returns the result after passed through the transform function.
    • characteristics

      public Set<Collector.Characteristics> characteristics()
      Default set of characteristics.
      Specified by:
      characteristics in interface Collector<T,ArrayList<T>,U>
      Returns:
      Returns the default set of characteristics.