net.sf.collections15.functors.predicate
Class OnePredicate<E>

java.lang.Object
  extended by net.sf.collections15.functors.predicate.AbstractMultplePredicateDecorator<E>
      extended by net.sf.collections15.functors.predicate.OnePredicate<E>
All Implemented Interfaces:
java.io.Serializable, MultplePredicateDecorator<E>, Predicate<E>

public final class OnePredicate<E>
extends AbstractMultplePredicateDecorator<E>

Predicate implementation that returns true if exactly one decorated Predicates return true.

Since:
Collections15 1.0
Author:
Stephen Colebourne, Chris Lambrou (port to Java 5.0)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.collections15.functors.predicate.AbstractMultplePredicateDecorator
decoratedPredicates
 
Constructor Summary
protected OnePredicate(java.util.Collection<Predicate<? super E>> predicates)
          Creates a new instance that wraps the specified collection of Predicates.
 
Method Summary
 boolean evaluate(E object)
          Evaluates the Predicate returning true exactly one of the decorated Predicates returns true.
static
<T> OnePredicate<T>
getInstance(java.util.Collection<Predicate<? super T>> predicates)
          Returns an instance that wraps the specified collection of Predicates.
 
Methods inherited from class net.sf.collections15.functors.predicate.AbstractMultplePredicateDecorator
getDecoratedPredicates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnePredicate

protected OnePredicate(java.util.Collection<Predicate<? super E>> predicates)
Creates a new instance that wraps the specified collection of Predicates.

Parameters:
predicates - The Predicates to wrap. The contents of the collection are defensively copied by the new instance.
Throws:
java.lang.IllegalArgumentException - Thrown if the collection, or any of its elements are null. The collection may be empty, however, in which case the resulting AnyPredicate will always return false.
Method Detail

getInstance

public static <T> OnePredicate<T> getInstance(java.util.Collection<Predicate<? super T>> predicates)
Returns an instance that wraps the specified collection of Predicates.

Parameters:
predicates - The Predicates to wrap. The contents of the collection are defensively copied by the new instance.
Returns:
A Predicate instance that will only evaluate to true if exactly one of the wrapped Predicates evaluates to true.
Throws:
java.lang.IllegalArgumentException - Thrown if the collection, or any of its elements are null. The collection may be empty, however, in which case the resulting AnyPredicate will always return false.

evaluate

public boolean evaluate(E object)
Evaluates the Predicate returning true exactly one of the decorated Predicates returns true.

Parameters:
object - The input object to evaluate.
Returns:
true if exactly one of the decorated Predicates returns true.


Copyright © 2001-2005 SourceForge.net. All Rights Reserved.