You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/07/10 14:55:06 UTC
(commons-collections) 02/03: Migrate toward java.util.function.Predicate
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit d5dd6e446864022acf7d65970ae16beb272d8fd8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jul 10 09:11:34 2024 -0400
Migrate toward java.util.function.Predicate
Maintains binary and source compatibility
---
.../collections4/functors/AbstractPredicate.java | 33 ++++++++++++++++++++++
.../collections4/functors/ComparatorPredicate.java | 4 +--
.../collections4/functors/EqualPredicate.java | 4 +--
.../collections4/functors/ExceptionPredicate.java | 4 +--
.../collections4/functors/FalsePredicate.java | 4 +--
.../collections4/functors/IdentityPredicate.java | 4 +--
.../collections4/functors/InstanceofPredicate.java | 4 +--
.../collections4/functors/NotNullPredicate.java | 4 +--
.../collections4/functors/NullPredicate.java | 4 +--
.../functors/TransformerPredicate.java | 4 +--
.../collections4/functors/TruePredicate.java | 4 +--
.../collections4/functors/UniquePredicate.java | 4 +--
12 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java
new file mode 100644
index 000000000..572ef16f5
--- /dev/null
+++ b/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.functors;
+
+import org.apache.commons.collections4.Predicate;
+
+/**
+ * Abstract base class for predicates.
+ *
+ * @param <T> the type of the input to the predicate.
+ * @since 4.5.0
+ */
+public abstract class AbstractPredicate<T> implements Predicate<T> {
+
+ @Override
+ public boolean evaluate(final T object) {
+ return test(object);
+ }
+}
diff --git a/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java b/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java
index 265a967fa..0efc3bebf 100644
--- a/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java
@@ -77,7 +77,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 4.0
*/
-public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
+public class ComparatorPredicate<T> extends AbstractPredicate<T> implements Serializable {
public enum Criterion {
EQUAL, GREATER, LESS, GREATER_OR_EQUAL, LESS_OR_EQUAL,
@@ -158,7 +158,7 @@ public class ComparatorPredicate<T> implements Predicate<T>, Serializable {
* @throws IllegalStateException if the criterion is invalid (really not possible)
*/
@Override
- public boolean evaluate(final T target) {
+ public boolean test(final T target) {
boolean result = false;
final int comparison = comparator.compare(object, target);
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 260398a29..827fde15b 100644
--- a/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java
@@ -28,7 +28,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class EqualPredicate<T> implements Predicate<T>, Serializable {
+public final class EqualPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 5633766978029907089L;
@@ -101,7 +101,7 @@ public final class EqualPredicate<T> implements Predicate<T>, Serializable {
* @return true if input object equals stored value
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
if (equator != null) {
return equator.equate(iValue, object);
}
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 bf46f60ea..e58ec9af5 100644
--- a/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/ExceptionPredicate.java
@@ -27,7 +27,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class ExceptionPredicate<T> implements Predicate<T>, Serializable {
+public final class ExceptionPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 7179106032121985545L;
@@ -61,7 +61,7 @@ public final class ExceptionPredicate<T> implements Predicate<T>, Serializable {
* @throws FunctorException always
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
throw new FunctorException("ExceptionPredicate invoked");
}
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 184234c6b..e5896c73d 100644
--- a/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/FalsePredicate.java
@@ -26,7 +26,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class FalsePredicate<T> implements Predicate<T>, Serializable {
+public final class FalsePredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 7533784454832764388L;
@@ -59,7 +59,7 @@ public final class FalsePredicate<T> implements Predicate<T>, Serializable {
* @return false always
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return false;
}
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 74ef13ad7..f58cd65d7 100644
--- a/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/IdentityPredicate.java
@@ -27,7 +27,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
+public final class IdentityPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = -89901658494523293L;
@@ -67,7 +67,7 @@ public final class IdentityPredicate<T> implements Predicate<T>, Serializable {
* @return true if input is the same object as the stored value
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return iValue == object;
}
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 6cc591582..149d7d4b9 100644
--- a/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/InstanceofPredicate.java
@@ -27,7 +27,7 @@ import org.apache.commons.collections4.Predicate;
*
* @since 3.0
*/
-public final class InstanceofPredicate implements Predicate<Object>, Serializable {
+public final class InstanceofPredicate extends AbstractPredicate<Object> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = -6682656911025165584L;
@@ -63,7 +63,7 @@ public final class InstanceofPredicate implements Predicate<Object>, Serializabl
* @return true if input is of stored type
*/
@Override
- public boolean evaluate(final Object object) {
+ public boolean test(final Object object) {
return iType.isInstance(object);
}
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 6913cfdb4..d2dc9e2f6 100644
--- a/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/NotNullPredicate.java
@@ -26,7 +26,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class NotNullPredicate<T> implements Predicate<T>, Serializable {
+public final class NotNullPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 7533784454832764388L;
@@ -59,7 +59,7 @@ public final class NotNullPredicate<T> implements Predicate<T>, Serializable {
* @return true if not null
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return object != null;
}
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 93820fc54..645fd811b 100644
--- a/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/NullPredicate.java
@@ -26,7 +26,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class NullPredicate<T> implements Predicate<T>, Serializable {
+public final class NullPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 7533784454832764388L;
@@ -59,7 +59,7 @@ public final class NullPredicate<T> implements Predicate<T>, Serializable {
* @return true if input is null
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return object == null;
}
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 80d61934b..ff5c796d9 100644
--- a/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/TransformerPredicate.java
@@ -29,7 +29,7 @@ import org.apache.commons.collections4.Transformer;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class TransformerPredicate<T> implements Predicate<T>, Serializable {
+public final class TransformerPredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = -2407966402920578741L;
@@ -67,7 +67,7 @@ public final class TransformerPredicate<T> implements Predicate<T>, Serializable
* @throws FunctorException if the transformer returns an invalid type
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
final Boolean result = iTransformer.transform(object);
if (result == null) {
throw new FunctorException(
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 ef1dd6a94..d2c3cdfa4 100644
--- a/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/TruePredicate.java
@@ -26,7 +26,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class TruePredicate<T> implements Predicate<T>, Serializable {
+public final class TruePredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = 3374767158756189740L;
@@ -59,7 +59,7 @@ public final class TruePredicate<T> implements Predicate<T>, Serializable {
* @return true always
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return true;
}
diff --git a/src/main/java/org/apache/commons/collections4/functors/UniquePredicate.java b/src/main/java/org/apache/commons/collections4/functors/UniquePredicate.java
index a8b348914..a91f4537e 100644
--- a/src/main/java/org/apache/commons/collections4/functors/UniquePredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/UniquePredicate.java
@@ -29,7 +29,7 @@ import org.apache.commons.collections4.Predicate;
* @param <T> the type of the input to the predicate.
* @since 3.0
*/
-public final class UniquePredicate<T> implements Predicate<T>, Serializable {
+public final class UniquePredicate<T> extends AbstractPredicate<T> implements Serializable {
/** Serial version UID */
private static final long serialVersionUID = -3319417438027438040L;
@@ -63,7 +63,7 @@ public final class UniquePredicate<T> implements Predicate<T>, Serializable {
* @return true if this is the first time the object is seen
*/
@Override
- public boolean evaluate(final T object) {
+ public boolean test(final T object) {
return iSet.add(object);
}