Class OnePredicate<T>
java.lang.Object
org.apache.commons.collections4.functors.AbstractQuantifierPredicate<T>
org.apache.commons.collections4.functors.OnePredicate<T>
- All Implemented Interfaces:
Serializable
,Predicate<T>
,PredicateDecorator<T>
,Predicate<T>
Predicate implementation that returns true if only one of the
predicates return true.
If the array of predicates is empty, then this predicate returns false.
NOTE: In versions prior to 3.2 an array size of zero or one threw an exception.
- Since:
- 3.0
- See Also:
-
Field Summary
Fields inherited from class org.apache.commons.collections4.functors.AbstractQuantifierPredicate
iPredicates
-
Constructor Summary
ConstructorDescriptionOnePredicate
(Predicate<? super T>... predicates) Constructor that performs no validation. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Evaluates the predicate returning true if only one decorated predicate returns true.static <T> Predicate<T>
onePredicate
(Collection<? extends Predicate<? super T>> predicates) Factory to create the predicate.static <T> Predicate<T>
onePredicate
(Predicate<? super T>... predicates) Factory to create the predicate.Methods inherited from class org.apache.commons.collections4.functors.AbstractQuantifierPredicate
getPredicates
-
Constructor Details
-
OnePredicate
Constructor that performs no validation. UseonePredicate
if you want that.- Parameters:
predicates
- the predicates to check, not cloned, not null
-
-
Method Details
-
onePredicate
Factory to create the predicate.- Type Parameters:
T
- the type that the predicate queries- Parameters:
predicates
- the predicates to check, cloned, not null- Returns:
- the
one
predicate - Throws:
NullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is null
-
onePredicate
Factory to create the predicate.If the array is size zero, the predicate always returns false. If the array is size one, then that predicate is returned.
- Type Parameters:
T
- the type that the predicate queries- Parameters:
predicates
- the predicates to check, cloned, not null- Returns:
- the
any
predicate - Throws:
NullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is null
-
evaluate
Evaluates the predicate returning true if only one decorated predicate returns true.- Parameters:
object
- the input object- Returns:
- true if only one decorated predicate returns true
-