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 String
format
(Collection<?> c) Returns theString
representation of the given collection, ornull
if the given collection isnull
.static boolean
Returnstrue
if the given collection has onlynull
elements,false
otherwise.static boolean
isEmpty
(Collection<?> c) Returnstrue
if the given collection isnull
or 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
Returnstrue
if the given collection isnull
or empty.- Parameters:
c
- the collection to check.- Returns:
true
if the given collection isnull
or empty, otherwisefalse
.
-
filter
-
format
Returns theString
representation of the given collection, ornull
if the given collection isnull
.- Parameters:
c
- the collection to format.- Returns:
- the
String
representation 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 onlynull
elements or if it is empty. This method returnsnull
if 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
null
if 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 onlynull
elements or if it is empty. This method returnsnull
if 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
null
if the given list isnull
. - Since:
- 1.1.3
-
hasOnlyNullElements
Returnstrue
if the given collection has onlynull
elements,false
otherwise. If given collection is empty, this method returnstrue
.- Parameters:
c
- the given collection. It must not be null.- Returns:
true
if the given collection has onlynull
elements or is empty,false
otherwise.- Throws:
NullPointerException
- if the given collection isnull
.- Since:
- 1.1.3
-