Package org.n52.shetland.util
Class CollectionHelper
- java.lang.Object
-
- org.n52.shetland.util.CollectionHelper
-
public final class CollectionHelper extends Object
- Since:
- 1.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
voidaddToCollectionMap(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)static List<String>csvStringToList(String csv)Parse CSV string toListstatic Set<String>csvStringToSet(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>
booleanisEmpty(Map<K,V> map)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>
booleanisNotEmpty(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>map(Map.Entry<K,V>... entries)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>reverse(Map<K,V> map)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 valuesstatic List<String>svStringToList(String sv, String separator)Parse separated value string toListstatic Set<String>svStringToSet(String sv, String separator)Parse separated value string toSetstatic <K,V>
Map<K,V>synchronizedInitialSizeMapWithLoadFactor1(int capacity)static <E> List<E>synchronizedList()Constructs a new synchronizedListbased on aLinkedList.static <E> List<E>synchronizedList(int initialCapacity)static <K,V>
Map<K,V>synchronizedMap()static <K,V>
Map<K,V>synchronizedMap(int initialCapacity)static <K,V>
Map<K,V>synchronizedMap(int initialCapacity, float loadFactor)static <T> Set<T>synchronizedSet()Constructs a new synchronizedSetbased on aHashSet.static <T> Set<T>synchronizedSet(int initialCapacity)static <T> Set<T>union(Iterable<Set<T>> elements)static <T> Set<T>union(Set<T>... elements)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 Detail
-
map
@SafeVarargs public static <K,V> Map<K,V> map(Map.Entry<K,V>... entries)
- 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
@SafeVarargs public static <T> Set<T> set(T... elements)
- Type Parameters:
T- the element type- Parameters:
elements- the elements- Returns:
- an UNMODIFIABLE Set<T>
-
list
@SafeVarargs public static <T> List<T> list(T... elements)
- Type Parameters:
T- the element type- Parameters:
elements- the elements- Returns:
- an UNMODIFIABLE List<T>
-
union
@SafeVarargs public static <T> Set<T> union(Set<T>... elements)
-
intersection
@SafeVarargs public static <T> Set<T> intersection(Set<T>... elements)
-
unmodifiableSet
public static <T> Set<? extends T> unmodifiableSet(Set<? extends T> s)
- Type Parameters:
T- the element type- Parameters:
s- the set- Returns:
- an UNMODIFIABLE Set<T>
-
unmodifiableMap
public static <K,V> Map<? extends K,? extends V> unmodifiableMap(Map<? extends K,? extends V> m)
- Type Parameters:
K- the key typeV- the value type- Parameters:
m- the map- Returns:
- an UNMODIFIABLE Map<K, V>
-
unmodifiableCollection
public static <T> Collection<? extends T> unmodifiableCollection(Collection<? extends T> c)
- Type Parameters:
T- the element type- Parameters:
c- the collection- Returns:
- an UNMODIFIABLE Collection<T>
-
unmodifiableList
public static <T> List<? extends T> unmodifiableList(List<? extends T> l)
- Type Parameters:
T- the element type- Parameters:
l- the list- Returns:
- an UNMODIFIABLE List<T>
-
conjunctCollections
public static <T> List<T> conjunctCollections(Collection<T> list1, Collection<T> list2)
-
conjunctCollectionsToSet
public static <T> Set<T> conjunctCollectionsToSet(Collection<T> list1, Collection<T> list2)
-
synchronizedInitialSizeMapWithLoadFactor1
public static <K,V> Map<K,V> synchronizedInitialSizeMapWithLoadFactor1(int capacity)
-
synchronizedMap
public static <K,V> Map<K,V> synchronizedMap()
-
synchronizedMap
public static <K,V> Map<K,V> synchronizedMap(int initialCapacity)
-
synchronizedMap
public static <K,V> Map<K,V> synchronizedMap(int initialCapacity, float loadFactor)
-
synchronizedSet
public static <T> Set<T> synchronizedSet()
Constructs a new synchronizedSetbased on aHashSet.- Type Parameters:
T- the element type- Returns:
- a synchronized Set
-
synchronizedSet
public static <T> Set<T> synchronizedSet(int initialCapacity)
- Type Parameters:
T- the element type- Parameters:
initialCapacity- the initial capacity of the set- Returns:
- a synchronized Set
-
synchronizedList
public static <E> List<E> synchronizedList()
Constructs a new synchronizedListbased on aLinkedList.- Type Parameters:
E- the element type- Returns:
- a synchronized List
-
synchronizedList
public static <E> List<E> synchronizedList(int initialCapacity)
- 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
public static <T> boolean isNotEmpty(Collection<T> collection)
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
public static <K,V> boolean isNotEmpty(Map<K,V> map)
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
public static <T> boolean isEmptyOrNull(Collection<T> collection)
-
isEmpty
public static <T> boolean isEmpty(Collection<T> collection)
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
public static <K,V> boolean isEmpty(Map<K,V> map)
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
public static <K,V> Map<V,K> reverse(Map<K,V> map)
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
public static boolean nullEmptyOrContainsOnlyNulls(Collection<? extends Object> collection)
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
public static boolean isNotNullOrEmpty(Object[] array)
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
public static boolean isNullOrEmpty(Object[] array)
Check if array is not null or not empty- Parameters:
array- Array to check- Returns:
true, if array is null or empty
-
collectionToString
public static String collectionToString(Collection<?> collection)
-
addToCollectionMap
public static <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 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
public static <K,V extends Comparable<? super V>> Map<K,V> sortByValue(Map<K,V> map)
-
csvStringToList
public static List<String> csvStringToList(String csv)
Parse CSV string toList- Parameters:
csv- CSV string- Returns:
Listwith separated values
-
svStringToList
public static List<String> svStringToList(String sv, String separator)
Parse separated value string toList- Parameters:
sv- Separated value stringseparator- Separator character- Returns:
Listwith separated values
-
csvStringToSet
public static Set<String> csvStringToSet(String csv)
Parse CSV string toSet- Parameters:
csv- CSV string- Returns:
Setwith separated values
-
svStringToSet
public static Set<String> svStringToSet(String sv, String separator)
Parse separated value string toSet- Parameters:
sv- Separated value stringseparator- Seperator character- Returns:
Setwith separated values
-
svStringToArray
public static String[] svStringToArray(String sv, String separator)
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)
-
-