Class CustomCollectors

java.lang.Object
com.ggalmazor.ltdownsampling.tools.CustomCollectors

public class CustomCollectors extends Object
Utility class to wire in the sliding window collector defined by SlidingCollector.
  • Constructor Details

    • CustomCollectors

      public CustomCollectors()
  • Method Details

    • sliding

      public static <T> Collector<T, ?, List<List<T>>> sliding(int size)
      Collects a Stream into lists of consecutive elements in groups of the provided size without overlaps or gaps.
      Type Parameters:
      T - the type of elements in the Stream being collected
      Parameters:
      size - the size of the output lists
      Returns:
      a list of lists
    • sliding

      public static <T> Collector<T, ?, List<List<T>>> sliding(int size, int step)
      Collects a Stream into lists of consecutive elements in groups of the provided size, advancing step elements between each group.

      Depending on the value of step, the resulting lists can have overlaps or gaps:

      • sliding(2,1) produces overlapping lists (every input element is present in two output elements except for the first and last).
      • sliding(2,3) produces a list with gaps (every third input element is skipped).
      Type Parameters:
      T - the type of elements in the Stream being collected
      Parameters:
      size - the number of elements in each list element of the output list
      step - the number of input elements to advance after each output list element
      Returns:
      a list of lists