org.fest.util
Class Collections

java.lang.Object
  extended by org.fest.util.Collections

public final class Collections
extends Object

Understands utility methods related to collections.

Author:
Yvonne Wang, Alex Ruiz

Method Summary
static
<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 the String representation of the given collection, or null if the given collection is null.
static boolean hasOnlyNullElements(Collection<?> collection)
          Returns true if the given collection has only null elements, false otherwise.
static boolean isEmpty(Collection<?> c)
          Returns true if the given collection is null or empty.
static
<T> List<T>
list(T... elements)
          Creates a list containing the given elements.
static Collection<Object> nonNullElements(Collection<?> collection)
          Returns a new collection composed of the non null elements of the given collection.
static List<Object> nonNullElements(List<?> list)
          Returns a new list composed of the non null elements of the given list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

list

public static <T> List<T> list(T... elements)
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

public static <T> Collection<T> duplicatesFrom(Collection<T> c)
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

public static boolean isEmpty(Collection<?> c)
Returns true if the given collection is null or empty.

Parameters:
c - the collection to check.
Returns:
true if the given collection is null or empty, otherwise false.

filter

public static <T> List<T> filter(Collection<?> target,
                                 CollectionFilter<T> filter)

format

public static String format(Collection<?> c)
Returns the String representation of the given collection, or null if the given collection is null.

Parameters:
c - the collection to format.
Returns:
the String representation of the given collection.

nonNullElements

public static Collection<Object> nonNullElements(Collection<?> collection)
Returns a new collection composed of the non null elements of the given collection.

Returns an empty collection if given collection has only null elements, and null if given collection is null.

Parameters:
collection - Collection we want to extract non null elements
Returns:
A new collection composed of the non null elements of the given collection

nonNullElements

public static List<Object> nonNullElements(List<?> list)
Returns a new list composed of the non null elements of the given list.

Returns an empty list if given list has only null elements, and null if given list is null.

Parameters:
list - List we want to extract non null elements
Returns:
A new list composed of the non null elements of the given list

hasOnlyNullElements

public static boolean hasOnlyNullElements(Collection<?> collection)
Returns true if the given collection has only null elements, false otherwise.

If given collection is empty, returns true.

Parameters:
collection - the given collection, must not be null.
Returns:
True if the given collection has only null elements or is empty, false otherwise
Throws:
NullPointerException - if the given collection is null


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.