de.unkrig.commons.util.collections
Class CollectionUtil

java.lang.Object
  extended by de.unkrig.commons.util.collections.CollectionUtil

public final class CollectionUtil
extends java.lang.Object

java.util.collection-related utility methods.


Field Summary
static java.util.Iterator AT_END
          An iterator which is at its end.
static java.util.SortedMap EMPTY_SORTED_MAP
          Desperately missing from java.util.Collections.
static java.util.SortedSet EMPTY_SORTED_SET
          Desperately missing from java.util.Collections.
 
Method Summary
static
<K,V> java.util.SortedMap<K,V>
emptySortedMap()
          Desperately missing from java.util.Collections.
static
<T> java.util.SortedSet<T>
emptySortedSet()
          Desperately missing from java.util.Collections.
static
<K,V> java.util.Map<K,V>
map(K[] keys, V[] values)
          Returns an unmodifiable map, mapping the given key-value pairs.
static
<K,V> java.util.Map<K,V>
map(java.lang.Object... keyValuePairs)
          Returns an unmodifiable map, mapping the given key-value pairs.
static
<T> T
removeFirstFrom(java.util.Collection<T> subject)
          Removes and returns the first element of the given collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_SORTED_MAP

public static final java.util.SortedMap EMPTY_SORTED_MAP
Desperately missing from java.util.Collections.


EMPTY_SORTED_SET

public static final java.util.SortedSet EMPTY_SORTED_SET
Desperately missing from java.util.Collections.


AT_END

public static final java.util.Iterator AT_END
An iterator which is at its end.

Method Detail

removeFirstFrom

@Nullable
public static <T> T removeFirstFrom(java.util.Collection<T> subject)
Removes and returns the first element of the given collection. This is also known as the 'shift' operation.

Returns:
null iff the collection is empty

map

public static <K,V> java.util.Map<K,V> map(java.lang.Object... keyValuePairs)
Returns an unmodifiable map, mapping the given key-value pairs. null keys and null values are supported.

Parameters:
keyValuePairs - An alternating sequence of keys and values
Throws:
java.lang.ArrayIndexOutOfBoundsException - The length of keyValuePairs is odd
java.lang.IllegalArgumentException - Two of the keys are equal

map

public static <K,V> java.util.Map<K,V> map(K[] keys,
                                           V[] values)
Returns an unmodifiable map, mapping the given key-value pairs. null keys and null values are supported.

Throws:
java.lang.ArrayIndexOutOfBoundsException - The length of keyValuePairs is odd
java.lang.IllegalArgumentException - Two of the keys are equal

emptySortedMap

public static <K,V> java.util.SortedMap<K,V> emptySortedMap()
Desperately missing from java.util.Collections.


emptySortedSet

public static <T> java.util.SortedSet<T> emptySortedSet()
Desperately missing from java.util.Collections.