|
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(Collection<T> collection)
Returns a sorted unmodifiable list for a collection. |
|
static
|
asSortedUnmodifiableList(Collection<T> collection,
Comparator<? super T> comparator)
Returns a sorted unmodifiable list for a collection. |
|
static
|
asUnmodifiable(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(List<T> l)
Returns a new unmodifiable list wrapping the given list. |
|
static
|
asUnmodifiable(Map<S,T> m)
Returns a new unmodifiable map wrapping the given map. |
|
static
|
asUnmodifiable(Set<T> s)
Returns a new unmodifiable set wrapping the given set. |
|
static
|
asUnmodifiable(SortedMap<S,T> m)
Returns a new unmodifiable sorted map wrapping the given sorted map. |
|
static
|
asUnmodifiable(SortedSet<T> s)
Returns a new unmodifiable sorted set wrapping the given sorted set. |
|
static
|
computeUnorderedPairs(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(Iterable<T> iterable)
Returns one object from an Iterable or null if the
iterable is empty. |
|
static
|
getLast(List<T> list)
Returns the last element in list or null, if list is empty. |
|
static
|
reverse(Collection<T> list)
Returns a list that contains the elements of the specified list in reversed order. |
|
static
|
sort(Collection<T> collection)
Sorts the specified list into ascending order, according to the natural ordering of its elements. |
|
static
|
sort(Collection<T> collection,
Comparator<? super T> comparator)
Sorts the specified list according to the order induced by the specified comparator. |
|
static
|
toArray(Collection<? extends T> collection,
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> HashSet<T> asHashSet(T... elements)
T - typeelements - elements in the set.
Arrays.asList(Object[])public static <T> UnmodifiableCollection<T> asUnmodifiable(Collection<T> c)
public static <S,T> UnmodifiableHashedListMap<S,T> asUnmodifiable(HashedListMap<S,T> m)
public static <T> UnmodifiableList<T> asUnmodifiable(List<T> l)
public static <S,T> UnmodifiableMap<S,T> asUnmodifiable(Map<S,T> m)
public static <T> UnmodifiableSet<T> asUnmodifiable(Set<T> s)
public static <S,T> UnmodifiableSortedMap<S,T> asUnmodifiable(SortedMap<S,T> m)
public static <T> UnmodifiableSortedSet<T> asUnmodifiable(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 Comparable<? super T>> List<T> sort(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> List<T> reverse(Collection<T> list)
This method does not modify the original collection.
public static <T> List<T> sort(Collection<T> collection,
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 Comparable<T>> UnmodifiableList<T> asSortedUnmodifiableList(Collection<T> collection)
public static <T extends Comparable<T>> UnmodifiableList<T> asSortedUnmodifiableList(Collection<T> collection,
Comparator<? super T> comparator)
comparator - Comparator used for sortingpublic static <T> T getAny(Iterable<T> iterable)
Iterable or null if the
iterable is empty.
public static <T> T[] toArray(Collection<? extends T> collection,
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> List<ImmutablePair<T,T>> computeUnorderedPairs(Collection<T> collection)
public static <T> T getLast(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 | |||||||||