vitro.util
Class Groups

java.lang.Object
  extended by vitro.util.Groups

public class Groups
extends Object

Groups provides a set of utility methods for filtering and manipulating collections.


Constructor Summary
Groups()
           
 
Method Summary
static
<S> S
any(Collection<S> source)
          Extract a random element from a Collection.
static
<S,C extends S>
boolean
containsType(Class<C> c, Collection<S> source)
          Check a Collection for elements with a given class.
static
<S> S
first(Collection<S> source)
          Extract the first element from a Collection.
static
<S,C extends S>
S
firstOfType(Class<C> c, Collection<S> source)
          Extract an element from a Collection with a given class.
static
<S,C extends S>
List<S>
ofType(Class<C> c, Collection<S> source)
          Extract elements from a Collection with a given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Groups

public Groups()
Method Detail

firstOfType

public static <S,C extends S> S firstOfType(Class<C> c,
                                            Collection<S> source)
Extract an element from a Collection with a given class.

Parameters:
c - the desired Class.
source - the Collection to filter.
Returns:
the first Object in source that is an instance of c.

ofType

public static <S,C extends S> List<S> ofType(Class<C> c,
                                             Collection<S> source)
Extract elements from a Collection with a given class.

Parameters:
c - the desired Class.
source - the Collection to filter.
Returns:
a List of Objects from source that are instances of c.

containsType

public static <S,C extends S> boolean containsType(Class<C> c,
                                                   Collection<S> source)
Check a Collection for elements with a given class.

Parameters:
c - the desired Class.
source - the Collection to examine.
Returns:
true if there is an Object in source that is an instance of c.

any

public static <S> S any(Collection<S> source)
Extract a random element from a Collection.

Parameters:
source - the Collection to filter.
Returns:
a random Object from source.

first

public static <S> S first(Collection<S> source)
Extract the first element from a Collection. The first element returned by the collection's iterator is considered 'first'.

Parameters:
source - the Collection to filter.
Returns:
the first Object from source.