Class Grouping
- java.lang.Object
-
- org.openmuc.jeebus.spine.utils.algorithms.Grouping
-
public class Grouping extends java.lang.ObjectUtility class for algorithms that group collection elements together.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.List<java.util.List<java.lang.Integer>>groupIndices(java.util.List<T> elements, java.util.function.BiPredicate<? super T,? super T> equals)Group list elements according to the given equality predicate, storing the groups as lists of indices into the original list.static <K,V>
java.util.Map<K,java.util.List<V>>groupZipMap(java.util.List<K> keys, java.util.List<V> vals, java.util.function.BiPredicate<? super K,? super K> equals)Construct a multimap from a list of keys and a list of values.static <K,V>
java.util.Map<K,java.util.List<V>>groupZipMapFromIndices(java.util.List<java.util.List<java.lang.Integer>> groupIndices, java.util.List<K> keys, java.util.List<V> vals)Construct a map from a grouped list of keys and a list of values.
-
-
-
Method Detail
-
groupIndices
public static <T> java.util.List<java.util.List<java.lang.Integer>> groupIndices(java.util.List<T> elements, java.util.function.BiPredicate<? super T,? super T> equals)Group list elements according to the given equality predicate, storing the groups as lists of indices into the original list.- Type Parameters:
T- type of list elements- Parameters:
elements- The list to work on.equals- The equality predicate to use. For best results, this should be an equivalence relation.- Returns:
- the list of groups
-
groupZipMapFromIndices
public static <K,V> java.util.Map<K,java.util.List<V>> groupZipMapFromIndices(java.util.List<java.util.List<java.lang.Integer>> groupIndices, java.util.List<K> keys, java.util.List<V> vals)Construct a map from a grouped list of keys and a list of values. The key for each map entry is the first element of a group, and the value is a list of all values at the indices of the group.- Type Parameters:
K- type of keysV- type of values- Parameters:
groupIndices- Indices of group inkeyskeys- List of keysvals- List of values- Returns:
- Multimap from keys to values
-
groupZipMap
public static <K,V> java.util.Map<K,java.util.List<V>> groupZipMap(java.util.List<K> keys, java.util.List<V> vals, java.util.function.BiPredicate<? super K,? super K> equals)Construct a multimap from a list of keys and a list of values. The lists should be of equal length. Each key is mapped to the value at the same index, and keys are collated according to the given predicate.- Type Parameters:
K- type of keysV- type of values- Parameters:
keys- List of keysvals- List of valuesequals- The equality predicate to use. For best results, this should be an equivalence relation.- Returns:
- Multimap from keys to values
-
-