Package org.n52.shetland.util
Class CollectionHelper
java.lang.Object
org.n52.shetland.util.CollectionHelper
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> void addToCollectionMap(K key, V valueToAdd, Map<K, Collection<V>> map) Add a value to a map collection, initializing the key's collection if neededstatic StringcollectionToString(Collection<?> collection) static <T> List<T> conjunctCollections(Collection<T> list1, Collection<T> list2) static <T> Set<T> conjunctCollectionsToSet(Collection<T> list1, Collection<T> list2) csvStringToList(String csv) Parse CSV string toListcsvStringToSet(String csv) Parse CSV string toSetstatic <T> Set<T> intersection(Iterable<Set<T>> sets) static <T> Set<T> intersection(Set<T>... elements) static <T> booleanisEmpty(Collection<T> collection) Check if collection is not null and emptystatic <K,V> boolean Check if map is not null and emptystatic <T> booleanisEmptyOrNull(Collection<T> collection) static <T> booleanisNotEmpty(Collection<T> collection) Check if collection is not null and not emptystatic <K,V> boolean isNotEmpty(Map<K, V> map) Check if collection is not null and not emptystatic booleanisNotNullOrEmpty(Object[] array) Check if array is not null and not emptystatic booleanisNullOrEmpty(Object[] array) Check if array is not null or not emptystatic <T> List<T> list(T... elements) static <K,V> Map <K, V> static <T extends Comparable<? super T>>
SortedSet<T> newSortedSet(Collection<? extends T> set) static booleannullEmptyOrContainsOnlyNulls(Collection<? extends Object> collection) Examine a collection and determines if it is null, empty, or contains only null valuesstatic <K,V> Map <V, K> Reverses a map (switches key and value types).static <T> Set<T> set(T... elements) static <K,V extends Comparable<? super V>>
Map<K, V> sortByValue(Map<K, V> map) static String[]svStringToArray(String sv, String separator) Parse separated value string to array with trimmed valuessvStringToList(String sv, String separator) Parse separated value string toListsvStringToSet(String sv, String separator) Parse separated value string toSetstatic <K,V> Map <K, V> synchronizedInitialSizeMapWithLoadFactor1(int capacity) static <E> List<E> Constructs a new synchronizedListbased on aLinkedList.static <E> List<E> synchronizedList(int initialCapacity) static <K,V> Map <K, V> static <K,V> Map <K, V> synchronizedMap(int initialCapacity) static <K,V> Map <K, V> synchronizedMap(int initialCapacity, float loadFactor) static <T> Set<T> Constructs a new synchronizedSetbased on aHashSet.static <T> Set<T> synchronizedSet(int initialCapacity) static <T> Set<T> static <T> Set<T> static <T> Set<T> unionOfListOfLists(Collection<? extends Collection<? extends T>> collectionOfCollection) static <T> Collection<? extends T> unmodifiableCollection(Collection<? extends T> c) static <T> List<? extends T> unmodifiableList(List<? extends T> l) static <K,V> Map <? extends K, ? extends V> unmodifiableMap(Map<? extends K, ? extends V> m) static <T> Set<? extends T> unmodifiableSet(Set<? extends T> s)
-
Method Details
-
map
- Type Parameters:
K- the key typeV- the value type- Parameters:
entries- the final set of entries to add to the newly created unmodifiable map- Returns:
- an unmodifiable map with all given entries
-
set
- Type Parameters:
T- the element type- Parameters:
elements- the elements- Returns:
- an UNMODIFIABLE Set<T>
-
list
- Type Parameters:
T- the element type- Parameters:
elements- the elements- Returns:
- an UNMODIFIABLE List<T>
-
union
-
union
-
intersection
-
intersection
-
unmodifiableSet
- Type Parameters:
T- the element type- Parameters:
s- the set- Returns:
- an UNMODIFIABLE Set<T>
-
unmodifiableMap
- Type Parameters:
K- the key typeV- the value type- Parameters:
m- the map- Returns:
- an UNMODIFIABLE Map<K, V>
-
unmodifiableCollection
- Type Parameters:
T- the element type- Parameters:
c- the collection- Returns:
- an UNMODIFIABLE Collection<T>
-
unmodifiableList
- Type Parameters:
T- the element type- Parameters:
l- the list- Returns:
- an UNMODIFIABLE List<T>
-
conjunctCollections
-
conjunctCollectionsToSet
-
synchronizedInitialSizeMapWithLoadFactor1
-
synchronizedMap
-
synchronizedMap
-
synchronizedMap
-
synchronizedSet
Constructs a new synchronizedSetbased on aHashSet.- Type Parameters:
T- the element type- Returns:
- a synchronized Set
-
synchronizedSet
- Type Parameters:
T- the element type- Parameters:
initialCapacity- the initial capacity of the set- Returns:
- a synchronized Set
-
synchronizedList
Constructs a new synchronizedListbased on aLinkedList.- Type Parameters:
E- the element type- Returns:
- a synchronized List
-
synchronizedList
- Type Parameters:
E- the element type- Parameters:
initialCapacity- the initial capacity of the array list- Returns:
- a synchronized List
-
unionOfListOfLists
public static <T> Set<T> unionOfListOfLists(Collection<? extends Collection<? extends T>> collectionOfCollection) - Type Parameters:
T- the element type- Parameters:
collectionOfCollection- aCollection<Collection<T>>- Returns:
- a Set<T> containing all values of all Collections<T> without any duplicates
-
isNotEmpty
Check if collection is not null and not empty- Type Parameters:
T- the element type- Parameters:
collection- Collection to check- Returns:
- empty or not
-
isNotEmpty
Check if collection is not null and not empty- Type Parameters:
K- the key typeV- the value type- Parameters:
map- Map to check- Returns:
- false, if map is null or empty, else true.
-
isEmptyOrNull
-
isEmpty
Check if collection is not null and empty- Type Parameters:
T- the element type- Parameters:
collection- Collection to check- Returns:
- true, if collection is not null and empty, else false
-
isEmpty
Check if map is not null and empty- Type Parameters:
K- the key typeV- the value type- Parameters:
map- map to check- Returns:
- true, if map is not null and empty, else false
-
reverse
Reverses a map (switches key and value types).- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the map- Returns:
- the reversed map
-
nullEmptyOrContainsOnlyNulls
Examine a collection and determines if it is null, empty, or contains only null values- Parameters:
collection- Collection to examine- Returns:
- whether the collection is null, empty, or contains only nulls
-
isNotNullOrEmpty
Check if array is not null and not empty- Parameters:
array- Array to check- Returns:
true, if array is not null and not empty
-
isNullOrEmpty
Check if array is not null or not empty- Parameters:
array- Array to check- Returns:
true, if array is null or empty
-
collectionToString
-
addToCollectionMap
Add a value to a map collection, initializing the key's collection if needed- Type Parameters:
K- the key typeV- the value type- Parameters:
key- Key whose value collection should be added tovalueToAdd- Vale to add to the key's collectionmap- Map holding collections
-
sortByValue
-
csvStringToList
Parse CSV string toList- Parameters:
csv- CSV string- Returns:
Listwith separated values
-
svStringToList
Parse separated value string toList- Parameters:
sv- Separated value stringseparator- Separator character- Returns:
Listwith separated values
-
csvStringToSet
Parse CSV string toSet- Parameters:
csv- CSV string- Returns:
Setwith separated values
-
svStringToSet
Parse separated value string toSet- Parameters:
sv- Separated value stringseparator- Seperator character- Returns:
Setwith separated values
-
svStringToArray
Parse separated value string to array with trimmed values- Parameters:
sv- Separated value stringseparator- Separator character- Returns:
- Array with separated values
-
newSortedSet
public static <T extends Comparable<? super T>> SortedSet<T> newSortedSet(Collection<? extends T> set)
-