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 a = new MockClosure<>(); MockClosure b = new MockClosure<>(); - ClosureUtils.chainedClosure(a, b).execute(null); + ClosureUtils.chainedClosure(a, b).accept(null); assertEquals(1, a.count); assertEquals(1, b.count); diff --git a/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java b/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java index d33c8c180..e05d3f353 100644 --- a/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java @@ -149,7 +149,7 @@ public class FactoryUtilsTest { public void testInstantiateFactorySimple() { final Factory factory = FactoryUtils.instantiateFactory(Mock3.class); assertNotNull(factory); - Mock3 created = factory.create(); + Mock3 created = factory.get(); assertEquals(0, created.getValue()); created = factory.create(); assertEquals(1, created.getValue()); diff --git a/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java b/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java index 29be30368..f6f1d1d4d 100644 --- a/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java @@ -57,9 +57,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @SuppressWarnings("unchecked") public void testAllPredicate() { assertPredicateTrue(AllPredicate.allPredicate(), null); - assertTrue(AllPredicate.allPredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null)); - assertFalse(AllPredicate.allPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); - assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertTrue(AllPredicate.allPredicate(truePredicate(), truePredicate(), truePredicate()).test(null)); + assertFalse(AllPredicate.allPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).test(null)); + assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).test(null)); assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); final Collection> coll = new ArrayList<>(); coll.add(TruePredicate.truePredicate()); diff --git a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java index 42ff8ffdf..69a20c1e7 100644 --- a/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/TransformerUtilsTest.java @@ -55,7 +55,9 @@ public class TransformerUtilsTest { public void testChainedTransformer() { final Transformer a = TransformerUtils.constantTransformer("A"); final Transformer b = TransformerUtils.constantTransformer((Object) "B"); - + assertEquals("A", TransformerUtils.chainedTransformer(b, a).apply(null)); + assertEquals("B", TransformerUtils.chainedTransformer(a, b).apply(null)); + assertEquals("A", TransformerUtils.chainedTransformer(b, a).apply(null)); assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null)); assertEquals("B", TransformerUtils.chainedTransformer(a, b).transform(null)); assertEquals("A", TransformerUtils.chainedTransformer(b, a).transform(null));