Package org.jboss.weld.util.collections
Class WeldCollections
- java.lang.Object
-
- org.jboss.weld.util.collections.WeldCollections
-
public class WeldCollections extends Object
Collection utilities.- Author:
- Jozef Hartinger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> boolean
addIfNotNull(Collection<T> collection, T element)
static <T> List<T>
immutableListView(List<T> list)
Returns an immutable view of a given list.static <K,V>
Map<K,V>immutableMapView(Map<K,V> map)
Returns an immutable view of a given map.static <T> Set<T>
immutableSetView(Set<T> set)
Returns an immutable view of a given set.static <K,V>
VputIfAbsent(Map<K,V> map, K key, V value)
Utility method for working with maps.static <T> List<T>
sort(List<T> list, Comparator<? super T> comparator)
Fluent version ofCollections.sort(List, Comparator)
static String
toMultiRowString(Collection<?> collection)
Returns the supplied collection as a multi-row string with every toString() of every element of the collection in its own row.
-
-
-
Method Detail
-
immutableSetView
public static <T> Set<T> immutableSetView(Set<T> set)
Returns an immutable view of a given set. If the given set is empty, a shared instance is returned. If the given set is an instance ofArraySet
, it is trimmed.
-
immutableListView
public static <T> List<T> immutableListView(List<T> list)
Returns an immutable view of a given list. If the given list is empty, a shared instance is returned. If the given list is an instance ofArrayList
, it is trimmed.
-
immutableMapView
public static <K,V> Map<K,V> immutableMapView(Map<K,V> map)
Returns an immutable view of a given map.
-
sort
public static <T> List<T> sort(List<T> list, Comparator<? super T> comparator)
Fluent version ofCollections.sort(List, Comparator)
-
toMultiRowString
public static String toMultiRowString(Collection<?> collection)
Returns the supplied collection as a multi-row string with every toString() of every element of the collection in its own row. Example: toMultiRowString(Arrays.asList("aaa", "bbb", "ccc")) will return:- aaa, - bbb, - ccc
-
addIfNotNull
public static <T> boolean addIfNotNull(Collection<T> collection, T element)
-
putIfAbsent
public static <K,V> V putIfAbsent(Map<K,V> map, K key, V value)
Utility method for working with maps. UnlikeMap.putIfAbsent(Object, Object)
this method always returns the value that ends up store in the map which is either the old value (if any was present) or the new value (if it was stored in the map).- Parameters:
map
- the mapkey
- the keyvalue
- the value- Returns:
- the value that ends up store in the map which is either the old value (if any was present) or the new value (if it was stored in the map)
-
-