Package org.omnifaces.utils
Class Collections
- java.lang.Object
-
- org.omnifaces.utils.Collections
-
public final class Collections extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
contains(Collection<?> collection, Object object)
Returnstrue
if the collection is not null and contains the specified element.static <E> List<E>
iterableToList(Iterable<E> iterable)
Converts an iterable into a list.static <T> Map<T,T>
reverse(Map<T,T> source)
Returns a new map that contains the reverse of the given map.static <E> Set<E>
unmodifiableSet(Object... values)
Creates an unmodifiable set based on the given values.
-
-
-
Method Detail
-
unmodifiableSet
public static <E> Set<E> unmodifiableSet(Object... values)
Creates an unmodifiable set based on the given values. If one of the values is an instance of an array or a collection, then each of its values will also be merged into the set. Nested arrays or collections will result in aClassCastException
.- Type Parameters:
E
- The expected set element type.- Parameters:
values
- The values to create an unmodifiable set for.- Returns:
- An unmodifiable set based on the given values.
- Throws:
ClassCastException
- When one of the values or one of the arrays or collections is of wrong type.
-
iterableToList
public static <E> List<E> iterableToList(Iterable<E> iterable)
Converts an iterable into a list.This method makes NO guarantee to whether changes to the source iterable are reflected in the returned list or not. For instance if the given iterable already is a list, it's returned directly.
- Type Parameters:
E
- The generic iterable element type.- Parameters:
iterable
- The iterable to be converted.- Returns:
- The list representation of the given iterable, possibly the same instance as that iterable.
-
reverse
public static <T> Map<T,T> reverse(Map<T,T> source)
Returns a new map that contains the reverse of the given map.The reverse of a map means that every value X becomes a key X' with as corresponding value Y' the key Y that was originally associated with the value X.
- Type Parameters:
T
- The generic map key/value type.- Parameters:
source
- the map that is to be reversed- Returns:
- the reverse of the given map
-
contains
public static boolean contains(Collection<?> collection, Object object)
Returnstrue
if the collection is not null and contains the specified element.- Parameters:
collection
- the collection to test for the specified elementobject
- element to test for in the specified collection- Returns:
true
if the collection is not null and contains the specified element
-
-