diff --git a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java index 402fda89f1..b23d9109ab 100644 --- a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java @@ -64,17 +64,6 @@ public AndPredicate(final Predicate predicate1, final Predicate[] getPredicates() { return new Predicate[] {iPredicate1, iPredicate2}; } + /** + * Evaluates the predicate returning true if both predicates return true. + * + * @param object the input object + * @return true if both decorated predicates return true + */ + @Override + public boolean test(final T object) { + return iPredicate1.test(object) && iPredicate2.test(object); + } + } diff --git a/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java b/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java index 827fde15bd..2d1a835bdb 100644 --- a/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java @@ -94,6 +94,16 @@ public EqualPredicate(final T object, final Equator equator) { this.equator = equator; } + /** + * Gets the value. + * + * @return the value + * @since 3.1 + */ + public Object getValue() { + return iValue; + } + /** * Evaluates the predicate returning true if the input equals the stored value. * @@ -108,14 +118,4 @@ public boolean test(final T object) { return iValue.equals(object); } - /** - * Gets the value. - * - * @return the value - * @since 3.1 - */ - public Object getValue() { - return iValue; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java b/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java index e58ec9af52..e0c4e459b7 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java @@ -53,6 +53,15 @@ public static Predicate exceptionPredicate() { private ExceptionPredicate() { } + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + private Object readResolve() { + return INSTANCE; + } + /** * Evaluates the predicate always throwing an exception. * @@ -65,13 +74,4 @@ public boolean test(final T object) { throw new FunctorException("ExceptionPredicate invoked"); } - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - private Object readResolve() { - return INSTANCE; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java b/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java index e5896c73d1..8cf0f4b452 100644 --- a/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java @@ -52,6 +52,15 @@ public static Predicate falsePredicate() { private FalsePredicate() { } + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + private Object readResolve() { + return INSTANCE; + } + /** * Evaluates the predicate returning false always. * @@ -63,13 +72,4 @@ public boolean test(final T object) { return false; } - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - private Object readResolve() { - return INSTANCE; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java b/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java index 7f23d56643..b696d010fc 100644 --- a/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java +++ b/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java @@ -107,20 +107,6 @@ static > T[] copy(final T... predicate return transformers.clone(); } - /** - * Validates the consumers to ensure that all is well. - * - * @param consumers the consumers to validate. - */ - static void validate(final Consumer... consumers) { - Objects.requireNonNull(consumers, "closures"); - for (int i = 0; i < consumers.length; i++) { - if (consumers[i] == null) { - throw new NullPointerException("closures[" + i + "]"); - } - } - } - /** * Validate the predicates to ensure that all is well. * @@ -144,15 +130,15 @@ static Predicate[] validate(final Collection... predicates) { - Objects.requireNonNull(predicates, "predicates"); - for (int i = 0; i < predicates.length; i++) { - if (predicates[i] == null) { - throw new NullPointerException("predicates[" + i + "]"); + static void validate(final Consumer... consumers) { + Objects.requireNonNull(consumers, "closures"); + for (int i = 0; i < consumers.length; i++) { + if (consumers[i] == null) { + throw new NullPointerException("closures[" + i + "]"); } } } @@ -171,6 +157,20 @@ static void validate(final Function... functions) { } } + /** + * Validate the predicates to ensure that all is well. + * + * @param predicates the predicates to validate + */ + static void validate(final java.util.function.Predicate... predicates) { + Objects.requireNonNull(predicates, "predicates"); + for (int i = 0; i < predicates.length; i++) { + if (predicates[i] == null) { + throw new NullPointerException("predicates[" + i + "]"); + } + } + } + /** * Restricted constructor. */ diff --git a/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java b/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java index f58cd65d75..79ffc35bcd 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java @@ -59,6 +59,16 @@ public IdentityPredicate(final T object) { iValue = object; } + /** + * Gets the value. + * + * @return the value + * @since 3.1 + */ + public T getValue() { + return iValue; + } + /** * Evaluates the predicate returning true if the input object is identical to * the stored object. @@ -71,14 +81,4 @@ public boolean test(final T object) { return iValue == object; } - /** - * Gets the value. - * - * @return the value - * @since 3.1 - */ - public T getValue() { - return iValue; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java b/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java index 149d7d4b9a..3692ff900d 100644 --- a/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java @@ -56,6 +56,16 @@ public InstanceofPredicate(final Class type) { iType = type; } + /** + * Gets the type to compare to. + * + * @return the type + * @since 3.1 + */ + public Class getType() { + return iType; + } + /** * Evaluates the predicate returning true if the input object is of the correct type. * @@ -67,14 +77,4 @@ public boolean test(final Object object) { return iType.isInstance(object); } - /** - * Gets the type to compare to. - * - * @return the type - * @since 3.1 - */ - public Class getType() { - return iType; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java index d2dc9e2f64..dc9d4e6333 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java @@ -52,6 +52,15 @@ public static Predicate notNullPredicate() { private NotNullPredicate() { } + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + private Object readResolve() { + return INSTANCE; + } + /** * Evaluates the predicate returning true if the object does not equal null. * @@ -63,13 +72,4 @@ public boolean test(final T object) { return object != null; } - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - private Object readResolve() { - return INSTANCE; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java index 987bbd4768..344c4162b9 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java @@ -57,17 +57,6 @@ public NotPredicate(final Predicate predicate) { iPredicate = predicate; } - /** - * Evaluates the predicate returning the opposite to the stored predicate. - * - * @param object the input object - * @return true if predicate returns false - */ - @Override - public boolean test(final T object) { - return !iPredicate.test(object); - } - /** * Gets the predicate being decorated. * @@ -80,4 +69,15 @@ public Predicate[] getPredicates() { return new Predicate[] {iPredicate}; } + /** + * Evaluates the predicate returning the opposite to the stored predicate. + * + * @param object the input object + * @return true if predicate returns false + */ + @Override + public boolean test(final T object) { + return !iPredicate.test(object); + } + } diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java index 4b31140bd2..84a20ab0cc 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java @@ -58,6 +58,18 @@ public NullIsExceptionPredicate(final Predicate predicate) { iPredicate = predicate; } + /** + * Gets the predicate being decorated. + * + * @return the predicate as the only element in an array + * @since 3.1 + */ + @Override + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; + } + /** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. @@ -74,16 +86,4 @@ public boolean test(final T object) { return iPredicate.test(object); } - /** - * Gets the predicate being decorated. - * - * @return the predicate as the only element in an array - * @since 3.1 - */ - @Override - @SuppressWarnings("unchecked") - public Predicate[] getPredicates() { - return new Predicate[] { iPredicate }; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java index b70b1b93f1..f4b6bf037f 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java @@ -57,6 +57,18 @@ public NullIsFalsePredicate(final Predicate predicate) { iPredicate = predicate; } + /** + * Gets the predicate being decorated. + * + * @return the predicate as the only element in an array + * @since 3.1 + */ + @Override + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; + } + /** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. @@ -72,16 +84,4 @@ public boolean test(final T object) { return iPredicate.test(object); } - /** - * Gets the predicate being decorated. - * - * @return the predicate as the only element in an array - * @since 3.1 - */ - @Override - @SuppressWarnings("unchecked") - public Predicate[] getPredicates() { - return new Predicate[] { iPredicate }; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java index 2dc0a107f5..556d0d6fbe 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java @@ -57,6 +57,18 @@ public NullIsTruePredicate(final Predicate predicate) { iPredicate = predicate; } + /** + * Gets the predicate being decorated. + * + * @return the predicate as the only element in an array + * @since 3.1 + */ + @Override + @SuppressWarnings("unchecked") + public Predicate[] getPredicates() { + return new Predicate[] { iPredicate }; + } + /** * Evaluates the predicate returning the result of the decorated predicate * once a null check is performed. @@ -72,16 +84,4 @@ public boolean test(final T object) { return iPredicate.test(object); } - /** - * Gets the predicate being decorated. - * - * @return the predicate as the only element in an array - * @since 3.1 - */ - @Override - @SuppressWarnings("unchecked") - public Predicate[] getPredicates() { - return new Predicate[] { iPredicate }; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java index 645fd811b5..70f6b529da 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java @@ -52,6 +52,15 @@ public static Predicate nullPredicate() { private NullPredicate() { } + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + private Object readResolve() { + return INSTANCE; + } + /** * Evaluates the predicate returning true if the input is null. * @@ -63,13 +72,4 @@ public boolean test(final T object) { return object == null; } - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - private Object readResolve() { - return INSTANCE; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java index cdd027aac9..a6f69c2ced 100644 --- a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java @@ -64,17 +64,6 @@ public OrPredicate(final Predicate predicate1, final Predicate[] getPredicates() { return new Predicate[] {iPredicate1, iPredicate2}; } + /** + * Evaluates the predicate returning true if either predicate returns true. + * + * @param object the input object + * @return true if either decorated predicate returns true + */ + @Override + public boolean test(final T object) { + return iPredicate1.test(object) || iPredicate2.test(object); + } + } diff --git a/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java b/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java index 7b19ce342e..8269da30f5 100644 --- a/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java @@ -68,19 +68,6 @@ public TransformedPredicate(final Transformer transforme iPredicate = predicate; } - /** - * Evaluates the predicate returning the result of the decorated predicate - * once the input has been transformed - * - * @param object the input object which will be transformed - * @return true if decorated predicate returns true - */ - @Override - public boolean test(final T object) { - final T result = iTransformer.apply(object); - return iPredicate.test(result); - } - /** * Gets the predicate being decorated. * @@ -102,4 +89,17 @@ public Predicate[] getPredicates() { return iTransformer; } + /** + * Evaluates the predicate returning the result of the decorated predicate + * once the input has been transformed + * + * @param object the input object which will be transformed + * @return true if decorated predicate returns true + */ + @Override + public boolean test(final T object) { + final T result = iTransformer.apply(object); + return iPredicate.test(result); + } + } diff --git a/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java b/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java index e40b014d77..b34fada5c3 100644 --- a/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java @@ -59,6 +59,16 @@ public TransformerPredicate(final Transformer transformer) { iTransformer = transformer; } + /** + * Gets the transformer. + * + * @return the transformer + * @since 3.1 + */ + public Transformer getTransformer() { + return iTransformer; + } + /** * Evaluates the predicate returning the result of the decorated transformer. * @@ -76,14 +86,4 @@ public boolean test(final T object) { return result.booleanValue(); } - /** - * Gets the transformer. - * - * @return the transformer - * @since 3.1 - */ - public Transformer getTransformer() { - return iTransformer; - } - } diff --git a/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java b/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java index d2c3cdfa4a..b333ea050f 100644 --- a/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java @@ -52,6 +52,15 @@ public static Predicate truePredicate() { private TruePredicate() { } + /** + * Returns the singleton instance. + * + * @return the singleton instance. + */ + private Object readResolve() { + return INSTANCE; + } + /** * Evaluates the predicate returning true always. * @@ -63,13 +72,4 @@ public boolean test(final T object) { return true; } - /** - * Returns the singleton instance. - * - * @return the singleton instance. - */ - private Object readResolve() { - return INSTANCE; - } - }