|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.tum.cs.commons.collections.CollectionUtils
public class CollectionUtils
This class offers utility methods for collections. In can be seen as an
extension to Collections
.
Constructor Summary | |
---|---|
CollectionUtils()
|
Method Summary | ||
---|---|---|
static
|
asHashSet(T... elements)
Create an hashed set from an array. |
|
static
|
asSortedUnmodifiableList(java.util.Collection<T> collection)
Returns a sorted unmodifiable list for a collection. |
|
static
|
asSortedUnmodifiableList(java.util.Collection<T> collection,
java.util.Comparator<? super T> comparator)
Returns a sorted unmodifiable list for a collection. |
|
static
|
asUnmodifiable(java.util.Collection<T> c)
Returns a new unmodifiable collection wrapping the given collection. |
|
static
|
asUnmodifiable(HashedListMap<S,T> m)
Returns a new unmodifiable hashed list map wrapping the given map. |
|
static
|
asUnmodifiable(java.util.List<T> l)
Returns a new unmodifiable list wrapping the given list. |
|
static
|
asUnmodifiable(java.util.Map<S,T> m)
Returns a new unmodifiable map wrapping the given map. |
|
static
|
asUnmodifiable(java.util.Set<T> s)
Returns a new unmodifiable set wrapping the given set. |
|
static
|
asUnmodifiable(java.util.SortedMap<S,T> m)
Returns a new unmodifiable sorted map wrapping the given sorted map. |
|
static
|
asUnmodifiable(java.util.SortedSet<T> s)
Returns a new unmodifiable sorted set wrapping the given sorted set. |
|
static
|
computeUnorderedPairs(java.util.Collection<T> collection)
Compute list of unordered pairs for all elements contained in a collection. |
|
static
|
copyArray(T[] original)
Copy an array. |
|
static
|
emptyList()
The way this method is defined allows to assign it to all parameterized types, i.e. bot of the following statements are accepted by the compiler without warnings: UnmodifiableList<String> emptyList = CollectionUtils.emptyList(); UnmodifiableList<Date> emptyList = CollectionUtils.emptyList(); |
|
static
|
emptyMap()
Returns an empty map. |
|
static
|
emptySet()
Returns an empty set. |
|
static
|
getAny(java.lang.Iterable<T> iterable)
Returns one object from an Iterable or null if the
iterable is empty. |
|
static
|
getLast(java.util.List<T> list)
Returns the last element in list or null , if list is empty. |
|
static
|
reverse(java.util.Collection<T> list)
Returns a list that contains the elements of the specified list in reversed order. |
|
static
|
sort(java.util.Collection<T> collection)
Sorts the specified list into ascending order, according to the natural ordering of its elements. |
|
static
|
sort(java.util.Collection<T> collection,
java.util.Comparator<? super T> comparator)
Sorts the specified list according to the order induced by the specified comparator. |
|
static
|
toArray(java.util.Collection<? extends T> collection,
java.lang.Class<T> type)
Convert collection to array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CollectionUtils()
Method Detail |
---|
public static <T> java.util.HashSet<T> asHashSet(T... elements)
T
- typeelements
- elements in the set.
Arrays.asList(Object[])
public static <T> UnmodifiableCollection<T> asUnmodifiable(java.util.Collection<T> c)
public static <S,T> UnmodifiableHashedListMap<S,T> asUnmodifiable(HashedListMap<S,T> m)
public static <T> UnmodifiableList<T> asUnmodifiable(java.util.List<T> l)
public static <S,T> UnmodifiableMap<S,T> asUnmodifiable(java.util.Map<S,T> m)
public static <T> UnmodifiableSet<T> asUnmodifiable(java.util.Set<T> s)
public static <S,T> UnmodifiableSortedMap<S,T> asUnmodifiable(java.util.SortedMap<S,T> m)
public static <T> UnmodifiableSortedSet<T> asUnmodifiable(java.util.SortedSet<T> s)
public static final <T> UnmodifiableList<T> emptyList()
UnmodifiableList<String> emptyList = CollectionUtils.emptyList(); UnmodifiableList<Date> emptyList = CollectionUtils.emptyList();
T
-
public static final <S,T> UnmodifiableMap<S,T> emptyMap()
emptyList()
for further details.
public static final <T> UnmodifiableSet<T> emptySet()
emptyList()
for further details.
public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sort(java.util.Collection<T> collection)
All elements in the list must implement the Comparable interface.
Furthermore, all elements in the list must be mutually comparable (that
is, e1.compareTo(e2) must not throw a ClassCastException
for
any elements e1 and e2 in the list).
This method does not modify the original collection.
public static <T> java.util.List<T> reverse(java.util.Collection<T> list)
This method does not modify the original collection.
public static <T> java.util.List<T> sort(java.util.Collection<T> collection, java.util.Comparator<? super T> comparator)
All elements in the list must implement the Comparable interface.
Furthermore, all elements in the list must be mutually comparable (that
is, e1.compareTo(e2) must not throw a ClassCastException
for
any elements e1 and e2 in the list).
This method does not modify the original collection.
public static <T extends java.lang.Comparable<T>> UnmodifiableList<T> asSortedUnmodifiableList(java.util.Collection<T> collection)
public static <T extends java.lang.Comparable<T>> UnmodifiableList<T> asSortedUnmodifiableList(java.util.Collection<T> collection, java.util.Comparator<? super T> comparator)
comparator
- Comparator used for sortingpublic static <T> T getAny(java.lang.Iterable<T> iterable)
Iterable
or null
if the
iterable is empty.
public static <T> T[] toArray(java.util.Collection<? extends T> collection, java.lang.Class<T> type)
Collection.toArray(Object[])
.
public static <T> T[] copyArray(T[] original)
Arrays.copyOf(Object[], int)
that does not require to specify the
length.
public static <T> java.util.List<ImmutablePair<T,T>> computeUnorderedPairs(java.util.Collection<T> collection)
public static <T> T getLast(java.util.List<T> list)
null
, if list is empty.
|
TUM CCSM Commons | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |