org.littleshoot.util
Interface CollectionUtils

All Known Implementing Classes:
CollectionUtilsImpl

public interface CollectionUtils

Collection utilities.


Method Summary
<T1,T2> T2
foldl(F2<T2,T1,T2> f, T2 initial, Collection<? extends T1> collection)
          Left-associative fold function.
<T> void
forAllDo(Collection<? extends T> collection, Closure<T> closure)
          Executes the specified Closure on all elements of the Collection.
<T> void
forAllDoSynchronized(Collection<? extends T> collection, Closure<T> closure)
          Executes the specified Closure on all elements of the Collection.
<T1,T2> Collection<T2>
map(Collection<? extends T1> collection, F1<T1,T2> f)
          Maps the items in a collection using a given function.
<T> boolean
matchesAll(Collection<? extends T> elements, Predicate<T> pred)
          Checks to see if all of the elements of the given Collection matches the predicate.
<T> boolean
matchesAny(Collection<? extends T> elements, Predicate<T> pred)
          Checks to see if any of the elements of the given Collection matches the predicate.
<T> Collection<T>
select(Collection<? extends T> collection, Predicate<T> predicate)
          Returns a collection of all of the elements in a given collection that satisfy a given predicate.
<T> void
select(Collection<? extends T> collection, Predicate<T> predicate, Collection<T> result)
          Adds all of the elements in a given collection that satisfy a given predicate to another given collection.
<T> T
selectFirst(Collection<? extends T> collection, Predicate<T> pred)
          Selects the first element matching the desired criteria, or null if no matching element exists.
<T> T
selectFirstSynchronized(Collection<? extends T> collection, Predicate<T> pred)
          Selects the first element matching the desired criteria, or null if no matching element exists.
 long sum(Collection<Long> c)
          Returns the sum of a collection of long integers.
<T> boolean
synchronizedMatchesAny(Collection<? extends T> elements, Predicate<T> pred)
          Checks to see if any of the elements of the given Collection matches the predicate.
 

Method Detail

select

<T> void select(Collection<? extends T> collection,
                Predicate<T> predicate,
                Collection<T> result)
Adds all of the elements in a given collection that satisfy a given predicate to another given collection.

Type Parameters:
T - The type of objects in the collection and expected by the predicate.
Parameters:
collection - The collection.
predicate - The predicate used to evaluate each element.
result - The collection to which to add the elements that satisfy the predicate.

select

<T> Collection<T> select(Collection<? extends T> collection,
                         Predicate<T> predicate)
Returns a collection of all of the elements in a given collection that satisfy a given predicate.

Type Parameters:
T - The type of objects in the collection and expected by the predicate.
Parameters:
collection - The collection.
predicate - The predicate used to evaluate each element.
Returns:
A collection of all of the elements in a given collection that satisfy a given predicate.

map

<T1,T2> Collection<T2> map(Collection<? extends T1> collection,
                           F1<T1,T2> f)
Maps the items in a collection using a given function.

Type Parameters:
T1 - The type of elements in the original collection.
T2 - The type to which we are mapping.
Parameters:
collection - The collection to map.
f - The mapping function.
Returns:
The mapped collection.

foldl

<T1,T2> T2 foldl(F2<T2,T1,T2> f,
                 T2 initial,
                 Collection<? extends T1> collection)
Left-associative fold function.

Type Parameters:
T1 - The type of the collection over which to fold.
T2 - The type returned by the folding function.
Parameters:
f - The folding function.
initial - The initial value for folding.
collection - The collection.
Returns:
The result of the folding.

sum

long sum(Collection<Long> c)
Returns the sum of a collection of long integers.

Parameters:
c - The collection of long integers.
Returns:
The sum of the collection of long integers.

forAllDo

<T> void forAllDo(Collection<? extends T> collection,
                  Closure<T> closure)
Executes the specified Closure on all elements of the Collection.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
collection - The Collection with elements to perform the closure on.
closure - The Closure to execute on each element.

forAllDoSynchronized

<T> void forAllDoSynchronized(Collection<? extends T> collection,
                              Closure<T> closure)
Executes the specified Closure on all elements of the Collection. Also synchronizes on the Collection.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
collection - The Collection with elements to perform the closure on.
closure - The Closure to execute on each element.

matchesAny

<T> boolean matchesAny(Collection<? extends T> elements,
                       Predicate<T> pred)
Checks to see if any of the elements of the given Collection matches the predicate.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
elements - The Collection to check.
pred - The Predicate determining if an element matches.
Returns:
true if there's any element in the Collection matching the desired criteria.

matchesAll

<T> boolean matchesAll(Collection<? extends T> elements,
                       Predicate<T> pred)
Checks to see if all of the elements of the given Collection matches the predicate.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
elements - The Collection to check.
pred - The Predicate determining if all elements match.
Returns:
true if all elements in the Collection match the desired criteria.

synchronizedMatchesAny

<T> boolean synchronizedMatchesAny(Collection<? extends T> elements,
                                   Predicate<T> pred)
Checks to see if any of the elements of the given Collection matches the predicate. Synchronizes on the Collection.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
elements - The Collection to check.
pred - The Predicate determining if an element matches.
Returns:
true if there's any element in the Collection matching the desired criteria.

selectFirst

<T> T selectFirst(Collection<? extends T> collection,
                  Predicate<T> pred)
Selects the first element matching the desired criteria, or null if no matching element exists. Synchronizes on the Collection.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
collection - The Collection of elements to search.
pred - The Predicate determining a match.
Returns:
The first matching element, or null if no such element exists.

selectFirstSynchronized

<T> T selectFirstSynchronized(Collection<? extends T> collection,
                              Predicate<T> pred)
Selects the first element matching the desired criteria, or null if no matching element exists. Synchronizes on the Collection.

Type Parameters:
T - The type of elements in the Collection.
Parameters:
collection - The Collection of elements to search.
pred - The Predicate determining a match.
Returns:
The first matching element, or null if no such element exists.


Copyright © 2011-2013 LittleShoot. All Rights Reserved.