Package org.fest.util
Class Collections
java.lang.Object
org.fest.util.Collections
Understands utility methods related to collections.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection<T>duplicatesFrom(Collection<T> c) Returns any duplicate elements from the given collection.static <T> List<T>filter(Collection<?> target, CollectionFilter<T> filter) static Stringformat(Collection<?> c) Returns theStringrepresentation of the given collection, ornullif the given collection isnull.static booleanReturnstrueif the given collection has onlynullelements,falseotherwise.static booleanisEmpty(Collection<?> c) Returnstrueif the given collection isnullor empty.static <T> List<T>list(T... elements) Creates a list containing the given elements.static <T> Collection<T>nonNullElements(Collection<T> c) Returns a new unmodifiable collection containing the non-null elements of the given collection.static <T> List<T>nonNullElements(List<T> l) Returns a new unmodifiable list containing the non-null elements of the given list.
-
Constructor Details
-
Collections
private Collections()
-
-
Method Details
-
list
Creates a list containing the given elements.- Type Parameters:
T- the type of elements of the list to create.- Parameters:
elements- the elements to store in the list.- Returns:
- a list containing the given elements.
-
duplicatesFrom
Returns any duplicate elements from the given collection.- Type Parameters:
T- the generic type of the given collection.- Parameters:
c- the given collection that might have duplicate elements.- Returns:
- a collection containing the duplicate elements of the given one. If no duplicates are found, an empty collection is returned.
-
isEmpty
Returnstrueif the given collection isnullor empty.- Parameters:
c- the collection to check.- Returns:
trueif the given collection isnullor empty, otherwisefalse.
-
filter
-
format
Returns theStringrepresentation of the given collection, ornullif the given collection isnull.- Parameters:
c- the collection to format.- Returns:
- the
Stringrepresentation of the given collection.
-
nonNullElements
Returns a new unmodifiable collection containing the non-null elements of the given collection. This method returns an empty unmodifiable collection if the given collection has onlynullelements or if it is empty. This method returnsnullif the given collection isnull.- Type Parameters:
T- the type of elements of the collection.- Parameters:
c- the collection we want to extract non null elements from.- Returns:
- a new unmodifiable collection containing the non-null elements of the given collection, or
nullif the given collection isnull. - Since:
- 1.1.3
-
nonNullElements
Returns a new unmodifiable list containing the non-null elements of the given list. This method returns an empty unmodifiable list if the given list has onlynullelements or if it is empty. This method returnsnullif the given list isnull.- Type Parameters:
T- the type of elements of the list.- Parameters:
l- the list we want to extract non null elements from.- Returns:
- a new unmodifiable list containing the non-null elements of the given list, or
nullif the given list isnull. - Since:
- 1.1.3
-
hasOnlyNullElements
Returnstrueif the given collection has onlynullelements,falseotherwise. If given collection is empty, this method returnstrue.- Parameters:
c- the given collection. It must not be null.- Returns:
trueif the given collection has onlynullelements or is empty,falseotherwise.- Throws:
NullPointerException- if the given collection isnull.- Since:
- 1.1.3
-