Deprecate Transformer in favor of java.util.function.Function
This commit is contained in:
parent
c208c4adde
commit
f17fbd5033
|
@ -29,6 +29,7 @@
|
|||
<action type="update" dev="ggregory" due-to="Gary Gregory">Deprecate Closure in favor of java.util.function.Consumer.</action>
|
||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Deprecate Factory in favor of java.util.function.Supplier.</action>
|
||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Deprecate Predicate in favor of java.util.function.Predicate.</action>
|
||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Deprecate Transformer in favor of java.util.function.Function.</action>
|
||||
<!-- UPDATE -->
|
||||
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.apache.commons:commons-parent from 67 to 69 #473.</action>
|
||||
<action type="update" dev="ggregory" due-to="Dependabot">Bump tests commons-io:commons-io from 2.16.0 to 2.16.1 #475 .</action>
|
||||
|
|
|
@ -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.
|
||||
* </p>
|
||||
*
|
||||
* @param <I> the input type to the transformer
|
||||
* @param <O> the output type from the transformer
|
||||
* @param <T> the input type to the transformer
|
||||
* @param <R> the output type from the transformer
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated Use {@link Function}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Transformer<I, O> {
|
||||
@Deprecated
|
||||
public interface Transformer<T, R> extends Function<T, R> {
|
||||
|
||||
@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<I, O> {
|
|||
* @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);
|
||||
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ClosureUtilsTest {
|
|||
public void testChainedClosure() {
|
||||
MockClosure<Object> a = new MockClosure<>();
|
||||
MockClosure<Object> b = new MockClosure<>();
|
||||
ClosureUtils.chainedClosure(a, b).execute(null);
|
||||
ClosureUtils.chainedClosure(a, b).accept(null);
|
||||
assertEquals(1, a.count);
|
||||
assertEquals(1, b.count);
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ public class FactoryUtilsTest {
|
|||
public void testInstantiateFactorySimple() {
|
||||
final Factory<Mock3> 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());
|
||||
|
|
|
@ -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<Predicate<Object>> coll = new ArrayList<>();
|
||||
coll.add(TruePredicate.truePredicate());
|
||||
|
|
|
@ -55,7 +55,9 @@ public class TransformerUtilsTest {
|
|||
public void testChainedTransformer() {
|
||||
final Transformer<Object, Object> a = TransformerUtils.<Object, Object>constantTransformer("A");
|
||||
final Transformer<Object, Object> 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));
|
||||
|
|
Loading…
Reference in New Issue