Package org.cyclops.cyclopscore.helper
Class CollectionHelpers
java.lang.Object
org.cyclops.cyclopscore.helper.CollectionHelpers
Helper methods for collections.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> void addToMapList
(Map<K, List<V>> map, K key, V value) Add the given key value pair in a map structure where multiple values for a key can exist.static <K,
V> void addToMapSet
(Map<K, Set<V>> map, K key, V value) Add the given key value pair in a map structure where multiple values for a key can exist.static <T extends Comparable<T>>
intcompareCollection
(Collection<? super T> a, Collection<? super T> b) Compare two collections with comparable elements.static <T> int
compareCollection
(Collection<? super T> a, Collection<? super T> b, Comparator<T> comparator) Compare two collections with a custom comparator.
-
Constructor Details
-
CollectionHelpers
public CollectionHelpers()
-
-
Method Details
-
addToMapList
Add the given key value pair in a map structure where multiple values for a key can exist. This will take care of making a new list into the map when one did not exist before.- Type Parameters:
K
- The key type.V
- The value type.- Parameters:
map
- The map.key
- The key.value
- The value.
-
addToMapSet
Add the given key value pair in a map structure where multiple values for a key can exist. This will take care of making a new set into the map when one did not exist before.- Type Parameters:
K
- The key type.V
- The value type.- Parameters:
map
- The map.key
- The key.value
- The value.
-
compareCollection
public static <T extends Comparable<T>> int compareCollection(Collection<? super T> a, Collection<? super T> b) Compare two collections with comparable elements.- Type Parameters:
T
- The type of the elements.- Parameters:
a
- A first collection.b
- A second collection.- Returns:
- The comparator value.
-
compareCollection
public static <T> int compareCollection(Collection<? super T> a, Collection<? super T> b, Comparator<T> comparator) Compare two collections with a custom comparator.- Type Parameters:
T
- The type of the elements.- Parameters:
a
- A first collection.b
- A second collection.comparator
- The element comparator.- Returns:
- The comparator value.
-