Class Grouping


  • public class Grouping
    extends Object
    For grouping Binnable and ungrouping BinnableGroup objects.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • Grouping

        public Grouping()
    • Method Detail

      • group

        protected static <T> com.github.fracpete.javautils.struct.Struct2<List<String>,​Map<String,​BinnableGroup<T>>> group​(List<Binnable<T>> data,
                                                                                                                                       Grouping.GroupExtractor<T> extractor)
        Combines the binnable items into groups based on the groups extracted.
        Type Parameters:
        T - the payload type
        Parameters:
        data - the data to group
        extractor - for extracting the group
        Returns:
        the order of the groups and group map
      • groupAsMap

        public static <T> Map<String,​BinnableGroup<T>> groupAsMap​(List<Binnable<T>> data,
                                                                        Grouping.GroupExtractor<T> extractor)
        Combines the binnable items into groups based on the groups extracted.
        Type Parameters:
        T - the payload type
        Parameters:
        data - the data to group
        extractor - for extracting the group
        Returns:
        the groups
      • groupAsList

        public static <T> List<BinnableGroup<T>> groupAsList​(List<Binnable<T>> data,
                                                             Grouping.GroupExtractor<T> extractor)
        Combines the binnable items into groups based on the groups extracted. The generated list consists of the sorted groups.
        Type Parameters:
        T - the payload type
        Parameters:
        data - the data to group
        extractor - for extracting the group
        Returns:
        the groups
      • ungroupMap

        public static <T> List<Binnable<T>> ungroupMap​(Map<String,​BinnableGroup<T>> data,
                                                       boolean sortByGroup)
        Unravels the grouped binnable items into a single list again.
        Type Parameters:
        T - the payload type
        Parameters:
        data - the data to ungroup
        sortByGroup - whether to sort by group
        Returns:
        the generated list
      • ungroup

        public static <T> List<Binnable<T>> ungroup​(BinnableGroup<T> data)
        Unravels the grouped binnable items into a single list again.
        Type Parameters:
        T - the payload type
        Parameters:
        data - the data to ungroup
        Returns:
        the generated list