From f17fbd5033af65b3be782b62f58dbc1353556dd2 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Sun, 28 Apr 2024 09:48:40 -0400
Subject: [PATCH] Deprecate Transformer in favor of java.util.function.Function
---
src/changes/changes.xml | 1 +
.../commons/collections4/Transformer.java | 18 +++++++++++++-----
.../comparators/FixedOrderComparator.java | 2 +-
.../commons/collections4/ClosureUtilsTest.java | 2 +-
.../commons/collections4/FactoryUtilsTest.java | 2 +-
.../collections4/PredicateUtilsTest.java | 6 +++---
.../collections4/TransformerUtilsTest.java | 4 +++-
7 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a7f38449a..8e0f434f2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -29,6 +29,7 @@
Deprecate Closure in favor of java.util.function.Consumer.Deprecate Factory in favor of java.util.function.Supplier.Deprecate Predicate in favor of java.util.function.Predicate.
+ Deprecate Transformer in favor of java.util.function.Function.Bump org.apache.commons:commons-parent from 67 to 69 #473.Bump tests commons-io:commons-io from 2.16.0 to 2.16.1 #475 .
diff --git a/src/main/java/org/apache/commons/collections4/Transformer.java b/src/main/java/org/apache/commons/collections4/Transformer.java
index cdf2ab9eb..5bf322361 100644
--- a/src/main/java/org/apache/commons/collections4/Transformer.java
+++ b/src/main/java/org/apache/commons/collections4/Transformer.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4;
+import java.util.function.Function;
+
/**
* Defines a functor interface implemented by classes that transform one
* object into another.
@@ -31,13 +33,19 @@ package org.apache.commons.collections4;
* cloning and returning the string value.
*
*
- * @param the input type to the transformer
- * @param the output type from the transformer
+ * @param the input type to the transformer
+ * @param the output type from the transformer
*
* @since 1.0
+ * @deprecated Use {@link Function}.
*/
-@FunctionalInterface
-public interface Transformer {
+@Deprecated
+public interface Transformer extends Function {
+
+ @Override
+ default R apply(final T t) {
+ return transform(t);
+ }
/**
* Transforms the input object (leaving it unchanged) into some output object.
@@ -48,6 +56,6 @@ public interface Transformer {
* @throws IllegalArgumentException (runtime) if the input is invalid
* @throws FunctorException (runtime) if the transform cannot be completed
*/
- O transform(I input);
+ R transform(T input);
}
diff --git a/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java b/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
index 7c00ac38b..c7b44a105 100644
--- a/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
+++ b/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
@@ -212,7 +212,7 @@ public class FixedOrderComparator implements Comparator, Serializable {
if (getClass() != obj.getClass()) {
return false;
}
- FixedOrderComparator other = (FixedOrderComparator) obj;
+ FixedOrderComparator> other = (FixedOrderComparator>) obj;
return counter == other.counter && isLocked == other.isLocked && Objects.equals(map, other.map) && unknownObjectBehavior == other.unknownObjectBehavior;
}
diff --git a/src/test/java/org/apache/commons/collections4/ClosureUtilsTest.java b/src/test/java/org/apache/commons/collections4/ClosureUtilsTest.java
index 0e607d063..40613717a 100644
--- a/src/test/java/org/apache/commons/collections4/ClosureUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/ClosureUtilsTest.java
@@ -70,7 +70,7 @@ public class ClosureUtilsTest {
public void testChainedClosure() {
MockClosure