org.databene.commons
Class CollectionUtil

java.lang.Object
  extended by org.databene.commons.CollectionUtil

public final class CollectionUtil
extends java.lang.Object

Provides Collection-related utility methods.

Created: 18.12.2006 06:46:24


Constructor Summary
CollectionUtil()
           
 
Method Summary
static
<T,U extends T,C extends java.util.Collection<? super T>>
C
add(C target, U... values)
          Adds the content of an array to a collection
static
<K,V> java.util.Map<K,V>
buildMap(K key, V value)
           
static java.util.Map buildMap(java.lang.Object... keyValuePairs)
           
static java.util.Map buildOrderedMap(java.lang.Object... keyValuePairs)
           
static
<V> boolean
containsCaseInsensitive(java.lang.String key, java.util.Map<java.lang.String,V> map)
           
static
<T> java.util.List<T>
copy(java.util.List<? extends T> src, int offset, int length)
           
static
<T> java.util.List<T>
emptyList()
           
static
<T> boolean
equalsIgnoreOrder(java.util.List<T> a1, java.util.List<T> a2)
          Compares two lists for identical content, accepting different order.
static
<T> T[]
extractArray(java.util.List<? extends T> source, java.lang.Class<T> componentType, int fromIndex, int toIndex)
           
static
<V> V
getCaseInsensitive(java.lang.String key, java.util.Map<java.lang.String,V> map)
           
static boolean isEmpty(java.util.Collection<?> collection)
           
static
<T> T
lastElement(java.util.List<T> list)
           
static
<T extends java.util.Collection<U>,U>
T
newInstance(java.lang.Class<T> collectionType)
          Creates a new instance of a Collection.
static
<T> boolean
ofEqualContent(java.util.List<T> list, T[] array)
           
static
<T,U> T[]
toArray(java.util.Collection<? extends T> source)
           
static
<T> T[]
toArray(java.util.Collection<? extends T> source, java.lang.Class<T> componentType)
           
static char[] toArray(java.util.Collection<java.lang.Character> source)
           
static
<T> java.util.List<T>
toList(T... array)
          Converts an array into a list.
static
<T,S> java.util.List<T>
toListOfType(S... array)
           
static
<T> java.util.Set<T>
toSet(T... elements)
          Creates a HashSet filled with the specified elements
static
<T,U extends T>
java.util.SortedSet<T>
toSortedSet(U... elements)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtil

public CollectionUtil()
Method Detail

isEmpty

public static boolean isEmpty(java.util.Collection<?> collection)

toList

public static <T> java.util.List<T> toList(T... array)
Converts an array into a list.

Parameters:
array - the array to convert into a list.
Returns:
a list containing all elements of the given array.

toListOfType

public static <T,S> java.util.List<T> toListOfType(S... array)

toSet

public static <T> java.util.Set<T> toSet(T... elements)
Creates a HashSet filled with the specified elements

Parameters:
elements - the content of the Set
Returns:
a HashSet with the elements

toSortedSet

public static <T,U extends T> java.util.SortedSet<T> toSortedSet(U... elements)

add

public static <T,U extends T,C extends java.util.Collection<? super T>> C add(C target,
                                                                              U... values)
Adds the content of an array to a collection

Parameters:
target - the collection to be extended
values - the values to add

copy

public static <T> java.util.List<T> copy(java.util.List<? extends T> src,
                                         int offset,
                                         int length)

toArray

public static <T,U> T[] toArray(java.util.Collection<? extends T> source)

toArray

public static <T> T[] toArray(java.util.Collection<? extends T> source,
                              java.lang.Class<T> componentType)

extractArray

public static <T> T[] extractArray(java.util.List<? extends T> source,
                                   java.lang.Class<T> componentType,
                                   int fromIndex,
                                   int toIndex)

toArray

public static char[] toArray(java.util.Collection<java.lang.Character> source)

buildMap

public static <K,V> java.util.Map<K,V> buildMap(K key,
                                                V value)

buildMap

public static java.util.Map buildMap(java.lang.Object... keyValuePairs)

buildOrderedMap

public static java.util.Map buildOrderedMap(java.lang.Object... keyValuePairs)

newInstance

public static <T extends java.util.Collection<U>,U> T newInstance(java.lang.Class<T> collectionType)
Creates a new instance of a Collection. Abstract interfaces are mapped to a default implementation class.


equalsIgnoreOrder

public static <T> boolean equalsIgnoreOrder(java.util.List<T> a1,
                                            java.util.List<T> a2)
Compares two lists for identical content, accepting different order.


getCaseInsensitive

public static <V> V getCaseInsensitive(java.lang.String key,
                                       java.util.Map<java.lang.String,V> map)

containsCaseInsensitive

public static <V> boolean containsCaseInsensitive(java.lang.String key,
                                                  java.util.Map<java.lang.String,V> map)

ofEqualContent

public static <T> boolean ofEqualContent(java.util.List<T> list,
                                         T[] array)

lastElement

public static <T> T lastElement(java.util.List<T> list)

emptyList

public static <T> java.util.List<T> emptyList()


Copyright © 2010. All Rights Reserved.