Migrate toward java.util.function.Predicate
- Maintains binary and source compatibility - Javadoc
This commit is contained in:
parent
d5dd6e4468
commit
3618193221
|
@ -833,7 +833,7 @@ public class CollectionUtils {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (collection != null && predicate != null) {
|
if (collection != null && predicate != null) {
|
||||||
for (final Iterator<T> it = collection.iterator(); it.hasNext();) {
|
for (final Iterator<T> it = collection.iterator(); it.hasNext();) {
|
||||||
if (!predicate.evaluate(it.next())) {
|
if (!predicate.test(it.next())) {
|
||||||
it.remove();
|
it.remove();
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -1740,7 +1740,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
if (inputCollection != null && predicate != null) {
|
if (inputCollection != null && predicate != null) {
|
||||||
for (final O item : inputCollection) {
|
for (final O item : inputCollection) {
|
||||||
if (predicate.evaluate(item)) {
|
if (predicate.test(item)) {
|
||||||
outputCollection.add(item);
|
outputCollection.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1783,7 +1783,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
if (inputCollection != null && predicate != null) {
|
if (inputCollection != null && predicate != null) {
|
||||||
for (final O element : inputCollection) {
|
for (final O element : inputCollection) {
|
||||||
if (predicate.evaluate(element)) {
|
if (predicate.test(element)) {
|
||||||
outputCollection.add(element);
|
outputCollection.add(element);
|
||||||
} else {
|
} else {
|
||||||
rejectedCollection.add(element);
|
rejectedCollection.add(element);
|
||||||
|
@ -1837,7 +1837,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
if (inputCollection != null && predicate != null) {
|
if (inputCollection != null && predicate != null) {
|
||||||
for (final O item : inputCollection) {
|
for (final O item : inputCollection) {
|
||||||
if (!predicate.evaluate(item)) {
|
if (!predicate.test(item)) {
|
||||||
outputCollection.add(item);
|
outputCollection.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1998,7 +1998,7 @@ public class CollectionUtils {
|
||||||
final ArrayList<O> list = new ArrayList<>();
|
final ArrayList<O> list = new ArrayList<>();
|
||||||
final HashBag<O> bag = new HashBag<>();
|
final HashBag<O> bag = new HashBag<>();
|
||||||
for (final O element : b) {
|
for (final O element : b) {
|
||||||
if (p.evaluate(element)) {
|
if (p.test(element)) {
|
||||||
bag.add(element);
|
bag.add(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,7 +698,7 @@ public class IterableUtils {
|
||||||
for (final O element : iterable) {
|
for (final O element : iterable) {
|
||||||
boolean elementAssigned = false;
|
boolean elementAssigned = false;
|
||||||
for (int i = 0; i < numberOfPredicates; ++i) {
|
for (int i = 0; i < numberOfPredicates; ++i) {
|
||||||
if (predicates[i].evaluate(element)) {
|
if (predicates[i].test(element)) {
|
||||||
partitions.get(i).add(element);
|
partitions.get(i).add(element);
|
||||||
elementAssigned = true;
|
elementAssigned = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -673,7 +673,7 @@ public class IteratorUtils {
|
||||||
if (iterator != null) {
|
if (iterator != null) {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E element = iterator.next();
|
final E element = iterator.next();
|
||||||
if (predicate.evaluate(element)) {
|
if (predicate.test(element)) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -860,7 +860,7 @@ public class IteratorUtils {
|
||||||
if (iterator != null) {
|
if (iterator != null) {
|
||||||
for (int index = 0; iterator.hasNext(); index++) {
|
for (int index = 0; iterator.hasNext(); index++) {
|
||||||
final E element = iterator.next();
|
final E element = iterator.next();
|
||||||
if (predicate.evaluate(element)) {
|
if (predicate.test(element)) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -935,7 +935,7 @@ public class IteratorUtils {
|
||||||
if (iterator != null) {
|
if (iterator != null) {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E element = iterator.next();
|
final E element = iterator.next();
|
||||||
if (!predicate.evaluate(element)) {
|
if (!predicate.test(element)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class ListUtils {
|
||||||
if (list != null && predicate != null) {
|
if (list != null && predicate != null) {
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
final E item = list.get(i);
|
final E item = list.get(i);
|
||||||
if (predicate.evaluate(item)) {
|
if (predicate.test(item)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ package org.apache.commons.collections4;
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param <T> the type of the input to the predicate.
|
* @param <T> the type of the input to the predicate.
|
||||||
*
|
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @deprecated Use {@link java.util.function.Predicate}.
|
* @deprecated Use {@link java.util.function.Predicate}.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
|
||||||
* @return the PredicatedCollectionBuilder.
|
* @return the PredicatedCollectionBuilder.
|
||||||
*/
|
*/
|
||||||
public Builder<E> add(final E item) {
|
public Builder<E> add(final E item) {
|
||||||
if (predicate.evaluate(item)) {
|
if (predicate.test(item)) {
|
||||||
accepted.add(item);
|
accepted.add(item);
|
||||||
} else {
|
} else {
|
||||||
rejected.add(item);
|
rejected.add(item);
|
||||||
|
@ -419,7 +419,7 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
|
||||||
* @throws IllegalArgumentException if the add is invalid
|
* @throws IllegalArgumentException if the add is invalid
|
||||||
*/
|
*/
|
||||||
protected void validate(final E object) {
|
protected void validate(final E object) {
|
||||||
if (!predicate.evaluate(object)) {
|
if (!predicate.test(object)) {
|
||||||
throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate '" +
|
throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate '" +
|
||||||
predicate + "' rejected it");
|
predicate + "' rejected it");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Abstract base class for quantification predicates, e.g. All, Any, None.
|
* Abstract base class for quantification predicates, e.g. All, Any, None.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractQuantifierPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public abstract class AbstractQuantifierPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -3094696765038308799L;
|
private static final long serialVersionUID = -3094696765038308799L;
|
||||||
|
@ -53,8 +54,4 @@ public abstract class AbstractQuantifierPredicate<T> implements PredicateDecorat
|
||||||
return FunctorUtils.<T>copy(iPredicates);
|
return FunctorUtils.<T>copy(iPredicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean evaluate(final T object) {
|
|
||||||
return test(object);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* threw an exception.
|
* threw an exception.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class AllPredicate<T> extends AbstractQuantifierPredicate<T> {
|
public final class AllPredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
|
@ -106,7 +107,7 @@ public final class AllPredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
for (final Predicate<? super T> iPredicate : iPredicates) {
|
for (final Predicate<? super T> iPredicate : iPredicates) {
|
||||||
if (!iPredicate.evaluate(object)) {
|
if (!iPredicate.test(object)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that returns true if both the predicates return true.
|
* Predicate implementation that returns true if both the predicates return true.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class AndPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class AndPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 4189014213763186912L;
|
private static final long serialVersionUID = 4189014213763186912L;
|
||||||
|
@ -70,8 +71,8 @@ public final class AndPredicate<T> implements PredicateDecorator<T>, Serializabl
|
||||||
* @return true if both decorated predicates return true
|
* @return true if both decorated predicates return true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
return iPredicate1.evaluate(object) && iPredicate2.evaluate(object);
|
return iPredicate1.test(object) && iPredicate2.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* threw an exception.
|
* threw an exception.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class AnyPredicate<T> extends AbstractQuantifierPredicate<T> {
|
public final class AnyPredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
|
@ -103,7 +104,7 @@ public final class AnyPredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
for (final Predicate<? super T> iPredicate : iPredicates) {
|
for (final Predicate<? super T> iPredicate : iPredicates) {
|
||||||
if (iPredicate.evaluate(object)) {
|
if (iPredicate.test(object)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* following way:</p>
|
* following way:</p>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* ComparatorPredicate.comparatorPredicate(ONE, comparator).evaluate(TWO);
|
* ComparatorPredicate.comparatorPredicate(ONE, comparator).test(TWO);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>The input variable {@code TWO} in compared to the stored variable {@code ONE} using
|
* <p>The input variable {@code TWO} in compared to the stored variable {@code ONE} using
|
||||||
|
@ -67,7 +67,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* evaluation of a comparator result.</p>
|
* evaluation of a comparator result.</p>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* ComparatorPredicate.comparatorPredicate(ONE, comparator,<b>ComparatorPredicate.Criterion.GREATER</b>).evaluate(TWO);
|
* ComparatorPredicate.comparatorPredicate(ONE, comparator,<b>ComparatorPredicate.Criterion.GREATER</b>).test(TWO);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* <p>The input variable TWO is compared to the stored variable ONE using the supplied {@code comparator}
|
* <p>The input variable TWO is compared to the stored variable ONE using the supplied {@code comparator}
|
||||||
|
@ -150,7 +150,7 @@ public class ComparatorPredicate<T> extends AbstractPredicate<T> implements Seri
|
||||||
* <li>{@code comparator.compare(object, input) <= 0 && criterion == LESS_OR_EQUAL}</li>
|
* <li>{@code comparator.compare(object, input) <= 0 && criterion == LESS_OR_EQUAL}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @see org.apache.commons.collections4.Predicate#evaluate(Object)
|
* @see org.apache.commons.collections4.Predicate#test(Object)
|
||||||
* @see java.util.Comparator#compare(Object first, Object second)
|
* @see java.util.Comparator#compare(Object first, Object second)
|
||||||
*
|
*
|
||||||
* @param target the target object to compare to
|
* @param target the target object to compare to
|
||||||
|
|
|
@ -49,7 +49,7 @@ final class FunctorUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A very simple method that coerces Predicate<? super T> to Predicate<T>.
|
* A very simple method that coerces Predicate<? super T> to Predicate<T>.
|
||||||
* Due to the {@link Predicate#evaluate(T)} method, Predicate<? super T> is
|
* Due to the {@link Predicate#test(T)} method, Predicate<? super T> is
|
||||||
* able to be coerced to Predicate<T> without casting issues.
|
* able to be coerced to Predicate<T> without casting issues.
|
||||||
* <p>This method exists
|
* <p>This method exists
|
||||||
* simply as centralised documentation and atomic unchecked warning
|
* simply as centralised documentation and atomic unchecked warning
|
||||||
|
@ -96,7 +96,7 @@ final class FunctorUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone the predicates to ensure that the internal reference can't be messed with.
|
* Clone the predicates to ensure that the internal reference can't be messed with.
|
||||||
* Due to the {@link Predicate#evaluate(T)} method, Predicate<? super T> is
|
* Due to the {@link Predicate#test(T)} method, Predicate<? super T> is
|
||||||
* able to be coerced to Predicate<T> without casting issues.
|
* able to be coerced to Predicate<T> without casting issues.
|
||||||
*
|
*
|
||||||
* @param predicates the predicates to copy
|
* @param predicates the predicates to copy
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class IfClosure<E> implements Closure<E>, Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(final E input) {
|
public void execute(final E input) {
|
||||||
if (iPredicate.evaluate(input)) {
|
if (iPredicate.test(input)) {
|
||||||
iTrueClosure.accept(input);
|
iTrueClosure.accept(input);
|
||||||
} else {
|
} else {
|
||||||
iFalseClosure.accept(input);
|
iFalseClosure.accept(input);
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public O transform(final I input) {
|
||||||
if (iPredicate.evaluate(input)) {
|
if (iPredicate.test(input)) {
|
||||||
return iTrueTransformer.transform(input);
|
return iTrueTransformer.transform(input);
|
||||||
}
|
}
|
||||||
return iFalseTransformer.transform(input);
|
return iFalseTransformer.transform(input);
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* threw an exception.
|
* threw an exception.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class NonePredicate<T> extends AbstractQuantifierPredicate<T> {
|
public final class NonePredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
|
@ -93,7 +94,7 @@ public final class NonePredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
for (final Predicate<? super T> iPredicate : iPredicates) {
|
for (final Predicate<? super T> iPredicate : iPredicates) {
|
||||||
if (iPredicate.evaluate(object)) {
|
if (iPredicate.test(object)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that returns the opposite of the decorated predicate.
|
* Predicate implementation that returns the opposite of the decorated predicate.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class NotPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class NotPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -2654603322338049674L;
|
private static final long serialVersionUID = -2654603322338049674L;
|
||||||
|
@ -63,8 +64,8 @@ public final class NotPredicate<T> implements PredicateDecorator<T>, Serializabl
|
||||||
* @return true if predicate returns false
|
* @return true if predicate returns false
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
return !iPredicate.evaluate(object);
|
return !iPredicate.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,9 +25,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that throws an exception if the input is null.
|
* Predicate implementation that throws an exception if the input is null.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class NullIsExceptionPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class NullIsExceptionPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = 3243449850504576071L;
|
private static final long serialVersionUID = 3243449850504576071L;
|
||||||
|
@ -66,11 +67,11 @@ public final class NullIsExceptionPredicate<T> implements PredicateDecorator<T>,
|
||||||
* @throws FunctorException if input is null
|
* @throws FunctorException if input is null
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
throw new FunctorException("Input Object must not be null");
|
throw new FunctorException("Input Object must not be null");
|
||||||
}
|
}
|
||||||
return iPredicate.evaluate(object);
|
return iPredicate.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,9 +24,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that returns false if the input is null.
|
* Predicate implementation that returns false if the input is null.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class NullIsFalsePredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class NullIsFalsePredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -2997501534564735525L;
|
private static final long serialVersionUID = -2997501534564735525L;
|
||||||
|
@ -64,11 +65,11 @@ public final class NullIsFalsePredicate<T> implements PredicateDecorator<T>, Ser
|
||||||
* @return true if decorated predicate returns true, false if input is null
|
* @return true if decorated predicate returns true, false if input is null
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return iPredicate.evaluate(object);
|
return iPredicate.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,9 +24,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that returns true if the input is null.
|
* Predicate implementation that returns true if the input is null.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class NullIsTruePredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class NullIsTruePredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -7625133768987126273L;
|
private static final long serialVersionUID = -7625133768987126273L;
|
||||||
|
@ -64,11 +65,11 @@ public final class NullIsTruePredicate<T> implements PredicateDecorator<T>, Seri
|
||||||
* @return true if decorated predicate returns true or input is null
|
* @return true if decorated predicate returns true or input is null
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return iPredicate.evaluate(object);
|
return iPredicate.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.collections4.Predicate;
|
||||||
* threw an exception.
|
* threw an exception.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class OnePredicate<T> extends AbstractQuantifierPredicate<T> {
|
public final class OnePredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
|
@ -95,7 +96,7 @@ public final class OnePredicate<T> extends AbstractQuantifierPredicate<T> {
|
||||||
public boolean test(final T object) {
|
public boolean test(final T object) {
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
for (final Predicate<? super T> iPredicate : iPredicates) {
|
for (final Predicate<? super T> iPredicate : iPredicates) {
|
||||||
if (iPredicate.evaluate(object)) {
|
if (iPredicate.test(object)) {
|
||||||
if (match) {
|
if (match) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,10 @@ import org.apache.commons.collections4.Predicate;
|
||||||
/**
|
/**
|
||||||
* Predicate implementation that returns true if either of the predicates return true.
|
* Predicate implementation that returns true if either of the predicates return true.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public final class OrPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class OrPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -8791518325735182855L;
|
private static final long serialVersionUID = -8791518325735182855L;
|
||||||
|
@ -70,8 +71,8 @@ public final class OrPredicate<T> implements PredicateDecorator<T>, Serializable
|
||||||
* @return true if either decorated predicate returns true
|
* @return true if either decorated predicate returns true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
return iPredicate1.evaluate(object) || iPredicate2.evaluate(object);
|
return iPredicate1.test(object) || iPredicate2.test(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class PredicateTransformer<T> implements Transformer<T, Boolean>, Seriali
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean transform(final T input) {
|
public Boolean transform(final T input) {
|
||||||
return Boolean.valueOf(iPredicate.evaluate(input));
|
return Boolean.valueOf(iPredicate.test(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class SwitchClosure<E> implements Closure<E>, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public void execute(final E input) {
|
public void execute(final E input) {
|
||||||
for (int i = 0; i < iPredicates.length; i++) {
|
for (int i = 0; i < iPredicates.length; i++) {
|
||||||
if (iPredicates[i].evaluate(input)) {
|
if (iPredicates[i].test(input)) {
|
||||||
iClosures[i].accept(input);
|
iClosures[i].accept(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class SwitchTransformer<I, O> implements Transformer<I, O>, Serializable
|
||||||
@Override
|
@Override
|
||||||
public O transform(final I input) {
|
public O transform(final I input) {
|
||||||
for (int i = 0; i < iPredicates.length; i++) {
|
for (int i = 0; i < iPredicates.length; i++) {
|
||||||
if (iPredicates[i].evaluate(input)) {
|
if (iPredicates[i].test(input)) {
|
||||||
return iTransformers[i].transform(input);
|
return iTransformers[i].transform(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,10 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* Predicate implementation that transforms the given object before invoking
|
* Predicate implementation that transforms the given object before invoking
|
||||||
* another {@code Predicate}.
|
* another {@code Predicate}.
|
||||||
*
|
*
|
||||||
|
* @param <T> the type of the input to the predicate.
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public final class TransformedPredicate<T> implements PredicateDecorator<T>, Serializable {
|
public final class TransformedPredicate<T> extends AbstractPredicate<T> implements PredicateDecorator<T>, Serializable {
|
||||||
|
|
||||||
/** Serial version UID */
|
/** Serial version UID */
|
||||||
private static final long serialVersionUID = -5596090919668315834L;
|
private static final long serialVersionUID = -5596090919668315834L;
|
||||||
|
@ -75,9 +76,9 @@ public final class TransformedPredicate<T> implements PredicateDecorator<T>, Ser
|
||||||
* @return true if decorated predicate returns true
|
* @return true if decorated predicate returns true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final T object) {
|
public boolean test(final T object) {
|
||||||
final T result = iTransformer.transform(object);
|
final T result = iTransformer.transform(object);
|
||||||
return iPredicate.evaluate(result);
|
return iPredicate.test(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class WhileClosure<E> implements Closure<E> {
|
||||||
if (iDoLoop) {
|
if (iDoLoop) {
|
||||||
iClosure.accept(input);
|
iClosure.accept(input);
|
||||||
}
|
}
|
||||||
while (iPredicate.evaluate(input)) {
|
while (iPredicate.test(input)) {
|
||||||
iClosure.accept(input);
|
iClosure.accept(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class FilterIterator<E> implements Iterator<E> {
|
||||||
private boolean setNextObject() {
|
private boolean setNextObject() {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E object = iterator.next();
|
final E object = iterator.next();
|
||||||
if (predicate.evaluate(object)) {
|
if (predicate.test(object)) {
|
||||||
nextObject = object;
|
nextObject = object;
|
||||||
nextObjectSet = true;
|
nextObjectSet = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -229,7 +229,7 @@ public class FilterListIterator<E> implements ListIterator<E> {
|
||||||
}
|
}
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final E object = iterator.next();
|
final E object = iterator.next();
|
||||||
if (predicate.evaluate(object)) {
|
if (predicate.test(object)) {
|
||||||
nextObject = object;
|
nextObject = object;
|
||||||
nextObjectSet = true;
|
nextObjectSet = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -265,7 +265,7 @@ public class FilterListIterator<E> implements ListIterator<E> {
|
||||||
}
|
}
|
||||||
while (iterator.hasPrevious()) {
|
while (iterator.hasPrevious()) {
|
||||||
final E object = iterator.previous();
|
final E object = iterator.previous();
|
||||||
if (predicate.evaluate(object)) {
|
if (predicate.test(object)) {
|
||||||
previousObject = object;
|
previousObject = object;
|
||||||
previousObjectSet = true;
|
previousObjectSet = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class PredicatedMap<K, V>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected V checkSetValue(final V value) {
|
protected V checkSetValue(final V value) {
|
||||||
if (!valuePredicate.evaluate(value)) {
|
if (!valuePredicate.test(value)) {
|
||||||
throw new IllegalArgumentException("Cannot set value - Predicate rejected it");
|
throw new IllegalArgumentException("Cannot set value - Predicate rejected it");
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -164,10 +164,10 @@ public class PredicatedMap<K, V>
|
||||||
* @throws IllegalArgumentException if invalid
|
* @throws IllegalArgumentException if invalid
|
||||||
*/
|
*/
|
||||||
protected void validate(final K key, final V value) {
|
protected void validate(final K key, final V value) {
|
||||||
if (keyPredicate != null && !keyPredicate.evaluate(key)) {
|
if (keyPredicate != null && !keyPredicate.test(key)) {
|
||||||
throw new IllegalArgumentException("Cannot add key - Predicate rejected it");
|
throw new IllegalArgumentException("Cannot add key - Predicate rejected it");
|
||||||
}
|
}
|
||||||
if (valuePredicate != null && !valuePredicate.evaluate(value)) {
|
if (valuePredicate != null && !valuePredicate.test(value)) {
|
||||||
throw new IllegalArgumentException("Cannot add value - Predicate rejected it");
|
throw new IllegalArgumentException("Cannot add value - Predicate rejected it");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public abstract class AbstractMockPredicateTest<T> {
|
||||||
protected final Predicate<T> createMockPredicate(final Boolean returnValue) {
|
protected final Predicate<T> createMockPredicate(final Boolean returnValue) {
|
||||||
final Predicate<T> mockPredicate = EasyMock.createMock(Predicate.class);
|
final Predicate<T> mockPredicate = EasyMock.createMock(Predicate.class);
|
||||||
if (returnValue != null) {
|
if (returnValue != null) {
|
||||||
EasyMock.expect(mockPredicate.evaluate(testValue)).andReturn(returnValue);
|
EasyMock.expect(mockPredicate.test(testValue)).andReturn(returnValue);
|
||||||
}
|
}
|
||||||
replay(mockPredicate);
|
replay(mockPredicate);
|
||||||
mockPredicatesToVerify.add(mockPredicate);
|
mockPredicatesToVerify.add(mockPredicate);
|
||||||
|
|
|
@ -80,8 +80,7 @@ public class AllPredicateTest extends AbstractAnyAllOnePredicateTest<Integer> {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyCollectionToGetInstance() {
|
public void testEmptyCollectionToGetInstance() {
|
||||||
final Predicate<Integer> allPredicate = getPredicateInstance(
|
final Predicate<Integer> allPredicate = getPredicateInstance(Collections.<Predicate<Integer>>emptyList());
|
||||||
Collections.<Predicate<Integer>>emptyList());
|
|
||||||
assertTrue(allPredicate.evaluate(getTestValue()), "empty collection not true");
|
assertTrue(allPredicate.evaluate(getTestValue()), "empty collection not true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +93,7 @@ public class AllPredicateTest extends AbstractAnyAllOnePredicateTest<Integer> {
|
||||||
// use the constructor directly, as getInstance() returns the original predicate when passed
|
// use the constructor directly, as getInstance() returns the original predicate when passed
|
||||||
// an array of size one.
|
// an array of size one.
|
||||||
final Predicate<Integer> predicate = createMockPredicate(false);
|
final Predicate<Integer> predicate = createMockPredicate(false);
|
||||||
assertFalse(allPredicate(predicate).evaluate(getTestValue()),
|
assertFalse(allPredicate(predicate).test(getTestValue()), "single false predicate evaluated to true");
|
||||||
"single false predicate evaluated to true");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,8 +105,7 @@ public class AllPredicateTest extends AbstractAnyAllOnePredicateTest<Integer> {
|
||||||
// use the constructor directly, as getInstance() returns the original predicate when passed
|
// use the constructor directly, as getInstance() returns the original predicate when passed
|
||||||
// an array of size one.
|
// an array of size one.
|
||||||
final Predicate<Integer> predicate = createMockPredicate(true);
|
final Predicate<Integer> predicate = createMockPredicate(true);
|
||||||
|
assertTrue(allPredicate(predicate).test(getTestValue()), "single true predicate evaluated to false");
|
||||||
assertTrue(allPredicate(predicate).evaluate(getTestValue()), "single true predicate evaluated to false");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue