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 the provided step elements between each group.

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

      • sliding(2,1) will produce overlapping lists (every input element is present in two output elements except for the first and the last input elements)
      • sliding(2,3) will produce 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 on each list element in the output list
      step - the number of input elements to skip after each list element in the output list
      Returns:
      a list of lists