public final class Collections2
extends java.lang.Object
Collection
s and Maps
.Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.Object,java.lang.Object> |
putToMap(java.lang.Object... keyAndValuePairs) |
static <T> java.util.List<T> |
requireNonNullList(java.util.List<T> list)
Verifies that
list and all of its elements are not null . |
static <T> java.util.List<T> |
requireNonNullList(T object,
T[] objects)
Verifies that the
List created by the mandatory object and the optional non-null array objects contains no null elements. |
static <K,V> V |
requireNonNullValue(java.lang.String key,
java.util.Map<K,V> map)
Verifies that the key
key refers to a value in map , that is not null . |
static <T> java.util.List<T> |
reverseCopyOf(java.util.List<T> list) |
static <K,V extends java.lang.Comparable<? super V>> |
sortByValue(java.util.Map<K,V> map) |
public static java.util.Map<java.lang.Object,java.lang.Object> putToMap(java.lang.Object... keyAndValuePairs)
public static <K,V> V requireNonNullValue(java.lang.String key, java.util.Map<K,V> map)
key
refers to a value in map
, that is not null
.
Returns the value held by map
given the key key
.
If either key
, map
or the value returned by map
are null
, a NullPointerException
will be thrown.
Some, or most Map
implementations allow null
as a value, but this method treats it as it's absent.
K
- the generic type of the key of the Map
V
- the generic type of the value of the Map
key
- the key of the value to returnmap
- the Map
in which the key may refer to an arbitrary valuemap
given the key key
java.lang.NullPointerException
- thrown if, and only if, either key
, map
or the value returned by map
are null
public static <K,V extends java.lang.Comparable<? super V>> java.util.Map<K,V> sortByValue(java.util.Map<K,V> map)
public static <T> java.util.List<T> requireNonNullList(java.util.List<T> list)
list
and all of its elements are not null
.
Returns the List
itself.
If list
or any of its elements are null
, a NullPointerException
will be thrown.
T
- the generic type of the List
list
- the List
to check for null
referencesList
itselfjava.lang.NullPointerException
- thrown if, and only if, list
or any of its elements are null
public static <T> java.util.List<T> requireNonNullList(T object, T[] objects)
List
created by the mandatory object
and the optional non-null
array objects
contains no null
elements.
Returns a new List
.
If object
, objects
or any of its elements are null
, a NullPointerException
will be thrown.
T
- the generic type of the List
object
- the mandatory Object
to addobjects
- the optional non-null
array to add after object
List
java.lang.NullPointerException
- thrown if, and only if, object
, objects
or any of its elements are null
public static <T> java.util.List<T> reverseCopyOf(java.util.List<T> list)