org.springframework.rules.closure.support
Class Algorithms

Show UML class diagram
java.lang.Object
  extended by org.springframework.rules.closure.support.Algorithms

public class Algorithms
extends Object

Convenience utility class which provides a number of algorithms involving function objects such as closures and constraints.

Author:
Keith Donald

Constructor Summary
Algorithms()
           
 
Method Summary
 boolean allTrue(Collection collection, Constraint constraint)
          Returns true if all elements in the given collection meet the specified predicate condition.
 boolean allTrue(Iterator it, Constraint constraint)
          Returns true if all elements in the given collection meet the specified predicate condition.
 boolean anyTrue(Collection collection, Constraint constraint)
          Returns true if any elements in the given collection meet the specified predicate condition.
 boolean anyTrue(Iterator it, Constraint constraint)
          Returns true if any elements in the given collection meet the specified predicate condition.
 Collection findAll(Collection collection, Constraint constraint)
          Find all the elements in the collection that match the specified constraint.
 Collection findAll(Iterator it, Constraint constraint)
          Find all the elements in the collection that match the specified constraint.
 Object findFirst(Collection collection, Constraint constraint)
          Find the first element in the collection matching the specified constraint.
 Object findFirst(Iterator it, Constraint constraint)
          Find the first element in the collection matching the specified constraint.
 void forEach(Collection collection, Closure closure)
          Execute the provided closure for each element in the collection.
 void forEach(Iterator it, Closure closure)
          Execute the provided closure for each element in the collection.
static Algorithms instance()
          Singleton instance accessor
static void load(Algorithms instance)
          Load the shared instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Algorithms

public Algorithms()
Method Detail

load

public static void load(Algorithms instance)
Load the shared instance

Parameters:
instance -

instance

public static Algorithms instance()
Singleton instance accessor

Returns:
The algorithms instance

anyTrue

public boolean anyTrue(Collection collection,
                       Constraint constraint)
Returns true if any elements in the given collection meet the specified predicate condition.

Parameters:
collection - the collection
constraint - the iterator
Returns:
true or false

anyTrue

public boolean anyTrue(Iterator it,
                       Constraint constraint)
Returns true if any elements in the given collection meet the specified predicate condition.

Parameters:
it - the iterator
constraint - the constraint
Returns:
true or false

allTrue

public boolean allTrue(Collection collection,
                       Constraint constraint)
Returns true if all elements in the given collection meet the specified predicate condition.

Parameters:
collection -
constraint -
Returns:
true or false

allTrue

public boolean allTrue(Iterator it,
                       Constraint constraint)
Returns true if all elements in the given collection meet the specified predicate condition.

Parameters:
it - the iterator
constraint - the constraint
Returns:
true if all true, false otherwise

findFirst

public Object findFirst(Collection collection,
                        Constraint constraint)
Find the first element in the collection matching the specified constraint.

Parameters:
collection - the collection
constraint - the predicate
Returns:
The first object match, or null if no match

findFirst

public Object findFirst(Iterator it,
                        Constraint constraint)
Find the first element in the collection matching the specified constraint.

Parameters:
it - the iterator
constraint - the predicate
Returns:
The first object match, or null if no match

findAll

public Collection findAll(Collection collection,
                          Constraint constraint)
Find all the elements in the collection that match the specified constraint.

Parameters:
collection -
constraint -
Returns:
The objects that match, or a empty collection if none match

findAll

public Collection findAll(Iterator it,
                          Constraint constraint)
Find all the elements in the collection that match the specified constraint.

Parameters:
it - the iterator
constraint - the constraint
Returns:
The objects that match, or a empty collection if none match

forEach

public void forEach(Collection collection,
                    Closure closure)
Execute the provided closure for each element in the collection.

Parameters:
collection - the collection
closure - the callback

forEach

public void forEach(Iterator it,
                    Closure closure)
Execute the provided closure for each element in the collection.

Parameters:
it - the iterator
closure - the callback


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.