[FUNCTOR-24] Change default arity of Function, Procedure and Predicate
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/functor/trunk@1508677 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/api/src/main/java/org/apache/commons/functor/Function.java b/api/src/main/java/org/apache/commons/functor/Function.java
index 89e03b2..c1db775 100644
--- a/api/src/main/java/org/apache/commons/functor/Function.java
+++ b/api/src/main/java/org/apache/commons/functor/Function.java
@@ -17,20 +17,23 @@
package org.apache.commons.functor;
/**
- * A functor that takes no arguments and returns a value.
+ * A functor that takes one argument and returns an <code>Object</code> value.
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
+ * @param <A> the argument type.
* @param <T> the returned value type.
* @since 1.0
* @version $Revision$ $Date$
*/
-public interface Function<T> extends NullaryFunctor {
+public interface Function<A, T> extends UnaryFunctor<A> {
/**
* Evaluate this function.
+ *
+ * @param obj the A object to evaluate
* @return the T result of this evaluation
*/
- T evaluate();
+ T evaluate(A obj);
}
diff --git a/api/src/main/java/org/apache/commons/functor/UnaryFunction.java b/api/src/main/java/org/apache/commons/functor/NullaryFunction.java
similarity index 80%
rename from api/src/main/java/org/apache/commons/functor/UnaryFunction.java
rename to api/src/main/java/org/apache/commons/functor/NullaryFunction.java
index 41647ff..b567ba8 100644
--- a/api/src/main/java/org/apache/commons/functor/UnaryFunction.java
+++ b/api/src/main/java/org/apache/commons/functor/NullaryFunction.java
@@ -17,23 +17,20 @@
package org.apache.commons.functor;
/**
- * A functor that takes one argument and returns an <code>Object</code> value.
+ * A functor that takes no arguments and returns a value.
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
- * @param <A> the argument type.
* @param <T> the returned value type.
* @since 1.0
- * @version $Revision$ $Date$
+ * @version $Revision: 1438784 $ $Date: 2013-01-25 22:09:13 -0200 (Fri, 25 Jan 2013) $
*/
-public interface UnaryFunction<A, T> extends UnaryFunctor<A> {
+public interface NullaryFunction<T> extends NullaryFunctor {
/**
* Evaluate this function.
- *
- * @param obj the A object to evaluate
* @return the T result of this evaluation
*/
- T evaluate(A obj);
+ T evaluate();
}
diff --git a/api/src/main/java/org/apache/commons/functor/UnaryPredicate.java b/api/src/main/java/org/apache/commons/functor/NullaryPredicate.java
similarity index 81%
rename from api/src/main/java/org/apache/commons/functor/UnaryPredicate.java
rename to api/src/main/java/org/apache/commons/functor/NullaryPredicate.java
index 18d721e..045b5e1 100644
--- a/api/src/main/java/org/apache/commons/functor/UnaryPredicate.java
+++ b/api/src/main/java/org/apache/commons/functor/NullaryPredicate.java
@@ -17,22 +17,19 @@
package org.apache.commons.functor;
/**
- * A functor that takes one argument and returns a <code>boolean</code> value.
+ * A functor that takes no arguments and returns a <code>boolean</code> value.
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
- * @param <A> the argument type.
* @since 1.0
- * @version $Revision$ $Date$
+ * @version $Revision: 1438784 $ $Date: 2013-01-25 22:09:13 -0200 (Fri, 25 Jan 2013) $
*/
-public interface UnaryPredicate<A> extends UnaryFunctor<A> {
+public interface NullaryPredicate extends NullaryFunctor {
/**
* Evaluate this predicate.
- *
- * @param obj the A object to test
* @return the result of this test
*/
- boolean test(A obj);
+ boolean test();
}
diff --git a/api/src/main/java/org/apache/commons/functor/UnaryFunction.java b/api/src/main/java/org/apache/commons/functor/NullaryProcedure.java
similarity index 68%
copy from api/src/main/java/org/apache/commons/functor/UnaryFunction.java
copy to api/src/main/java/org/apache/commons/functor/NullaryProcedure.java
index 41647ff..c783450 100644
--- a/api/src/main/java/org/apache/commons/functor/UnaryFunction.java
+++ b/api/src/main/java/org/apache/commons/functor/NullaryProcedure.java
@@ -17,23 +17,22 @@
package org.apache.commons.functor;
/**
- * A functor that takes one argument and returns an <code>Object</code> value.
+ * A functor that takes no arguments and returns no value.
+ * <p>
+ * Note that this functor implements the
+ * {@link Runnable Runnable}
+ * interface, making all <code>Procedure</code>s
+ * immediately usable in a number of contexts (Swing, Jelly, etc.).
+ * </p>
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
- * @param <A> the argument type.
- * @param <T> the returned value type.
* @since 1.0
- * @version $Revision$ $Date$
+ * @version $Revision: 1438784 $ $Date: 2013-01-25 22:09:13 -0200 (Fri, 25 Jan 2013) $
*/
-public interface UnaryFunction<A, T> extends UnaryFunctor<A> {
- /**
- * Evaluate this function.
- *
- * @param obj the A object to evaluate
- * @return the T result of this evaluation
- */
- T evaluate(A obj);
+public interface NullaryProcedure extends NullaryFunctor, Runnable {
+ /** Execute this procedure. */
+ void run();
}
diff --git a/api/src/main/java/org/apache/commons/functor/Predicate.java b/api/src/main/java/org/apache/commons/functor/Predicate.java
index 8cbcdee..45ef446 100644
--- a/api/src/main/java/org/apache/commons/functor/Predicate.java
+++ b/api/src/main/java/org/apache/commons/functor/Predicate.java
@@ -17,19 +17,22 @@
package org.apache.commons.functor;
/**
- * A functor that takes no arguments and returns a <code>boolean</code> value.
+ * A functor that takes one argument and returns a <code>boolean</code> value.
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
+ * @param <A> the argument type.
* @since 1.0
* @version $Revision$ $Date$
*/
-public interface Predicate extends NullaryFunctor {
+public interface Predicate<A> extends UnaryFunctor<A> {
/**
* Evaluate this predicate.
+ *
+ * @param obj the A object to test
* @return the result of this test
*/
- boolean test();
+ boolean test(A obj);
}
diff --git a/api/src/main/java/org/apache/commons/functor/Procedure.java b/api/src/main/java/org/apache/commons/functor/Procedure.java
index ccfe109..167dcbb 100644
--- a/api/src/main/java/org/apache/commons/functor/Procedure.java
+++ b/api/src/main/java/org/apache/commons/functor/Procedure.java
@@ -17,22 +17,20 @@
package org.apache.commons.functor;
/**
- * A functor that takes no arguments and returns no value.
- * <p>
- * Note that this functor implements the
- * {@link Runnable Runnable}
- * interface, making all <code>Procedure</code>s
- * immediately usable in a number of contexts (Swing, Jelly, etc.).
- * </p>
+ * A functor that takes one argument and returns no value.
* <p>
* Implementors are encouraged but not required to make their functors
* {@link java.io.Serializable Serializable}.
* </p>
*
+ * @param <A> the argument type.
* @since 1.0
* @version $Revision$ $Date$
*/
-public interface Procedure extends NullaryFunctor, Runnable {
- /** Execute this procedure. */
- void run();
+public interface Procedure<A> extends UnaryFunctor<A> {
+ /**
+ * Execute this procedure.
+ * @param obj an A parameter to this execution
+ */
+ void run(A obj);
}
diff --git a/api/src/main/java/org/apache/commons/functor/UnaryProcedure.java b/api/src/main/java/org/apache/commons/functor/UnaryProcedure.java
deleted file mode 100644
index ef9e9de..0000000
--- a/api/src/main/java/org/apache/commons/functor/UnaryProcedure.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.functor;
-
-/**
- * A functor that takes one argument and returns no value.
- * <p>
- * Implementors are encouraged but not required to make their functors
- * {@link java.io.Serializable Serializable}.
- * </p>
- *
- * @param <A> the argument type.
- * @since 1.0
- * @version $Revision$ $Date$
- */
-public interface UnaryProcedure<A> extends UnaryFunctor<A> {
- /**
- * Execute this procedure.
- * @param obj an A parameter to this execution
- */
- void run(A obj);
-}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionFunction.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionFunction.java
index 2a72ebd..aea8d2c 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionUnaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BinaryFunctionFunction.java
@@ -17,27 +17,27 @@
package org.apache.commons.functor.adapter;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
- * Adapts a BinaryFunction as a UnaryFunction by sending the same argument to both sides of the BinaryFunction.
+ * Adapts a BinaryFunction as a Function by sending the same argument to both sides of the BinaryFunction.
* It sounds nonsensical, but using Composite functions, can be made to do something useful.
* @param <A> the argument type.
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class BinaryFunctionUnaryFunction<A, T> implements UnaryFunction<A, T> {
+public final class BinaryFunctionFunction<A, T> implements Function<A, T> {
/**
* The adapted function.
*/
private final BinaryFunction<? super A, ? super A, ? extends T> function;
/**
- * Create a new BinaryFunctionUnaryFunction.
+ * Create a new BinaryFunctionFunction.
* @param function to adapt
*/
- public BinaryFunctionUnaryFunction(BinaryFunction<? super A, ? super A, ? extends T> function) {
+ public BinaryFunctionFunction(BinaryFunction<? super A, ? super A, ? extends T> function) {
this.function = Validate.notNull(function, "BinaryFunction argument was null");
}
@@ -53,16 +53,16 @@
*/
@Override
public boolean equals(Object obj) {
- return obj == this || obj instanceof BinaryFunctionUnaryFunction<?, ?>
- && equals((BinaryFunctionUnaryFunction<?, ?>) obj);
+ return obj == this || obj instanceof BinaryFunctionFunction<?, ?>
+ && equals((BinaryFunctionFunction<?, ?>) obj);
}
/**
- * Learn whether another BinaryFunctionUnaryFunction is equal to <code>this</code>.
- * @param that BinaryFunctionUnaryFunction to check
+ * Learn whether another BinaryFunctionFunction is equal to <code>this</code>.
+ * @param that BinaryFunctionFunction to check
* @return whether equal
*/
- public boolean equals(BinaryFunctionUnaryFunction<?, ?> that) {
+ public boolean equals(BinaryFunctionFunction<?, ?> that) {
return that != null && that.function.equals(this.function);
}
@@ -71,7 +71,7 @@
*/
@Override
public int hashCode() {
- return ("BinaryFunctionUnaryFunction".hashCode() << 2) | function.hashCode();
+ return ("BinaryFunctionFunction".hashCode() << 2) | function.hashCode();
}
/**
@@ -79,18 +79,18 @@
*/
@Override
public String toString() {
- return "BinaryFunctionUnaryFunction<" + function + ">";
+ return "BinaryFunctionFunction<" + function + ">";
}
/**
- * Adapt a BinaryFunction as a UnaryFunction.
+ * Adapt a BinaryFunction as a Function.
* @param <A> input type
* @param <T> result type
* @param function to adapt
- * @return UnaryFunction<A, T>
+ * @return Function<A, T>
*/
- public static <A, T> UnaryFunction<A, T> adapt(BinaryFunction<? super A, ? super A, ? extends T> function) {
- return null == function ? null : new BinaryFunctionUnaryFunction<A, T>(function);
+ public static <A, T> Function<A, T> adapt(BinaryFunction<? super A, ? super A, ? extends T> function) {
+ return null == function ? null : new BinaryFunctionFunction<A, T>(function);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicatePredicate.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicatePredicate.java
index 9545e52..64691f9 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicateUnaryPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BinaryPredicatePredicate.java
@@ -17,25 +17,25 @@
package org.apache.commons.functor.adapter;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
- * Adapts a BinaryPredicate as a UnaryPredicate by sending the same argument to both sides of the BinaryPredicate.
+ * Adapts a BinaryPredicate as a Predicate by sending the same argument to both sides of the BinaryPredicate.
* @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class BinaryPredicateUnaryPredicate<A> implements UnaryPredicate<A> {
+public final class BinaryPredicatePredicate<A> implements Predicate<A> {
/**
* The adapted {@link BinaryPredicate}.
*/
private final BinaryPredicate<? super A, ? super A> predicate;
/**
- * Create a new BinaryPredicateUnaryPredicate.
+ * Create a new BinaryPredicatePredicate.
* @param predicate to adapt
*/
- public BinaryPredicateUnaryPredicate(BinaryPredicate<? super A, ? super A> predicate) {
+ public BinaryPredicatePredicate(BinaryPredicate<? super A, ? super A> predicate) {
this.predicate = Validate.notNull(predicate, "BinaryPredicate argument was null");
}
@@ -51,19 +51,19 @@
*/
@Override
public boolean equals(Object obj) {
- return obj == this || obj instanceof BinaryPredicateUnaryPredicate<?>
- && equals((BinaryPredicateUnaryPredicate<?>) obj);
+ return obj == this || obj instanceof BinaryPredicatePredicate<?>
+ && equals((BinaryPredicatePredicate<?>) obj);
}
/**
- * Learn whether another BinaryPredicateUnaryPredicate is equal to
+ * Learn whether another BinaryPredicatePredicate is equal to
* <code>this</code>.
*
- * @param that BinaryPredicateUnaryPredicate to check
+ * @param that BinaryPredicatePredicate to check
*
* @return whether equal
*/
- public boolean equals(BinaryPredicateUnaryPredicate<?> that) {
+ public boolean equals(BinaryPredicatePredicate<?> that) {
return that != null && that.predicate.equals(this.predicate);
}
@@ -72,7 +72,7 @@
*/
@Override
public int hashCode() {
- return ("BinaryPredicateUnaryPredicate".hashCode() << 2) | predicate.hashCode();
+ return ("BinaryPredicatePredicate".hashCode() << 2) | predicate.hashCode();
}
/**
@@ -80,17 +80,17 @@
*/
@Override
public String toString() {
- return "BinaryPredicateUnaryPredicate<" + predicate + ">";
+ return "BinaryPredicatePredicate<" + predicate + ">";
}
/**
- * Adapt a BinaryFunction as a UnaryFunction.
+ * Adapt a BinaryPredicate as a Predicate.
* @param <A> the argument type.
* @param predicate BinaryPredicate to adapt
- * @return UnaryPredicate<A>
+ * @return Predicate<A>
*/
- public static <A> UnaryPredicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate) {
- return null == predicate ? null : new BinaryPredicateUnaryPredicate<A>(predicate);
+ public static <A> Predicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate) {
+ return null == predicate ? null : new BinaryPredicatePredicate<A>(predicate);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureProcedure.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureProcedure.java
index 76a6c6c..726ce15 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureUnaryProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BinaryProcedureProcedure.java
@@ -17,25 +17,25 @@
package org.apache.commons.functor.adapter;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * Adapts a BinaryProcedure as a UnaryProcedure by sending the same argument to both sides of the BinaryProcedure.
+ * Adapts a BinaryProcedure as a Procedure by sending the same argument to both sides of the BinaryProcedure.
* @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class BinaryProcedureUnaryProcedure<A> implements UnaryProcedure<A> {
+public final class BinaryProcedureProcedure<A> implements Procedure<A> {
/**
* The adapted procedure.
*/
private final BinaryProcedure<? super A, ? super A> procedure;
/**
- * Create a new BinaryProcedureUnaryProcedure.
+ * Create a new BinaryProcedureProcedure.
* @param procedure to adapt
*/
- public BinaryProcedureUnaryProcedure(BinaryProcedure<? super A, ? super A> procedure) {
+ public BinaryProcedureProcedure(BinaryProcedure<? super A, ? super A> procedure) {
this.procedure = Validate.notNull(procedure, "BinaryProcedure argument was null");
}
@@ -51,19 +51,19 @@
*/
@Override
public boolean equals(Object obj) {
- return obj == this || obj instanceof BinaryProcedureUnaryProcedure<?>
- && equals((BinaryProcedureUnaryProcedure<?>) obj);
+ return obj == this || obj instanceof BinaryProcedureProcedure<?>
+ && equals((BinaryProcedureProcedure<?>) obj);
}
/**
- * Learn whether another BinaryProcedureUnaryProcedure is equal to
+ * Learn whether another BinaryProcedureProcedure is equal to
* <code>this</code>.
*
- * @param that BinaryProcedureUnaryProcedure to check
+ * @param that BinaryProcedureProcedure to check
*
* @return whether equal
*/
- public boolean equals(BinaryProcedureUnaryProcedure<?> that) {
+ public boolean equals(BinaryProcedureProcedure<?> that) {
return that != null && that.procedure.equals(this.procedure);
}
@@ -72,7 +72,7 @@
*/
@Override
public int hashCode() {
- return ("BinaryProcedureUnaryProcedure".hashCode() << 2) | procedure.hashCode();
+ return ("BinaryProcedureProcedure".hashCode() << 2) | procedure.hashCode();
}
/**
@@ -80,17 +80,17 @@
*/
@Override
public String toString() {
- return "BinaryProcedureUnaryProcedure<" + procedure + ">";
+ return "BinaryProcedureProcedure<" + procedure + ">";
}
/**
- * Adapt a BinaryProcedure as a UnaryProcedure.
+ * Adapt a BinaryProcedure as a Procedure.
* @param <A> argument type
* @param procedure BinaryProcedure to adapt
- * @return UnaryProcedure<A>
+ * @return Procedure<A>
*/
- public static <A> UnaryProcedure<A> adapt(BinaryProcedure<? super A, ? super A> procedure) {
- return null == procedure ? null : new BinaryProcedureUnaryProcedure<A>(procedure);
+ public static <A> Procedure<A> adapt(BinaryProcedure<? super A, ? super A> procedure) {
+ return null == procedure ? null : new BinaryProcedureProcedure<A>(procedure);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryFunction.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryFunction.java
index 452e3aa..8d3b443 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BoundFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryFunction.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.Function;
-import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryFunction UnaryFunction}
+ * {@link Function Function}
* to the
- * {@link Function Function} interface
+ * {@link NullaryFunction NullaryFunction} interface
* using a constant unary argument.
* <p/>
* Note that although this class implements
@@ -37,29 +37,29 @@
* <code>Serializable</code> will result in an exception.
*
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class BoundFunction<T> implements Function<T>, Serializable {
+public final class BoundNullaryFunction<T> implements NullaryFunction<T>, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 8873081237760986490L;
- /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
- private final UnaryFunction<Object, ? extends T> function;
+ /** The {@link Function Function} I'm wrapping. */
+ private final Function<Object, ? extends T> function;
/** The argument to pass to {@code function}. */
private final Object arg;
/**
- * Create a new BoundFunction instance.
+ * Create a new BoundNullaryFunction instance.
* @param <A> the argument value type
* @param function the function to adapt
* @param arg the constant argument to use
*/
@SuppressWarnings("unchecked")
- public <A> BoundFunction(UnaryFunction<? super A, ? extends T> function, A arg) {
+ public <A> BoundNullaryFunction(Function<? super A, ? extends T> function, A arg) {
this.function =
- (UnaryFunction<Object, ? extends T>) Validate.notNull(function,
- "UnaryFunction argument was null");
+ (Function<Object, ? extends T>) Validate.notNull(function,
+ "Function argument was null");
this.arg = arg;
}
@@ -75,15 +75,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof BoundFunction<?> && equals((BoundFunction<?>) that));
+ return that == this || (that instanceof BoundNullaryFunction<?> && equals((BoundNullaryFunction<?>) that));
}
/**
- * Learn whether another BoundFunction is equal to this.
- * @param that BoundFunction to test
+ * Learn whether another BoundNullaryFunction is equal to this.
+ * @param that BoundNullaryFunction to test
* @return boolean
*/
- public boolean equals(BoundFunction<?> that) {
+ public boolean equals(BoundNullaryFunction<?> that) {
if (that == null) {
return false;
}
@@ -98,7 +98,7 @@
*/
@Override
public int hashCode() {
- int result = "BoundFunction".hashCode();
+ int result = "BoundNullaryFunction".hashCode();
result <<= 2;
result |= function.hashCode();
result <<= 2;
@@ -110,28 +110,28 @@
*/
@Override
public String toString() {
- return "BoundFunction<" + function.toString() + "(" + arg + ")>";
+ return "BoundNullaryFunction<" + function.toString() + "(" + arg + ")>";
}
/**
* Adapt the given, possibly-<code>null</code>,
- * {@link UnaryFunction UnaryFunction} to the
- * {@link Function Function} interface by binding
+ * {@link Function Function} to the
+ * {@link NullaryFunction NullaryFunction} interface by binding
* the specified <code>Object</code> as a constant
* argument.
- * When the given <code>UnaryFunction</code> is <code>null</code>,
+ * When the given <code>Function</code> is <code>null</code>,
* returns <code>null</code>.
* @param <A> input type
* @param <T> result type
* @param function the possibly-<code>null</code>
- * {@link UnaryFunction UnaryFunction} to adapt
+ * {@link Function Function} to adapt
* @param arg the object to bind as a constant argument
- * @return a <code>BoundFunction</code> wrapping the given
- * {@link UnaryFunction UnaryFunction}, or <code>null</code>
- * if the given <code>UnaryFunction</code> is <code>null</code>
+ * @return a <code>BoundNullaryFunction</code> wrapping the given
+ * {@link Function Function}, or <code>null</code>
+ * if the given <code>Function</code> is <code>null</code>
*/
- public static <A, T> BoundFunction<T> bind(UnaryFunction<? super A, ? extends T> function, A arg) {
- return null == function ? null : new BoundFunction<T>(function, arg);
+ public static <A, T> BoundNullaryFunction<T> bind(Function<? super A, ? extends T> function, A arg) {
+ return null == function ? null : new BoundNullaryFunction<T>(function, arg);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryPredicate.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryPredicate.java
index f0b7fb3..de65796 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BoundPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryPredicate.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryPredicate UnaryPredicate}
+ * {@link Predicate Predicate}
* to the
- * {@link Predicate Predicate} interface
+ * {@link NullaryPredicate NullaryPredicate} interface
* using a constant unary argument.
* <p/>
* Note that although this class implements
@@ -36,29 +36,29 @@
* an instance whose delegates are not
* <code>Serializable</code> will result in an exception.
*
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class BoundPredicate implements Predicate, Serializable {
+public final class BoundNullaryPredicate implements NullaryPredicate, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -5721164265625291834L;
- /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
- private final UnaryPredicate<Object> predicate;
+ /** The {@link Predicate Predicate} I'm wrapping. */
+ private final Predicate<Object> predicate;
/** The parameter to pass to {@code predicate}. */
private final Object param;
/**
- * Create a new BoundPredicate instance.
+ * Create a new BoundNullaryPredicate instance.
* @param <A> input type
* @param predicate the predicate to adapt
* @param arg the constant argument to use
*/
@SuppressWarnings("unchecked")
- public <A> BoundPredicate(UnaryPredicate<? super A> predicate, A arg) {
+ public <A> BoundNullaryPredicate(Predicate<? super A> predicate, A arg) {
this.predicate =
- (UnaryPredicate<Object>) Validate.notNull(predicate,
- "UnaryPredicate argument was null");
+ (Predicate<Object>) Validate.notNull(predicate,
+ "Predicate argument was null");
this.param = arg;
}
@@ -74,15 +74,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof BoundPredicate && equals((BoundPredicate) that));
+ return that == this || (that instanceof BoundNullaryPredicate && equals((BoundNullaryPredicate) that));
}
/**
- * Learn whether another BoundPredicate is equal to this.
- * @param that BoundPredicate to test
+ * Learn whether another BoundNullaryPredicate is equal to this.
+ * @param that BoundNullaryPredicate to test
* @return boolean
*/
- public boolean equals(BoundPredicate that) {
+ public boolean equals(BoundNullaryPredicate that) {
return null != that
&& predicate.equals(that.predicate)
&& (null == param ? null == that.param : param.equals(that.param));
@@ -94,7 +94,7 @@
*/
@Override
public int hashCode() {
- int hash = "BoundPredicate".hashCode();
+ int hash = "BoundNullaryPredicate".hashCode();
hash <<= 2;
hash ^= predicate.hashCode();
if (null != param) {
@@ -109,28 +109,28 @@
*/
@Override
public String toString() {
- return "BoundPredicate<" + predicate + "(" + param + ")>";
+ return "BoundNullaryPredicate<" + predicate + "(" + param + ")>";
}
/**
* Adapt the given, possibly-<code>null</code>,
- * {@link UnaryPredicate UnaryPredicate} to the
- * {@link Predicate Predicate} interface by binding
+ * {@link Predicate Predicate} to the
+ * {@link NullaryPredicate NullaryPredicate} interface by binding
* the specified <code>Object</code> as a constant
* argument.
- * When the given <code>UnaryPredicate</code> is <code>null</code>,
+ * When the given <code>Predicate</code> is <code>null</code>,
* returns <code>null</code>.
*
* @param <A> input type
* @param predicate the possibly-<code>null</code>
- * {@link UnaryPredicate UnaryPredicate} to adapt
+ * {@link Predicate Predicate} to adapt
* @param arg the object to bind as a constant argument
- * @return a <code>BoundPredicate</code> wrapping the given
- * {@link UnaryPredicate UnaryPredicate}, or <code>null</code>
- * if the given <code>UnaryPredicate</code> is <code>null</code>
+ * @return a <code>BoundNullaryPredicate</code> wrapping the given
+ * {@link Predicate Predicate}, or <code>null</code>
+ * if the given <code>Predicate</code> is <code>null</code>
*/
- public static <A> BoundPredicate bind(UnaryPredicate<? super A> predicate, A arg) {
- return null == predicate ? null : new BoundPredicate(predicate, arg);
+ public static <A> BoundNullaryPredicate bind(Predicate<? super A> predicate, A arg) {
+ return null == predicate ? null : new BoundNullaryPredicate(predicate, arg);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryProcedure.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java
rename to core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryProcedure.java
index 835000b..2024244 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/BoundProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/BoundNullaryProcedure.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryProcedure UnaryProcedure}
+ * {@link Procedure Procedure}
* to the
- * {@link Procedure Procedure} interface
+ * {@link NullaryProcedure NullaryProcedure} interface
* using a constant unary argument.
* <p/>
* Note that although this class implements
@@ -36,29 +36,29 @@
* an instance whose delegates are not
* <code>Serializable</code> will result in an exception.
*
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class BoundProcedure implements Procedure, Serializable {
+public final class BoundNullaryProcedure implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -6010802933400471747L;
- /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
- private final UnaryProcedure<Object> procedure;
+ /** The {@link Procedure Procedure} I'm wrapping. */
+ private final Procedure<Object> procedure;
/** The parameter to pass to {@code procedure}. */
private final Object param;
/**
- * Create a new BoundProcedure instance.
+ * Create a new BoundNullaryProcedure instance.
* @param <A> arg type
* @param procedure the procedure to adapt
* @param arg the constant argument to use
*/
@SuppressWarnings("unchecked")
- public <A> BoundProcedure(UnaryProcedure<? super A> procedure, A arg) {
+ public <A> BoundNullaryProcedure(Procedure<? super A> procedure, A arg) {
this.procedure =
- (UnaryProcedure<Object>) Validate.notNull(procedure,
- "UnaryProcedure argument was null");
+ (Procedure<Object>) Validate.notNull(procedure,
+ "Procedure argument was null");
this.param = arg;
}
@@ -74,15 +74,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof BoundProcedure && equals((BoundProcedure) that));
+ return that == this || (that instanceof BoundNullaryProcedure && equals((BoundNullaryProcedure) that));
}
/**
- * Learn whether a given BoundProcedure is equal to this.
- * @param that the BoundProcedure to test
+ * Learn whether a given BoundNullaryProcedure is equal to this.
+ * @param that the BoundNullaryProcedure to test
* @return boolean
*/
- public boolean equals(BoundProcedure that) {
+ public boolean equals(BoundNullaryProcedure that) {
return null != that
&& procedure.equals(that.procedure)
&& (null == param ? null == that.param : param.equals(that.param));
@@ -93,7 +93,7 @@
*/
@Override
public int hashCode() {
- int hash = "BoundProcedure".hashCode();
+ int hash = "BoundNullaryProcedure".hashCode();
hash <<= 2;
hash ^= procedure.hashCode();
if (null != param) {
@@ -108,28 +108,28 @@
*/
@Override
public String toString() {
- return "BoundProcedure<" + procedure + "(" + param + ")>";
+ return "BoundNullaryProcedure<" + procedure + "(" + param + ")>";
}
/**
* Adapt the given, possibly-<code>null</code>,
- * {@link UnaryProcedure UnaryProcedure} to the
- * {@link Procedure Procedure} interface by binding
+ * {@link Procedure Procedure} to the
+ * {@link NullaryProcedure NullaryProcedure} interface by binding
* the specified <code>Object</code> as a constant
* argument.
- * When the given <code>UnaryProcedure</code> is <code>null</code>,
+ * When the given <code>Procedure</code> is <code>null</code>,
* returns <code>null</code>.
*
* @param <A> arg type
* @param procedure the possibly-<code>null</code>
- * {@link UnaryProcedure UnaryProcedure} to adapt
+ * {@link Procedure Procedure} to adapt
* @param arg the object to bind as a constant argument
- * @return a <code>BoundProcedure</code> wrapping the given
- * {@link UnaryProcedure UnaryProcedure}, or <code>null</code>
- * if the given <code>UnaryProcedure</code> is <code>null</code>
+ * @return a <code>BoundNullaryProcedure</code> wrapping the given
+ * {@link Procedure Procedure}, or <code>null</code>
+ * if the given <code>Procedure</code> is <code>null</code>
*/
- public static <A> BoundProcedure bind(UnaryProcedure<? super A> procedure, A arg) {
- return null == procedure ? null : new BoundProcedure(procedure, arg);
+ public static <A> BoundNullaryProcedure bind(Procedure<? super A> procedure, A arg) {
+ return null == procedure ? null : new BoundNullaryProcedure(procedure, arg);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryFunction.java
similarity index 74%
rename from core/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
rename to core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryFunction.java
index c65d861..2fbcb80 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryFunction.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryFunction BinaryFunction}
* to the
- * {@link Function Function} interface
+ * {@link NullaryFunction NullaryFunction} interface
* using constant arguments.
* <p/>
* Note that although this class implements
@@ -37,9 +37,9 @@
* <code>Serializable</code> will result in an exception.
*
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class FullyBoundFunction<T> implements Function<T>, Serializable {
+public final class FullyBoundNullaryFunction<T> implements NullaryFunction<T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -52,7 +52,7 @@
private final Object right;
/**
- * Create a new FullyBoundFunction.
+ * Create a new FullyBoundNullaryFunction.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param function the function to adapt
@@ -60,7 +60,9 @@
* @param right the right side argument to use
*/
@SuppressWarnings("unchecked")
- public <L, R> FullyBoundFunction(BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right) {
+ public <L, R> FullyBoundNullaryFunction(
+ BinaryFunction<? super L, ? super R, ? extends T> function,
+ L left, R right) {
this.function =
(BinaryFunction<Object, Object, T>) Validate.notNull(function,
"BinaryFunction argument was null");
@@ -80,15 +82,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FullyBoundFunction<?> && equals((FullyBoundFunction<?>) that));
+ return that == this || (that instanceof FullyBoundNullaryFunction<?>
+ && equals((FullyBoundNullaryFunction<?>) that));
}
/**
- * Learn whether another FullyBoundFunction is equal to this.
- * @param that FullyBoundFunction to test
+ * Learn whether another FullyBoundNullaryFunction is equal to this.
+ * @param that FullyBoundNullaryFunction to test
* @return boolean
*/
- public boolean equals(FullyBoundFunction<?> that) {
+ public boolean equals(FullyBoundNullaryFunction<?> that) {
return null != that && function.equals(that.function)
&& (null == left ? null == that.left : left.equals(that.left))
&& (null == right ? null == that.right : right.equals(that.right));
@@ -99,7 +102,7 @@
*/
@Override
public int hashCode() {
- int hash = "FullyBoundFunction".hashCode();
+ int hash = "FullyBoundNullaryFunction".hashCode();
hash <<= 2;
hash ^= function.hashCode();
hash <<= 2;
@@ -118,22 +121,22 @@
*/
@Override
public String toString() {
- return "FullyBoundFunction<" + function + "(" + left + ", " + right + ")>";
+ return "FullyBoundNullaryFunction<" + function + "(" + left + ", " + right + ")>";
}
/**
- * Adapt a BinaryFunction as a Function.
+ * Adapt a BinaryNullaryFunction as a NullaryFunction.
* @param <L> left type
* @param <R> right type
* @param <T> result type
* @param function to adapt
* @param left left side argument
* @param right right side argument
- * @return FullyBoundFunction
+ * @return FullyBoundNullaryFunction
*/
- public static <L, R, T> FullyBoundFunction<T> bind(
+ public static <L, R, T> FullyBoundNullaryFunction<T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right) {
- return null == function ? null : new FullyBoundFunction<T>(function, left, right);
+ return null == function ? null : new FullyBoundNullaryFunction<T>(function, left, right);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryPredicate.java
similarity index 73%
rename from core/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
rename to core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryPredicate.java
index 7b21bfb..4908505 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryPredicate.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link BinaryPredicate BinaryPredicate}
+ * {@link BinaryNullaryPredicate BinaryNullaryPredicate}
* to the
- * {@link org.apache.commons.functor.UnaryPredicate UnaryPredicate} interface
+ * {@link org.apache.commons.functor.NullaryPredicate NullaryPredicate} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -36,9 +36,9 @@
* an instance whose delegates are not
* <code>Serializable</code> will result in an exception.
*
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class FullyBoundPredicate implements Predicate, Serializable {
+public final class FullyBoundNullaryPredicate implements NullaryPredicate, Serializable {
/**
* serialVersionUID declaration.
@@ -52,7 +52,7 @@
private final Object right;
/**
- * Create a new FullyBoundPredicate instance.
+ * Create a new FullyBoundNullaryPredicate instance.
* @param <L> left type
* @param <R> right type
* @param predicate the predicate to adapt
@@ -60,7 +60,7 @@
* @param right the right argument to use
*/
@SuppressWarnings("unchecked")
- public <L, R> FullyBoundPredicate(BinaryPredicate<? super L, ? super R> predicate, L left, R right) {
+ public <L, R> FullyBoundNullaryPredicate(BinaryPredicate<? super L, ? super R> predicate, L left, R right) {
this.predicate =
(BinaryPredicate<Object, Object>) Validate.notNull(predicate,
"BinaryPredicate argument was null");
@@ -80,15 +80,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FullyBoundPredicate && equals((FullyBoundPredicate) that));
+ return that == this || (that instanceof FullyBoundNullaryPredicate
+ && equals((FullyBoundNullaryPredicate) that));
}
/**
- * Learn whether another FullyBoundPredicate is equal to this.
- * @param that FullyBoundPredicate to test
+ * Learn whether another FullyBoundNullaryPredicate is equal to this.
+ * @param that FullyBoundNullaryPredicate to test
* @return boolean
*/
- public boolean equals(FullyBoundPredicate that) {
+ public boolean equals(FullyBoundNullaryPredicate that) {
return null != that && predicate.equals(that.predicate)
&& (null == left ? null == that.left : left.equals(that.left))
&& (null == right ? null == that.right : right.equals(that.right));
@@ -99,7 +100,7 @@
*/
@Override
public int hashCode() {
- int hash = "FullyBoundPredicate".hashCode();
+ int hash = "FullyBoundNullaryPredicate".hashCode();
hash <<= 2;
hash ^= predicate.hashCode();
hash <<= 2;
@@ -118,20 +119,20 @@
*/
@Override
public String toString() {
- return "FullyBoundPredicate<" + predicate + "(" + left + ", " + right + ")>";
+ return "FullyBoundNullaryPredicate<" + predicate + "(" + left + ", " + right + ")>";
}
/**
- * Adapt a BinaryPredicate to the Predicate interface.
+ * Adapt a BinaryPredicate to the NullaryPredicate interface.
* @param predicate to adapt
* @param <L> left type
* @param <R> right type
* @param left L argument to always send as the left operand to the wrapped function
* @param right R argument to always send as the right operand to the wrapped function
- * @return FullyBoundPredicate
+ * @return FullyBoundNullaryPredicate
*/
- public static <L, R> FullyBoundPredicate bind(
+ public static <L, R> FullyBoundNullaryPredicate bind(
BinaryPredicate<? super L, ? super R> predicate, L left, R right) {
- return null == predicate ? null : new FullyBoundPredicate(predicate, left, right);
+ return null == predicate ? null : new FullyBoundNullaryPredicate(predicate, left, right);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java
similarity index 69%
rename from core/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
rename to core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java
index 420345d..fbdc515 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link BinaryProcedure BinaryProcedure}
+ * {@link BinaryNullaryProcedure BinaryNullaryProcedure}
* to the
- * {@link Procedure Procedure} interface
+ * {@link NullaryProcedure NullaryProcedure} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -36,14 +36,14 @@
* an instance whose delegates are not
* <code>Serializable</code> will result in an exception.
*
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class FullyBoundProcedure implements Procedure, Serializable {
+public final class FullyBoundNullaryProcedure implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -904891610081737737L;
- /** The {@link BinaryProcedure BinaryProcedure} I'm wrapping. */
+ /** The {@link BinaryNullaryProcedure BinaryNullaryProcedure} I'm wrapping. */
private final BinaryProcedure<Object, Object> procedure;
/** The left parameter to pass to {@code procedure}. */
private final Object left;
@@ -51,7 +51,7 @@
private final Object right;
/**
- * Create a new FullyBoundProcedure instance.
+ * Create a new FullyBoundNullaryProcedure instance.
* @param <L> left type
* @param <R> right type
* @param procedure the procedure to adapt
@@ -59,7 +59,7 @@
* @param right the right argument to use
*/
@SuppressWarnings("unchecked")
- public <L, R> FullyBoundProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
+ public <L, R> FullyBoundNullaryProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
this.procedure =
(BinaryProcedure<Object, Object>) Validate.notNull(procedure,
"BinaryProcedure argument was null");
@@ -79,15 +79,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FullyBoundProcedure && equals((FullyBoundProcedure) that));
+ return that == this || (that instanceof FullyBoundNullaryProcedure
+ && equals((FullyBoundNullaryProcedure) that));
}
/**
- * Learn whether another FullyBoundProcedure is equal to this.
- * @param that FullyBoundProcedure to test
+ * Learn whether another FullyBoundNullaryProcedure is equal to this.
+ * @param that FullyBoundNullaryProcedure to test
* @return boolean
*/
- public boolean equals(FullyBoundProcedure that) {
+ public boolean equals(FullyBoundNullaryProcedure that) {
return null != that && procedure.equals(that.procedure)
&& (null == left ? null == that.left : left.equals(that.left))
&& (null == right ? null == that.right : right.equals(that.right));
@@ -98,7 +99,7 @@
*/
@Override
public int hashCode() {
- int hash = "FullyBoundProcedure".hashCode();
+ int hash = "FullyBoundNullaryProcedure".hashCode();
hash <<= 2;
hash ^= procedure.hashCode();
hash <<= 2;
@@ -117,20 +118,21 @@
*/
@Override
public String toString() {
- return "FullyBoundProcedure<" + procedure + "(" + left + ", " + right + ")>";
+ return "FullyBoundNullaryProcedure<" + procedure + "(" + left + ", " + right + ")>";
}
/**
- * Adapt a BinaryProcedure to the Procedure interface.
+ * Adapt a BinaryNullaryProcedure to the NullaryProcedure interface.
* @param <L> left type
* @param <R> right type
* @param procedure to adapt
* @param left left side argument
* @param right right side argument
- * @return FullyBoundProcedure
+ * @return FullyBoundNullaryProcedure
*/
- public static <L, R> FullyBoundProcedure bind(BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
- return null == procedure ? null : new FullyBoundProcedure(procedure, left, right);
+ public static <L, R> FullyBoundNullaryProcedure bind(
+ BinaryProcedure<? super L, ? super R> procedure, L left, R right) {
+ return null == procedure ? null : new FullyBoundNullaryProcedure(procedure, left, right);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
index b19c07d..b3556c0 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
@@ -24,43 +24,45 @@
/**
* Adapts a <code>Boolean</code>-valued
- * {@link Function Function} to the
- * {@link Predicate Predicate} interface.
+ * {@link Function Function}
+ * to the {@link Predicate Predicate}
+ * interface.
* <p/>
* Note that although this class implements
* {@link Serializable}, a given instance will
* only be truly <code>Serializable</code> if the
- * underlying functor is. Attempts to serialize
+ * underlying function is. Attempts to serialize
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
*
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class FunctionPredicate implements Predicate, Serializable {
-
+public final class FunctionPredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 6564796937660102222L;
+ private static final long serialVersionUID = -9211927278252224707L;
/** The {@link Function Function} I'm wrapping. */
- private final Function<Boolean> function;
+ private final Function<? super A, Boolean> function;
/**
- * Create a new FunctionPredicate.
- * @param function to adapt
+ * Create an {@link Predicate Predicate} wrapping
+ * the given {@link Function Function}.
+ * @param function the {@link Function Function} to wrap
*/
- public FunctionPredicate(Function<Boolean> function) {
+ public FunctionPredicate(Function<? super A, Boolean> function) {
this.function = Validate.notNull(function, "Function argument was null");
}
/**
+ * {@inheritDoc}
* Returns the <code>boolean</code> value of the non-<code>null</code>
* <code>Boolean</code> returned by the {@link Function#evaluate evaluate}
* method of my underlying function.
- * {@inheritDoc}
*/
- public boolean test() {
- return function.evaluate().booleanValue();
+ public boolean test(A obj) {
+ return function.evaluate(obj).booleanValue();
}
/**
@@ -68,7 +70,8 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FunctionPredicate && equals((FunctionPredicate) that));
+ return that == this
+ || (that instanceof FunctionPredicate<?> && equals((FunctionPredicate<?>) that));
}
/**
@@ -76,7 +79,7 @@
* @param that FunctionPredicate to test
* @return boolean
*/
- public boolean equals(FunctionPredicate that) {
+ public boolean equals(FunctionPredicate<?> that) {
return null != that && function.equals(that.function);
}
@@ -99,11 +102,21 @@
}
/**
- * Adapt a Function as a Predicate.
- * @param function to adapt
- * @return FunctionPredicate
+ * Adapt the given, possibly-<code>null</code>,
+ * {@link Function Function} to the
+ * {@link Predicate Predicate} interface.
+ * When the given <code>Function</code> is <code>null</code>,
+ * returns <code>null</code>.
+ *
+ * @param <A> the argument type.
+ * @param function the possibly-<code>null</code>
+ * {@link Function Function} to adapt
+ * @return a {@link Predicate Predicate} wrapping the given
+ * {@link Function Function}, or <code>null</code>
+ * if the given <code>Function</code> is <code>null</code>
*/
- public static FunctionPredicate adapt(Function<Boolean> function) {
- return null == function ? null : new FunctionPredicate(function);
+ public static <A> FunctionPredicate<A> adapt(Function<? super A, Boolean> function) {
+ return null == function ? null : new FunctionPredicate<A>(function);
}
+
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
index 6214bcb..af18a94 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
@@ -35,32 +35,34 @@
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
*
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class FunctionProcedure implements Procedure, Serializable {
+public final class FunctionProcedure<A> implements Procedure<A>, Serializable {
+
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -7300031015086684901L;
+ private static final long serialVersionUID = -3578673875995684811L;
/** The {@link Function Function} I'm wrapping. */
- private final Function<?> function;
+ private final Function<? super A, ?> function;
/**
* Create an {@link Procedure Procedure} wrapping
* the given {@link Function Function}.
* @param function the {@link Function Function} to wrap
*/
- public FunctionProcedure(Function<?> function) {
+ public FunctionProcedure(Function<? super A, ?> function) {
this.function = Validate.notNull(function, "Function argument was null");
}
/**
+ * {@link Function#evaluate Evaluate} my function, but
+ * ignore its returned value.
* {@inheritDoc}
- * {@link Function#evaluate Evaluate} my function,
- * but ignore its returned value.
*/
- public void run() {
- function.evaluate();
+ public void run(A obj) {
+ function.evaluate(obj);
}
/**
@@ -68,15 +70,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FunctionProcedure && equals((FunctionProcedure) that));
+ return that == this
+ || (that instanceof FunctionProcedure<?> && equals((FunctionProcedure<?>) that));
}
/**
- * Learn whether another FunctionProcedure is equal to this.
- * @param that FunctionProcedure to test
+ * Learn whether a specified FunctionPredicate is equal to this.
+ * @param that the FunctionPredicate to test
* @return boolean
*/
- public boolean equals(FunctionProcedure that) {
+ public boolean equals(FunctionProcedure<?> that) {
return null != that && function.equals(that.function);
}
@@ -105,14 +108,15 @@
* When the given <code>Function</code> is <code>null</code>,
* returns <code>null</code>.
*
+ * @param <A> the argument type.
* @param function the possibly-<code>null</code>
* {@link Function Function} to adapt
* @return a {@link Procedure Procedure} wrapping the given
* {@link Function Function}, or <code>null</code>
* if the given <code>Function</code> is <code>null</code>
*/
- public static FunctionProcedure adapt(Function<?> function) {
- return null == function ? null : new FunctionProcedure(function);
+ public static <A> FunctionProcedure<A> adapt(Function<? super A, ?> function) {
+ return null == function ? null : new FunctionProcedure<A>(function);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
index 1de56b6..af577c7 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryFunction UnaryFunction}
+ * {@link Function Function}
* to the
* {@link BinaryFunction BinaryFunction} interface
* by ignoring the first binary argument.
@@ -46,15 +46,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 4677703245851183542L;
- /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
- private final UnaryFunction<? super R, ? extends T> function;
+ /** The {@link Function Function} I'm wrapping. */
+ private final Function<? super R, ? extends T> function;
/**
* Create a new IgnoreLeftFunction.
- * @param function UnaryFunction for right argument
+ * @param function Function for right argument
*/
- public IgnoreLeftFunction(UnaryFunction<? super R, ? extends T> function) {
- this.function = Validate.notNull(function, "UnaryFunction argument was null");
+ public IgnoreLeftFunction(Function<? super R, ? extends T> function) {
+ this.function = Validate.notNull(function, "Function argument was null");
}
/**
@@ -101,14 +101,14 @@
}
/**
- * Adapt a UnaryFunction to the BinaryFunction interface.
+ * Adapt a Function to the BinaryFunction interface.
* @param <L> left type
* @param <R> right type
* @param <T> result type
* @param function to adapt
* @return IgnoreLeftFunction
*/
- public static <L, R, T> IgnoreLeftFunction<L, R, T> adapt(UnaryFunction<? super R, ? extends T> function) {
+ public static <L, R, T> IgnoreLeftFunction<L, R, T> adapt(Function<? super R, ? extends T> function) {
return null == function ? null : new IgnoreLeftFunction<L, R, T>(function);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
index 81f285a..9d7cc8a 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryPredicate UnaryPredicate}
+ * {@link Predicate Predicate}
* to the
* {@link BinaryPredicate BinaryPredicate} interface
* by ignoring the first binary argument.
@@ -45,15 +45,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -3200352647509255939L;
- /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
- private final UnaryPredicate<? super R> predicate;
+ /** The {@link Predicate Predicate} I'm wrapping. */
+ private final Predicate<? super R> predicate;
/**
* Create a new IgnoreLeftPredicate.
* @param predicate the right predicate
*/
- public IgnoreLeftPredicate(UnaryPredicate<? super R> predicate) {
- this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
+ public IgnoreLeftPredicate(Predicate<? super R> predicate) {
+ this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
/**
@@ -99,13 +99,13 @@
}
/**
- * Adapt a UnaryPredicate to an IgnoreLeftPredicate.
+ * Adapt a Predicate to an IgnoreLeftPredicate.
* @param <L> left type
* @param <R> right type
* @param predicate to adapt
* @return IgnoreLeftPredicate<L, R>
*/
- public static <L, R> IgnoreLeftPredicate<L, R> adapt(UnaryPredicate<? super R> predicate) {
+ public static <L, R> IgnoreLeftPredicate<L, R> adapt(Predicate<? super R> predicate) {
return null == predicate ? null : new IgnoreLeftPredicate<L, R>(predicate);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
index 8c4596b..2a024c2 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryProcedure UnaryProcedure}
+ * {@link Procedure Procedure}
* to the
* {@link BinaryProcedure BinaryProcedure} interface
* by ignoring the first binary argument.
@@ -45,15 +45,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 513435556181843298L;
- /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
- private final UnaryProcedure<? super R> procedure;
+ /** The {@link Procedure Procedure} I'm wrapping. */
+ private final Procedure<? super R> procedure;
/**
* Create a new IgnoreLeftProcedure.
* @param procedure to adapt
*/
- public IgnoreLeftProcedure(UnaryProcedure<? super R> procedure) {
- this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
+ public IgnoreLeftProcedure(Procedure<? super R> procedure) {
+ this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
@@ -99,13 +99,13 @@
}
/**
- * Adapt a UnaryProcedure to the BinaryProcedure interface.
+ * Adapt a Procedure to the BinaryProcedure interface.
* @param <L> left type
* @param <R> right type
* @param procedure to adapt
* @return IgnoreLeftProcedure<L, R>
*/
- public static <L, R> IgnoreLeftProcedure<L, R> adapt(UnaryProcedure<? super R> procedure) {
+ public static <L, R> IgnoreLeftProcedure<L, R> adapt(Procedure<? super R> procedure) {
return null == procedure ? null : new IgnoreLeftProcedure<L, R>(procedure);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
index 67156a0..2772943 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryFunction UnaryFunction}
+ * {@link Function Function}
* to the
* {@link BinaryFunction BinaryFunction} interface
* by ignoring the second binary argument.
@@ -46,15 +46,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -1564814716024791395L;
- /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
- private final UnaryFunction<? super L, ? extends T> function;
+ /** The {@link Function Function} I'm wrapping. */
+ private final Function<? super L, ? extends T> function;
/**
* Create a new IgnoreRightFunction.
- * @param function UnaryFunction to wrap
+ * @param function Function to wrap
*/
- public IgnoreRightFunction(UnaryFunction<? super L, ? extends T> function) {
- this.function = Validate.notNull(function, "UnaryFunction argument was null");
+ public IgnoreRightFunction(Function<? super L, ? extends T> function) {
+ this.function = Validate.notNull(function, "Function argument was null");
}
/**
@@ -101,14 +101,14 @@
}
/**
- * Adapt a UnaryFunction to the BinaryFunction interface.
+ * Adapt a Function to the BinaryFunction interface.
* @param <L> left type
* @param <R> right type
* @param <T> result type
- * @param function UnaryFunction to adapt
+ * @param function Function to adapt
* @return IgnoreRightFunction
*/
- public static <L, R, T> IgnoreRightFunction<L, R, T> adapt(UnaryFunction<? super L, ? extends T> function) {
+ public static <L, R, T> IgnoreRightFunction<L, R, T> adapt(Function<? super L, ? extends T> function) {
return null == function ? null : new IgnoreRightFunction<L, R, T>(function);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
index 942ad96..7832f8f 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryPredicate UnaryPredicate}
+ * {@link Predicate Predicate}
* to the
* {@link BinaryPredicate BinaryPredicate} interface
* by ignoring the second binary argument.
@@ -45,15 +45,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -4236624667788627722L;
- /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
- private final UnaryPredicate<? super L> predicate;
+ /** The {@link Predicate Predicate} I'm wrapping. */
+ private final Predicate<? super L> predicate;
/**
* Create a new IgnoreRightPredicate.
* @param predicate left
*/
- public IgnoreRightPredicate(UnaryPredicate<? super L> predicate) {
- this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
+ public IgnoreRightPredicate(Predicate<? super L> predicate) {
+ this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
/**
@@ -100,13 +100,13 @@
}
/**
- * Adapt a UnaryPredicate as an IgnoreRightPredicate.
+ * Adapt a Predicate as an IgnoreRightPredicate.
* @param <L> left type
* @param <R> right type
* @param predicate to adapt
* @return IgnoreRightPredicate<L, R>
*/
- public static <L, R> IgnoreRightPredicate<L, R> adapt(UnaryPredicate<? super L> predicate) {
+ public static <L, R> IgnoreRightPredicate<L, R> adapt(Predicate<? super L> predicate) {
return null == predicate ? null : new IgnoreRightPredicate<L, R>(predicate);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
index 8348e95..4b371ca 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link UnaryProcedure UnaryProcedure}
+ * {@link Procedure Procedure}
* to the
* {@link BinaryProcedure BinaryProcedure} interface
* by ignoring the second binary argument.
@@ -45,15 +45,15 @@
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -7374293905310619206L;
- /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
- private final UnaryProcedure<? super L> procedure;
+ /** The {@link Procedure Procedure} I'm wrapping. */
+ private final Procedure<? super L> procedure;
/**
* Create a new IgnoreRightProcedure.
- * @param procedure UnaryProcedure to adapt
+ * @param procedure Procedure to adapt
*/
- public IgnoreRightProcedure(UnaryProcedure<? super L> procedure) {
- this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
+ public IgnoreRightProcedure(Procedure<? super L> procedure) {
+ this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
@@ -100,13 +100,13 @@
}
/**
- * Adapt a UnaryProcedure to the BinaryProcedure interface.
+ * Adapt a Procedure to the BinaryProcedure interface.
* @param <L> left type
* @param <R> right type
- * @param procedure UnaryProcedure to adapt
+ * @param procedure Procedure to adapt
* @return IgnoreRightProcedure
*/
- public static <L, R> IgnoreRightProcedure<L, R> adapt(UnaryProcedure<? super L> procedure) {
+ public static <L, R> IgnoreRightProcedure<L, R> adapt(Procedure<? super L> procedure) {
return null == procedure ? null : new IgnoreRightProcedure<L, R>(procedure);
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
index 9814a4f..f4059af 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryFunction BinaryFunction}
* to the
- * {@link UnaryFunction UnaryFunction} interface
+ * {@link Function Function} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -40,7 +40,7 @@
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class LeftBoundFunction<A, T> implements UnaryFunction<A, T>, Serializable {
+public final class LeftBoundFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -114,7 +114,7 @@
}
/**
- * Adapt a BinaryFunction as a UnaryFunction.
+ * Adapt a BinaryFunction as a Function.
* @param <L> left type
* @param <R> right type
* @param <T> result type
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
index fe93d20..c9af90f 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryPredicate BinaryPredicate}
* to the
- * {@link UnaryPredicate UnaryPredicate} interface
+ * {@link Predicate Predicate} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -39,7 +39,7 @@
* @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class LeftBoundPredicate<A> implements UnaryPredicate<A>, Serializable {
+public final class LeftBoundPredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
@@ -114,7 +114,7 @@
}
/**
- * Adapt a BinaryPredicate to the UnaryPredicate interface.
+ * Adapt a BinaryPredicate to the Predicate interface.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param predicate to adapt
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
index f67c975..d3b9184 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryProcedure BinaryProcedure}
* to the
- * {@link UnaryProcedure UnaryProcedure} interface
+ * {@link Procedure Procedure} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -39,7 +39,7 @@
* @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class LeftBoundProcedure<A> implements UnaryProcedure<A>, Serializable {
+public final class LeftBoundProcedure<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -113,7 +113,7 @@
}
/**
- * Get a UnaryProcedure from <code>procedure</code>.
+ * Get a Procedure from <code>procedure</code>.
* @param <L> left type
* @param <R> right type
* @param procedure to adapt
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
rename to core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java
index 3cb90bb..29191b9 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.Function;
-import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link Function Function}
+ * {@link NullaryFunction NullaryFunction}
* to the
- * {@link UnaryFunction UnaryFunction} interface
+ * {@link Function Function} interface
* by ignoring the unary argument.
* <p/>
* Note that although this class implements
@@ -38,22 +38,22 @@
*
* @param <A> the argument type.
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class FunctionUnaryFunction<A, T> implements UnaryFunction<A, T>, Serializable {
+public final class NullaryFunctionFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 1993899041200996524L;
- /** The {@link Function Function} I'm wrapping. */
- private final Function<? extends T> function;
+ /** The {@link NullaryFunction NullaryFunction} I'm wrapping. */
+ private final NullaryFunction<? extends T> function;
/**
- * Create a new FunctionUnaryFunction.
+ * Create a new NullaryFunctionFunction.
* @param function to adapt
*/
- public FunctionUnaryFunction(Function<? extends T> function) {
- this.function = Validate.notNull(function, "Function argument was null");
+ public NullaryFunctionFunction(NullaryFunction<? extends T> function) {
+ this.function = Validate.notNull(function, "NullaryFunction argument was null");
}
/**
@@ -68,16 +68,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof FunctionUnaryFunction<?, ?>
- && equals((FunctionUnaryFunction<?, ?>) that));
+ return that == this || (that instanceof NullaryFunctionFunction<?, ?>
+ && equals((NullaryFunctionFunction<?, ?>) that));
}
/**
- * Learn whether another FunctionUnaryFunction is equal to this.
- * @param that FunctionUnaryFunction to test
+ * Learn whether another NullaryFunctionFunction is equal to this.
+ * @param that NullaryFunctionFunction to test
* @return boolean
*/
- public boolean equals(FunctionUnaryFunction<?, ?> that) {
+ public boolean equals(NullaryFunctionFunction<?, ?> that) {
return null != that && function.equals(that.function);
}
@@ -86,7 +86,7 @@
*/
@Override
public int hashCode() {
- int hash = "FunctionUnaryFunction".hashCode();
+ int hash = "NullaryFunctionFunction".hashCode();
hash ^= function.hashCode();
return hash;
}
@@ -96,18 +96,18 @@
*/
@Override
public String toString() {
- return "FunctionUnaryFunction<" + function + ">";
+ return "NullaryFunctionFunction<" + function + ">";
}
/**
- * Adapt a Function to the UnaryFunction interface.
+ * Adapt a NullaryFunction to the Function interface.
* @param <A> arg type
* @param <T> result type
* @param function to adapt
- * @return FunctionUnaryFunction
+ * @return NullaryFunctionFunction
*/
- public static <A, T> FunctionUnaryFunction<A, T> adapt(Function<? extends T> function) {
- return null == function ? null : new FunctionUnaryFunction<A, T>(function);
+ public static <A, T> NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function) {
+ return null == function ? null : new NullaryFunctionFunction<A, T>(function);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java
new file mode 100644
index 0000000..f22bf04
--- /dev/null
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java
@@ -0,0 +1,110 @@
+/*
+ * 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.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a <code>Boolean</code>-valued
+ * {@link NullaryFunction NullaryFunction} to the
+ * {@link NullaryPredicate NullaryPredicate} interface.
+ * <p/>
+ * Note that although this class implements
+ * {@link Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying functor is. Attempts to serialize
+ * an instance whose delegate is not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryFunctionNullaryPredicate implements NullaryPredicate, Serializable {
+
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = 6564796937660102222L;
+ /** The {@link NullaryFunction NullaryFunction} I'm wrapping. */
+ private final NullaryFunction<Boolean> function;
+
+ /**
+ * Create a new NullaryFunctionNullaryPredicate.
+ * @param function to adapt
+ */
+ public NullaryFunctionNullaryPredicate(NullaryFunction<Boolean> function) {
+ this.function = Validate.notNull(function, "NullaryFunction argument was null");
+ }
+
+ /**
+ * Returns the <code>boolean</code> value of the non-<code>null</code>
+ * <code>Boolean</code> returned by the {@link NullaryFunction#evaluate evaluate}
+ * method of my underlying function.
+ * {@inheritDoc}
+ */
+ public boolean test() {
+ return function.evaluate().booleanValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryFunctionNullaryPredicate
+ && equals((NullaryFunctionNullaryPredicate) that));
+ }
+
+ /**
+ * Learn whether another NullaryFunctionNullaryPredicate is equal to this.
+ * @param that NullaryFunctionNullaryPredicate to test
+ * @return boolean
+ */
+ public boolean equals(NullaryFunctionNullaryPredicate that) {
+ return null != that && function.equals(that.function);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryFunctionNullaryPredicate".hashCode();
+ hash ^= function.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryFunctionNullaryPredicate<" + function + ">";
+ }
+
+ /**
+ * Adapt a NullaryFunction as a NullaryPredicate.
+ * @param function to adapt
+ * @return NullaryFunctionNullaryPredicate
+ */
+ public static NullaryFunctionNullaryPredicate adapt(NullaryFunction<Boolean> function) {
+ return null == function ? null : new NullaryFunctionNullaryPredicate(function);
+ }
+}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java
new file mode 100644
index 0000000..9b9ace2
--- /dev/null
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java
@@ -0,0 +1,119 @@
+/*
+ * 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.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a {@link NullaryFunction NullaryFunction}
+ * to the {@link NullaryProcedure NullaryProcedure}
+ * interface by ignoring the value returned
+ * by the function.
+ * <p/>
+ * Note that although this class implements
+ * {@link Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying function is. Attempts to serialize
+ * an instance whose delegate is not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryFunctionNullaryProcedure implements NullaryProcedure, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = -7300031015086684901L;
+ /** The {@link NullaryFunction NullaryFunction} I'm wrapping. */
+ private final NullaryFunction<?> function;
+
+ /**
+ * Create an {@link NullaryProcedure NullaryProcedure} wrapping
+ * the given {@link NullaryFunction NullaryFunction}.
+ * @param function the {@link NullaryFunction NullaryFunction} to wrap
+ */
+ public NullaryFunctionNullaryProcedure(NullaryFunction<?> function) {
+ this.function = Validate.notNull(function, "NullaryFunction argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ * {@link NullaryFunction#evaluate Evaluate} my function,
+ * but ignore its returned value.
+ */
+ public void run() {
+ function.evaluate();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryFunctionNullaryProcedure
+ && equals((NullaryFunctionNullaryProcedure) that));
+ }
+
+ /**
+ * Learn whether another NullaryFunctionNullaryProcedure is equal to this.
+ * @param that NullaryFunctionNullaryProcedure to test
+ * @return boolean
+ */
+ public boolean equals(NullaryFunctionNullaryProcedure that) {
+ return null != that && function.equals(that.function);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryFunctionNullaryProcedure".hashCode();
+ hash ^= function.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryFunctionNullaryProcedure<" + function + ">";
+ }
+
+ /**
+ * Adapt the given, possibly-<code>null</code>,
+ * {@link NullaryFunction NullaryFunction} to the
+ * {@link NullaryProcedure NullaryProcedure} interface.
+ * When the given <code>NullaryFunction</code> is <code>null</code>,
+ * returns <code>null</code>.
+ *
+ * @param function the possibly-<code>null</code>
+ * {@link NullaryFunction NullaryFunction} to adapt
+ * @return a {@link NullaryProcedure NullaryProcedure} wrapping the given
+ * {@link NullaryFunction NullaryFunction}, or <code>null</code>
+ * if the given <code>NullaryFunction</code> is <code>null</code>
+ */
+ public static NullaryFunctionNullaryProcedure adapt(NullaryFunction<?> function) {
+ return null == function ? null : new NullaryFunctionNullaryProcedure(function);
+ }
+
+}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java
new file mode 100644
index 0000000..56ab8ab
--- /dev/null
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java
@@ -0,0 +1,113 @@
+/*
+ * 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.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link NullaryPredicate Predicate}
+ * to the
+ * {@link NullaryFunction NullaryFunction} interface.
+ * <p/>
+ * Note that although this class implements
+ * {@link Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying predicate is. Attempts to serialize
+ * an instance whose delegate is not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryPredicateNullaryFunction implements NullaryFunction<Boolean>, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = -8858981355549412629L;
+ /** The {@link NullaryPredicate NullaryPredicate} I'm wrapping. */
+ private final NullaryPredicate predicate;
+
+ /**
+ * Create a new NullaryPredicateNullaryFunction.
+ * @param predicate to adapt
+ */
+ public NullaryPredicateNullaryFunction(NullaryPredicate predicate) {
+ this.predicate = Validate.notNull(predicate, "NullaryPredicate argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ * Returns <code>Boolean.TRUE</code> (<code>Boolean.FALSE</code>)
+ * when the {@link NullaryPredicate#test test} method of my underlying
+ * predicate returns <code>true</code> (<code>false</code>).
+ *
+ * @return a non-<code>null</code> <code>Boolean</code> instance
+ */
+ public Boolean evaluate() {
+ return Boolean.valueOf(predicate.test());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryPredicateNullaryFunction
+ && equals((NullaryPredicateNullaryFunction) that));
+ }
+
+ /**
+ * Learn whether another NullaryPredicateNullaryFunction is equal to this.
+ * @param that NullaryPredicateNullaryFunction to test
+ * @return boolean
+ */
+ public boolean equals(NullaryPredicateNullaryFunction that) {
+ return null != that && predicate.equals(that.predicate);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryPredicateNullaryFunction".hashCode();
+ hash ^= predicate.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryPredicateNullaryFunction<" + predicate + ">";
+ }
+
+ /**
+ * Adapt a NullaryPredicate to the NullaryFunction interface.
+ * @param predicate to adapt
+ * @return NullaryPredicateNullaryFunction
+ */
+ public static NullaryPredicateNullaryFunction adapt(NullaryPredicate predicate) {
+ return null == predicate ? null : new NullaryPredicateNullaryFunction(predicate);
+ }
+
+}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java
similarity index 61%
rename from core/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
rename to core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java
index fd5bd39..bfc8f41 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/PredicateUnaryPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link Predicate Predicate}
+ * {@link NullaryPredicate NullaryPredicate}
* to the
- * {@link UnaryPredicate UnaryPredicate} interface
+ * {@link Predicate Predicate} interface
* by ignoring the given argument.
* <p/>
* Note that although this class implements
@@ -37,22 +37,22 @@
* <code>Serializable</code> will result in an exception.
*
* @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class PredicateUnaryPredicate<A> implements UnaryPredicate<A>, Serializable {
+public final class NullaryPredicatePredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -5168896606842881702L;
- /** The {@link Predicate Predicate} I'm wrapping. */
- private final Predicate predicate;
+ /** The {@link NullaryPredicate NullaryPredicate} I'm wrapping. */
+ private final NullaryPredicate predicate;
/**
- * Create a new PredicateUnaryPredicate.
+ * Create a new NullaryPredicatePredicate.
* @param predicate to adapt
*/
- public PredicateUnaryPredicate(Predicate predicate) {
- this.predicate = Validate.notNull(predicate, "Predicate argument was null");
+ public NullaryPredicatePredicate(NullaryPredicate predicate) {
+ this.predicate = Validate.notNull(predicate, "NullaryPredicate argument was null");
}
/**
@@ -67,16 +67,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof PredicateUnaryPredicate<?>
- && equals((PredicateUnaryPredicate<?>) that));
+ return that == this || (that instanceof NullaryPredicatePredicate<?>
+ && equals((NullaryPredicatePredicate<?>) that));
}
/**
- * Learn whether a given PredicateUnaryPredicate is equal to this.
- * @param that PredicateUnaryPredicate to test
+ * Learn whether a given NullaryPredicatePredicate is equal to this.
+ * @param that NullaryPredicatePredicate to test
* @return boolean
*/
- public boolean equals(PredicateUnaryPredicate<?> that) {
+ public boolean equals(NullaryPredicatePredicate<?> that) {
return null != that && predicate.equals(that.predicate);
}
@@ -85,7 +85,7 @@
*/
@Override
public int hashCode() {
- int hash = "PredicateUnaryPredicate".hashCode();
+ int hash = "NullaryPredicatePredicate".hashCode();
hash ^= predicate.hashCode();
return hash;
}
@@ -95,17 +95,17 @@
*/
@Override
public String toString() {
- return "PredicateUnaryPredicate<" + predicate + ">";
+ return "NullaryPredicatePredicate<" + predicate + ">";
}
/**
- * Adapt a Predicate to the UnaryPredicate interface.
+ * Adapt a NullaryPredicate to the Predicate interface.
* @param <A> the argument type.
* @param predicate to adapt
- * @return PredicateUnaryPredicate<A>
+ * @return NullaryPredicatePredicate<A>
*/
- public static <A> PredicateUnaryPredicate<A> adapt(Predicate predicate) {
- return null == predicate ? null : new PredicateUnaryPredicate<A>(predicate);
+ public static <A> NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate) {
+ return null == predicate ? null : new NullaryPredicatePredicate<A>(predicate);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java
new file mode 100644
index 0000000..28fbab2
--- /dev/null
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java
@@ -0,0 +1,112 @@
+/*
+ * 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.functor.adapter;
+
+import java.io.Serializable;
+
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link NullaryProcedure NullaryProcedure}
+ * to the
+ * {@link NullaryFunction NullaryFunction} interface
+ * by always returning <code>null</code>.
+ * <p/>
+ * Note that although this class implements
+ * {@link Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying nullary procedure is. Attempts to serialize
+ * an instance whose delegate is not
+ * <code>Serializable</code> will result in an exception.
+ *
+ * @param <T> the returned value type.
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryProcedureNullaryFunction<T> implements NullaryFunction<T>, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = -655207616317672341L;
+ /** The {@link NullaryProcedure NullaryProcedure} I'm wrapping. */
+ private final NullaryProcedure procedure;
+
+ /**
+ * Create a new NullaryProcedureNullaryFunction.
+ * @param procedure to adapt
+ */
+ public NullaryProcedureNullaryFunction(NullaryProcedure procedure) {
+ this.procedure = Validate.notNull(procedure, "NullaryProcedure argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T evaluate() {
+ procedure.run();
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryProcedureNullaryFunction<?>
+ && equals((NullaryProcedureNullaryFunction<?>) that));
+ }
+
+ /**
+ * Learn whether another NullaryProcedureNullaryFunction is equal to this.
+ * @param that NullaryProcedureNullaryFunction to test
+ * @return boolean
+ */
+ public boolean equals(NullaryProcedureNullaryFunction<?> that) {
+ return null != that && procedure.equals(that.procedure);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryProcedureNullaryFunction".hashCode();
+ hash ^= procedure.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryProcedureNullaryFunction<" + procedure + ">";
+ }
+
+ /**
+ * Adapt a NullaryProcedure as a NullaryFunction.
+ * @param <T> the returned value type.
+ * @param procedure to adapt
+ * @return NullaryProcedureNullaryFunction<T>
+ */
+ public static <T> NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure) {
+ return null == procedure ? null : new NullaryProcedureNullaryFunction<T>(procedure);
+ }
+
+}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java
similarity index 61%
rename from core/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
rename to core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java
index b7c62af..7de8824 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/ProcedureUnaryProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
- * {@link Procedure Procedure}
+ * {@link NullaryProcedure Procedure}
* to the
- * {@link UnaryProcedure UnaryProcedure} interface
+ * {@link Procedure Procedure} interface
* by ignoring the arguments.
* <p/>
* Note that although this class implements
@@ -37,22 +37,22 @@
* <code>Serializable</code> will result in an exception.
*
* @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class ProcedureUnaryProcedure<A> implements UnaryProcedure<A>, Serializable {
+public final class NullaryProcedureProcedure<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 501530698794315412L;
- /** The {@link Procedure Procedure} I'm wrapping. */
- private final Procedure procedure;
+ /** The {@link NullaryProcedure Procedure} I'm wrapping. */
+ private final NullaryProcedure procedure;
/**
- * Create a new ProcedureUnaryProcedure.
+ * Create a new NullaryProcedureProcedure.
* @param procedure to adapt
*/
- public ProcedureUnaryProcedure(Procedure procedure) {
- this.procedure = Validate.notNull(procedure, "Procedure argument was null");
+ public NullaryProcedureProcedure(NullaryProcedure procedure) {
+ this.procedure = Validate.notNull(procedure, "NullaryProcedure argument was null");
}
/**
@@ -67,16 +67,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ProcedureUnaryProcedure<?>
- && equals((ProcedureUnaryProcedure<?>) that));
+ return that == this || (that instanceof NullaryProcedureProcedure<?>
+ && equals((NullaryProcedureProcedure<?>) that));
}
/**
- * Learn whether another ProcedureUnaryProcedure is equal to this.
- * @param that ProcedureUnaryProcedure to test
+ * Learn whether another NullaryProcedureProcedure is equal to this.
+ * @param that NullaryProcedureProcedure to test
* @return boolean
*/
- public boolean equals(ProcedureUnaryProcedure<?> that) {
+ public boolean equals(NullaryProcedureProcedure<?> that) {
return null != that && procedure.equals(that.procedure);
}
@@ -85,7 +85,7 @@
*/
@Override
public int hashCode() {
- int hash = "ProcedureUnaryProcedure".hashCode();
+ int hash = "NullaryProcedureProcedure".hashCode();
hash ^= procedure.hashCode();
return hash;
}
@@ -95,17 +95,17 @@
*/
@Override
public String toString() {
- return "ProcedureUnaryProcedure<" + procedure + ">";
+ return "NullaryProcedureProcedure<" + procedure + ">";
}
/**
- * Adapt a Procedure to the UnaryProcedure interface.
+ * Adapt a NullaryProcedure to the Procedure interface.
* @param <A> the argument type.
* @param procedure to adapt
- * @return ProcedureUnaryProcedure<A>
+ * @return NullaryProcedureProcedure<A>
*/
- public static <A> ProcedureUnaryProcedure<A> adapt(Procedure procedure) {
- return null == procedure ? null : new ProcedureUnaryProcedure<A>(procedure);
+ public static <A> NullaryProcedureProcedure<A> adapt(NullaryProcedure procedure) {
+ return null == procedure ? null : new NullaryProcedureProcedure<A>(procedure);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
index 91596cd..dfe213d 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
@@ -35,21 +35,22 @@
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
*
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class PredicateFunction implements Function<Boolean>, Serializable {
+public final class PredicateFunction<A> implements Function<A, Boolean>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -8858981355549412629L;
+ private static final long serialVersionUID = 5660724725036398625L;
/** The {@link Predicate Predicate} I'm wrapping. */
- private final Predicate predicate;
+ private final Predicate<? super A> predicate;
/**
* Create a new PredicateFunction.
* @param predicate to adapt
*/
- public PredicateFunction(Predicate predicate) {
+ public PredicateFunction(Predicate<? super A> predicate) {
this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
@@ -61,8 +62,8 @@
*
* @return a non-<code>null</code> <code>Boolean</code> instance
*/
- public Boolean evaluate() {
- return Boolean.valueOf(predicate.test());
+ public Boolean evaluate(A obj) {
+ return Boolean.valueOf(predicate.test(obj));
}
/**
@@ -70,7 +71,8 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof PredicateFunction && equals((PredicateFunction) that));
+ return that == this
+ || (that instanceof PredicateFunction<?> && equals((PredicateFunction<?>) that));
}
/**
@@ -78,7 +80,7 @@
* @param that PredicateFunction to test
* @return boolean
*/
- public boolean equals(PredicateFunction that) {
+ public boolean equals(PredicateFunction<?> that) {
return null != that && predicate.equals(that.predicate);
}
@@ -102,11 +104,12 @@
/**
* Adapt a Predicate to the Function interface.
+ * @param <A> the argument type.
* @param predicate to adapt
* @return PredicateFunction
*/
- public static PredicateFunction adapt(Predicate predicate) {
- return null == predicate ? null : new PredicateFunction(predicate);
+ public static <A> PredicateFunction<A> adapt(Predicate<? super A> predicate) {
+ return null == predicate ? null : new PredicateFunction<A>(predicate);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
index 4de1822..f2fc7ce 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
@@ -36,30 +36,31 @@
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
*
+ * @param <A> the argument type.
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class ProcedureFunction<T> implements Function<T>, Serializable {
+public final class ProcedureFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -655207616317672341L;
+ private static final long serialVersionUID = 6153848695167906659L;
/** The {@link Procedure Procedure} I'm wrapping. */
- private final Procedure procedure;
+ private final Procedure<? super A> procedure;
/**
* Create a new ProcedureFunction.
* @param procedure to adapt
*/
- public ProcedureFunction(Procedure procedure) {
+ public ProcedureFunction(Procedure<? super A> procedure) {
this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
* {@inheritDoc}
*/
- public T evaluate() {
- procedure.run();
+ public T evaluate(A obj) {
+ procedure.run(obj);
return null;
}
@@ -68,15 +69,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ProcedureFunction<?> && equals((ProcedureFunction<?>) that));
+ return that == this || (that instanceof ProcedureFunction<?, ?>
+ && equals((ProcedureFunction<?, ?>) that));
}
/**
- * Learn whether another ProcedureFunction is equal to this.
+ * Learn whether a given ProcedureFunction is equal to this.
* @param that ProcedureFunction to test
* @return boolean
*/
- public boolean equals(ProcedureFunction<?> that) {
+ public boolean equals(ProcedureFunction<?, ?> that) {
return null != that && procedure.equals(that.procedure);
}
@@ -99,13 +101,14 @@
}
/**
- * Adapt a Procedure as a Function.
+ * Adapt a Procedure to the Function interface.
+ * @param <A> the argument type.
* @param <T> the returned value type.
* @param procedure to adapt
- * @return ProcedureFunction<T>
+ * @return ProcedureFunction
*/
- public static <T> ProcedureFunction<T> adapt(Procedure procedure) {
- return null == procedure ? null : new ProcedureFunction<T>(procedure);
+ public static <A, T> ProcedureFunction<A, T> adapt(Procedure<? super A> procedure) {
+ return null == procedure ? null : new ProcedureFunction<A, T>(procedure);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
index 98de272..02c75a7 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryFunction BinaryFunction}
* to the
- * {@link UnaryFunction UnaryFunction} interface
+ * {@link Function Function} interface
* using a constant right-side argument.
* <p/>
* Note that although this class implements
@@ -40,7 +40,7 @@
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class RightBoundFunction<A, T> implements UnaryFunction<A, T>, Serializable {
+public final class RightBoundFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -113,7 +113,7 @@
}
/**
- * Adapt a BinaryFunction to the UnaryFunction interface.
+ * Adapt a BinaryFunction to the Function interface.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param <T> the returned value type.
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
index 84cb11c..130c85e 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryPredicate BinaryPredicate}
* to the
- * {@link UnaryPredicate UnaryPredicate} interface
+ * {@link Predicate Predicate} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -39,7 +39,7 @@
* @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class RightBoundPredicate<A> implements UnaryPredicate<A>, Serializable {
+public final class RightBoundPredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -113,7 +113,7 @@
}
/**
- * Adapt a BinaryPredicate as a UnaryPredicate.
+ * Adapt a BinaryPredicate as a Predicate.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param predicate to adapt
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
index dd63307..5e0436c 100644
--- a/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
@@ -19,14 +19,14 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
* Adapts a
* {@link BinaryProcedure BinaryProcedure}
* to the
- * {@link UnaryProcedure UnaryProcedure} interface
+ * {@link Procedure Procedure} interface
* using a constant left-side argument.
* <p/>
* Note that although this class implements
@@ -39,7 +39,7 @@
* @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class RightBoundProcedure<A> implements UnaryProcedure<A>, Serializable {
+public final class RightBoundProcedure<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -113,7 +113,7 @@
}
/**
- * Get a UnaryProcedure from <code>procedure</code>.
+ * Get a Procedure from <code>procedure</code>.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param procedure to adapt
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java b/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
deleted file mode 100644
index 5f76993..0000000
--- a/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryPredicate.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import java.io.Serializable;
-
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.lang3.Validate;
-
-/**
- * Adapts a <code>Boolean</code>-valued
- * {@link UnaryFunction UnaryFunction}
- * to the {@link UnaryPredicate UnaryPredicate}
- * interface.
- * <p/>
- * Note that although this class implements
- * {@link Serializable}, a given instance will
- * only be truly <code>Serializable</code> if the
- * underlying function is. Attempts to serialize
- * an instance whose delegate is not
- * <code>Serializable</code> will result in an exception.
- *
- * @param <A> the argument type.
- * @version $Revision$ $Date$
- */
-public final class UnaryFunctionUnaryPredicate<A> implements UnaryPredicate<A>, Serializable {
- /**
- * serialVersionUID declaration.
- */
- private static final long serialVersionUID = -9211927278252224707L;
- /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
- private final UnaryFunction<? super A, Boolean> function;
-
- /**
- * Create an {@link UnaryPredicate UnaryPredicate} wrapping
- * the given {@link UnaryFunction UnaryFunction}.
- * @param function the {@link UnaryFunction UnaryFunction} to wrap
- */
- public UnaryFunctionUnaryPredicate(UnaryFunction<? super A, Boolean> function) {
- this.function = Validate.notNull(function, "UnaryFunction argument was null");
- }
-
- /**
- * {@inheritDoc}
- * Returns the <code>boolean</code> value of the non-<code>null</code>
- * <code>Boolean</code> returned by the {@link UnaryFunction#evaluate evaluate}
- * method of my underlying function.
- */
- public boolean test(A obj) {
- return function.evaluate(obj).booleanValue();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object that) {
- return that == this
- || (that instanceof UnaryFunctionUnaryPredicate<?> && equals((UnaryFunctionUnaryPredicate<?>) that));
- }
-
- /**
- * Learn whether another UnaryFunctionUnaryPredicate is equal to this.
- * @param that UnaryFunctionUnaryPredicate to test
- * @return boolean
- */
- public boolean equals(UnaryFunctionUnaryPredicate<?> that) {
- return null != that && function.equals(that.function);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- int hash = "UnaryFunctionUnaryPredicate".hashCode();
- hash ^= function.hashCode();
- return hash;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "UnaryFunctionUnaryPredicate<" + function + ">";
- }
-
- /**
- * Adapt the given, possibly-<code>null</code>,
- * {@link UnaryFunction UnaryFunction} to the
- * {@link UnaryPredicate UnaryPredicate} interface.
- * When the given <code>UnaryFunction</code> is <code>null</code>,
- * returns <code>null</code>.
- *
- * @param <A> the argument type.
- * @param function the possibly-<code>null</code>
- * {@link UnaryFunction UnaryFunction} to adapt
- * @return a {@link UnaryPredicate UnaryPredicate} wrapping the given
- * {@link UnaryFunction UnaryFunction}, or <code>null</code>
- * if the given <code>UnaryFunction</code> is <code>null</code>
- */
- public static <A> UnaryFunctionUnaryPredicate<A> adapt(UnaryFunction<? super A, Boolean> function) {
- return null == function ? null : new UnaryFunctionUnaryPredicate<A>(function);
- }
-
-}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java b/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
deleted file mode 100644
index f769af4..0000000
--- a/core/src/main/java/org/apache/commons/functor/adapter/UnaryFunctionUnaryProcedure.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import java.io.Serializable;
-
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.lang3.Validate;
-
-/**
- * Adapts a {@link UnaryFunction UnaryFunction}
- * to the {@link UnaryProcedure UnaryProcedure}
- * interface by ignoring the value returned
- * by the function.
- * <p/>
- * Note that although this class implements
- * {@link Serializable}, a given instance will
- * only be truly <code>Serializable</code> if the
- * underlying function is. Attempts to serialize
- * an instance whose delegate is not
- * <code>Serializable</code> will result in an exception.
- *
- * @param <A> the argument type.
- * @version $Revision$ $Date$
- */
-public final class UnaryFunctionUnaryProcedure<A> implements UnaryProcedure<A>, Serializable {
-
- /**
- * serialVersionUID declaration.
- */
- private static final long serialVersionUID = -3578673875995684811L;
- /** The {@link UnaryFunction UnaryFunction} I'm wrapping. */
- private final UnaryFunction<? super A, ?> function;
-
- /**
- * Create an {@link UnaryProcedure UnaryProcedure} wrapping
- * the given {@link UnaryFunction UnaryFunction}.
- * @param function the {@link UnaryFunction UnaryFunction} to wrap
- */
- public UnaryFunctionUnaryProcedure(UnaryFunction<? super A, ?> function) {
- this.function = Validate.notNull(function, "UnaryFunction argument was null");
- }
-
- /**
- * {@link UnaryFunction#evaluate Evaluate} my function, but
- * ignore its returned value.
- * {@inheritDoc}
- */
- public void run(A obj) {
- function.evaluate(obj);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object that) {
- return that == this
- || (that instanceof UnaryFunctionUnaryProcedure<?> && equals((UnaryFunctionUnaryProcedure<?>) that));
- }
-
- /**
- * Learn whether a specified UnaryFunctionUnaryPredicate is equal to this.
- * @param that the UnaryFunctionUnaryPredicate to test
- * @return boolean
- */
- public boolean equals(UnaryFunctionUnaryProcedure<?> that) {
- return null != that && function.equals(that.function);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- int hash = "UnaryFunctionUnaryProcedure".hashCode();
- hash ^= function.hashCode();
- return hash;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "UnaryFunctionUnaryProcedure<" + function + ">";
- }
-
- /**
- * Adapt the given, possibly-<code>null</code>,
- * {@link UnaryFunction UnaryFunction} to the
- * {@link UnaryProcedure UnaryProcedure} interface.
- * When the given <code>UnaryFunction</code> is <code>null</code>,
- * returns <code>null</code>.
- *
- * @param <A> the argument type.
- * @param function the possibly-<code>null</code>
- * {@link UnaryFunction UnaryFunction} to adapt
- * @return a {@link UnaryProcedure UnaryProcedure} wrapping the given
- * {@link UnaryFunction UnaryFunction}, or <code>null</code>
- * if the given <code>UnaryFunction</code> is <code>null</code>
- */
- public static <A> UnaryFunctionUnaryProcedure<A> adapt(UnaryFunction<? super A, ?> function) {
- return null == function ? null : new UnaryFunctionUnaryProcedure<A>(function);
- }
-
-}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java
deleted file mode 100644
index ae6cac6..0000000
--- a/core/src/main/java/org/apache/commons/functor/adapter/UnaryPredicateUnaryFunction.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import java.io.Serializable;
-
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.lang3.Validate;
-
-/**
- * Adapts a
- * {@link UnaryPredicate UnaryPredicate}
- * to the
- * {@link UnaryFunction UnaryFunction} interface.
- * <p/>
- * Note that although this class implements
- * {@link Serializable}, a given instance will
- * only be truly <code>Serializable</code> if the
- * underlying predicate is. Attempts to serialize
- * an instance whose delegate is not
- * <code>Serializable</code> will result in an exception.
- *
- * @param <A> the argument type.
- * @version $Revision$ $Date$
- */
-public final class UnaryPredicateUnaryFunction<A> implements UnaryFunction<A, Boolean>, Serializable {
- /**
- * serialVersionUID declaration.
- */
- private static final long serialVersionUID = 5660724725036398625L;
- /** The {@link UnaryPredicate UnaryPredicate} I'm wrapping. */
- private final UnaryPredicate<? super A> predicate;
-
- /**
- * Create a new UnaryPredicateUnaryFunction.
- * @param predicate to adapt
- */
- public UnaryPredicateUnaryFunction(UnaryPredicate<? super A> predicate) {
- this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
- }
-
- /**
- * {@inheritDoc}
- * Returns <code>Boolean.TRUE</code> (<code>Boolean.FALSE</code>)
- * when the {@link UnaryPredicate#test test} method of my underlying
- * predicate returns <code>true</code> (<code>false</code>).
- *
- * @return a non-<code>null</code> <code>Boolean</code> instance
- */
- public Boolean evaluate(A obj) {
- return Boolean.valueOf(predicate.test(obj));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object that) {
- return that == this
- || (that instanceof UnaryPredicateUnaryFunction<?> && equals((UnaryPredicateUnaryFunction<?>) that));
- }
-
- /**
- * Learn whether another UnaryPredicateUnaryFunction is equal to this.
- * @param that UnaryPredicateUnaryFunction to test
- * @return boolean
- */
- public boolean equals(UnaryPredicateUnaryFunction<?> that) {
- return null != that && predicate.equals(that.predicate);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- int hash = "UnaryPredicateUnaryFunction".hashCode();
- hash ^= predicate.hashCode();
- return hash;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "UnaryPredicateUnaryFunction<" + predicate + ">";
- }
-
- /**
- * Adapt a UnaryPredicate to the UnaryFunction interface.
- * @param <A> the argument type.
- * @param predicate to adapt
- * @return UnaryPredicateUnaryFunction
- */
- public static <A> UnaryPredicateUnaryFunction<A> adapt(UnaryPredicate<? super A> predicate) {
- return null == predicate ? null : new UnaryPredicateUnaryFunction<A>(predicate);
- }
-
-}
diff --git a/core/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java
deleted file mode 100644
index 0ebcb9a..0000000
--- a/core/src/main/java/org/apache/commons/functor/adapter/UnaryProcedureUnaryFunction.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import java.io.Serializable;
-
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.lang3.Validate;
-
-/**
- * Adapts a
- * {@link UnaryProcedure UnaryProcedure}
- * to the
- * {@link UnaryFunction UnaryFunction} interface
- * by always returning <code>null</code>.
- * <p/>
- * Note that although this class implements
- * {@link Serializable}, a given instance will
- * only be truly <code>Serializable</code> if the
- * underlying procedure is. Attempts to serialize
- * an instance whose delegate is not
- * <code>Serializable</code> will result in an exception.
- *
- * @param <A> the argument type.
- * @param <T> the returned value type.
- * @version $Revision$ $Date$
- */
-public final class UnaryProcedureUnaryFunction<A, T> implements UnaryFunction<A, T>, Serializable {
- /**
- * serialVersionUID declaration.
- */
- private static final long serialVersionUID = 6153848695167906659L;
- /** The {@link UnaryProcedure UnaryProcedure} I'm wrapping. */
- private final UnaryProcedure<? super A> procedure;
-
- /**
- * Create a new UnaryProcedureUnaryFunction.
- * @param procedure to adapt
- */
- public UnaryProcedureUnaryFunction(UnaryProcedure<? super A> procedure) {
- this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
- }
-
- /**
- * {@inheritDoc}
- */
- public T evaluate(A obj) {
- procedure.run(obj);
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object that) {
- return that == this || (that instanceof UnaryProcedureUnaryFunction<?, ?>
- && equals((UnaryProcedureUnaryFunction<?, ?>) that));
- }
-
- /**
- * Learn whether a given UnaryProcedureUnaryFunction is equal to this.
- * @param that UnaryProcedureUnaryFunction to test
- * @return boolean
- */
- public boolean equals(UnaryProcedureUnaryFunction<?, ?> that) {
- return null != that && procedure.equals(that.procedure);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- int hash = "UnaryProcedureUnaryFunction".hashCode();
- hash ^= procedure.hashCode();
- return hash;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "UnaryProcedureUnaryFunction<" + procedure + ">";
- }
-
- /**
- * Adapt a UnaryProcedure to the UnaryFunction interface.
- * @param <A> the argument type.
- * @param <T> the returned value type.
- * @param procedure to adapt
- * @return UnaryProcedureUnaryFunction
- */
- public static <A, T> UnaryProcedureUnaryFunction<A, T> adapt(UnaryProcedure<? super A> procedure) {
- return null == procedure ? null : new UnaryProcedureUnaryFunction<A, T>(procedure);
- }
-
-}
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java b/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java
index 0e7e16a..7993ebc 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java
@@ -18,7 +18,7 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
@@ -28,7 +28,7 @@
* List implementation they need to used -- and the abstract factory
* {@link #createList()} is provided for this.
* <p>This implementation also allows for various "aggregations" of the list to be
- * used by providing a {@link UnaryFunction UnaryFunction<List<T>, T>} in the
+ * used by providing a {@link Function Function<List<T>, T>} in the
* constructor.</p>
* <p>
* <b>Thread safety</b> : Note that due to the fact that
@@ -52,24 +52,24 @@
* Used to actually aggregate the data when {@link #evaluate()} is called.
* This is set in {@link #AbstractListBackedAggregator() the constructor}.
*/
- private UnaryFunction<List<T>, T> aggregationFunction;
+ private Function<List<T>, T> aggregationFunction;
/**
* Default constructor. Similar to
- * {@link #AbstractListBackedAggregator(UnaryFunction, long)
+ * {@link #AbstractListBackedAggregator(Function, long)
* AbstractListBackedAggregator(aggregationFunction,0L}.
*
* @param aggregationFunction
* Aggregation function to use in {@link #evaluate()}. Throws
* <code>NullPointerException</code> if this is <code>null</code>
*/
- public AbstractListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction) {
+ public AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction) {
this(aggregationFunction, 0L);
}
/**
* Similar to
- * {@link #AbstractListBackedAggregator(UnaryFunction, long, boolean)
+ * {@link #AbstractListBackedAggregator(Function, long, boolean)
* AbstractListBackedAggregator(aggregationFunction,interval,false}.
*
* @param aggregationFunction
@@ -78,7 +78,7 @@
* @param interval
* interval in miliseconds to reset this aggregator
*/
- public AbstractListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval) {
+ public AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval) {
this(aggregationFunction, interval, false);
}
@@ -97,10 +97,10 @@
* ; otherwise if it's false it will use its own timer instance
* @see AbstractTimedAggregator#AbstractTimedAggregator(long, boolean)
*/
- public AbstractListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval,
+ public AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval,
boolean useSharedTimer) {
super(interval, useSharedTimer);
- this.aggregationFunction = Validate.notNull(aggregationFunction, "UnaryFunction argument must not be null");
+ this.aggregationFunction = Validate.notNull(aggregationFunction, "Function argument must not be null");
this.series = createList();
}
@@ -173,7 +173,7 @@
*
* @return Current value of {@link #aggregationFunction}
*/
- final UnaryFunction<List<T>, T> getAggregationFunction() {
+ final Function<List<T>, T> getAggregationFunction() {
return aggregationFunction;
}
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java b/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java
index 3020f70..c9e2e98 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.aggregator;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
/**
* Interface which offers a means of "aggregating" data. It offers functions
@@ -36,7 +36,7 @@
* @param <T>
* type of data to aggregate
*/
-public interface Aggregator<T> extends Function<T> {
+public interface Aggregator<T> extends NullaryFunction<T> {
/**
* Adds data to the series which will be aggregated. It doesn't enforce any
* limitations on how much data can be stored (or in fact whether it should
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java b/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java
index 1bb30f9..4b7503b 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java
@@ -19,7 +19,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Implementation of an aggregator which stores the data series in an
@@ -30,20 +30,20 @@
*/
public class ArrayListBackedAggregator<T> extends AbstractListBackedAggregator<T> {
/**
- * Similar to {@link #ArrayListBackedAggregator(UnaryFunction, long)
+ * Similar to {@link #ArrayListBackedAggregator(Function, long)
* ArrayListBackedAggregator(aggregationFunction, 0L)}.
*
* @param aggregationFunction
* Aggregation function to use in {@link #evaluate()}. Throws
* <code>NullPointerException</code> if this is <code>null</code>
*/
- public ArrayListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction) {
+ public ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction) {
this(aggregationFunction, 0L);
}
/**
* Similar to
- * {@link #ArrayListBackedAggregator(UnaryFunction, long, boolean)
+ * {@link #ArrayListBackedAggregator(Function, long, boolean)
* ArrayListBackedAggregator(aggregationFunction,interval,false)}.
*
* @param aggregationFunction
@@ -52,7 +52,7 @@
* @param interval
* interval in miliseconds to reset this aggregator
*/
- public ArrayListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval) {
+ public ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval) {
this(aggregationFunction, interval, false);
}
@@ -70,7 +70,7 @@
* {@link AbstractTimedAggregator#AbstractTimedAggregator(long,boolean)}
* , otherwise this instance will use its private timer
*/
- public ArrayListBackedAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval,
+ public ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval,
boolean useSharedTimer) {
super(aggregationFunction, interval, useSharedTimer);
}
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java
index e9e385b..5f1a865 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java
@@ -18,7 +18,7 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -26,7 +26,7 @@
* which finds the maximum number in a list. It does this by traversing the list
* (once) -- so the complexity of this will be <i>O(n)</i>.
*/
-public class DoubleMaxAggregatorFunction implements UnaryFunction<List<Double>, Double> {
+public class DoubleMaxAggregatorFunction implements Function<List<Double>, Double> {
/**
* Does the actual traversal of the list and finds the maximum value then
* returns the result. Please note that caller is responsible for
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMeanValueAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMeanValueAggregatorFunction.java
index bd64aec..de82bf4 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMeanValueAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMeanValueAggregatorFunction.java
@@ -18,14 +18,14 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
* {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator}
* which computes the arithmetic mean of all the numbers in the list.
*/
-public final class DoubleMeanValueAggregatorFunction implements UnaryFunction<List<Double>, Double> {
+public final class DoubleMeanValueAggregatorFunction implements Function<List<Double>, Double> {
/**
* Does the actual computation and returns the result. Please note that
* caller is responsible for synchronizing access to the list.
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMedianValueAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMedianValueAggregatorFunction.java
index eecdbd3..52d0112 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMedianValueAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMedianValueAggregatorFunction.java
@@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -28,7 +28,7 @@
* which computes the <a href="http://en.wikipedia.org/wiki/Median">median</a>
* of all the numbers in the list.
*/
-public final class DoubleMedianValueAggregatorFunction implements UnaryFunction<List<Double>, Double> {
+public final class DoubleMedianValueAggregatorFunction implements Function<List<Double>, Double> {
/**
* Flag to indicate whether we are going to operate on a copy of the list
* given or not. In order to compute the median, we need to sort the list
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoublePercentileAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoublePercentileAggregatorFunction.java
index 2b00f40..17ca581 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoublePercentileAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoublePercentileAggregatorFunction.java
@@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -31,7 +31,7 @@
* using formula: <code>n = round((P / 100) * N + 0.5)</code> where N is the
* number of items in a list.
*/
-public class DoublePercentileAggregatorFunction implements UnaryFunction<List<Double>, Double> {
+public class DoublePercentileAggregatorFunction implements Function<List<Double>, Double> {
/** A percentile goes from 0 to 100% and that's it. */
private static final double MAX_PERCENTAGE = 100.0;
/**
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorFunction.java
index bc15a72..70b2bb4 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleSumAggregatorFunction.java
@@ -18,14 +18,14 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
* {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator}
* which sums up all the numbers in the list.
*/
-public final class DoubleSumAggregatorFunction implements UnaryFunction<List<Double>, Double> {
+public final class DoubleSumAggregatorFunction implements Function<List<Double>, Double> {
/**
* Does the actual adding and returns the result. Please note that caller is
* responsible for synchronizing access to the list.
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorFunction.java
index 35823bc..c17c60f 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMaxAggregatorFunction.java
@@ -18,7 +18,7 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -26,7 +26,7 @@
* which finds the maximum number in a list. It does this by traversing the list
* (once) -- so the complexity of this will be <i>O(n)</i>.
*/
-public class IntegerMaxAggregatorFunction implements UnaryFunction<List<Integer>, Integer> {
+public class IntegerMaxAggregatorFunction implements Function<List<Integer>, Integer> {
/**
* Does the actual traversal of the list and finds the maximum value then
* returns the result. Please note that caller is responsible for
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMeanValueAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMeanValueAggregatorFunction.java
index 9c73935..64a4471 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMeanValueAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMeanValueAggregatorFunction.java
@@ -18,14 +18,14 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
* {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator}
* which computes the arithmetic mean of all the numbers in the list.
*/
-public final class IntegerMeanValueAggregatorFunction implements UnaryFunction<List<Integer>, Integer> {
+public final class IntegerMeanValueAggregatorFunction implements Function<List<Integer>, Integer> {
/**
* Does the actual computation and returns the result. Please note that
* caller is responsible for synchronizing access to the list.
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMedianValueAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMedianValueAggregatorFunction.java
index dd247d5..daa28e2 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMedianValueAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerMedianValueAggregatorFunction.java
@@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -28,7 +28,7 @@
* which computes the <a href="http://en.wikipedia.org/wiki/Median">median</a>
* of all the numbers in the list.
*/
-public final class IntegerMedianValueAggregatorFunction implements UnaryFunction<List<Integer>, Integer> {
+public final class IntegerMedianValueAggregatorFunction implements Function<List<Integer>, Integer> {
/**
* Flag to indicate whether we are going to operate on a copy of the list
* given or not. In order to compute the median, we need to sort the list
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerPercentileAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerPercentileAggregatorFunction.java
index 1214c06..0cd392e 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerPercentileAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerPercentileAggregatorFunction.java
@@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
@@ -31,7 +31,7 @@
* using formula: <code>n = round((P / 100) * N + 0.5)</code> where N is the
* number of items in a list.
*/
-public class IntegerPercentileAggregatorFunction implements UnaryFunction<List<Integer>, Integer> {
+public class IntegerPercentileAggregatorFunction implements Function<List<Integer>, Integer> {
/** A percentile goes from 0 to 100% and that's it. */
private static final double MAX_PERCENTAGE = 100.0;
/**
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorFunction.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorFunction.java
index 3c3bc62..aabd322 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/IntegerSumAggregatorFunction.java
@@ -18,14 +18,14 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Aggregator function to be used with subclasses of
* {@link org.apache.commons.functor.aggregator.AbstractListBackedAggregator}
* which sums up all the numbers in the list.
*/
-public final class IntegerSumAggregatorFunction implements UnaryFunction<List<Integer>, Integer> {
+public final class IntegerSumAggregatorFunction implements Function<List<Integer>, Integer> {
/**
* Does the actual adding and returns the result. Please note that caller is
* responsible for synchronizing access to the list.
diff --git a/core/src/main/java/org/apache/commons/functor/aggregator/functions/package-info.java b/core/src/main/java/org/apache/commons/functor/aggregator/functions/package-info.java
index 338a766..7b9476f 100644
--- a/core/src/main/java/org/apache/commons/functor/aggregator/functions/package-info.java
+++ b/core/src/main/java/org/apache/commons/functor/aggregator/functions/package-info.java
@@ -17,7 +17,7 @@
/**
* <p>
- * This package contains <code>UnaryFunction</code>'s used by aggregators
+ * This package contains <code>Function</code>'s used by aggregators
* defined in <code>org.apache.commons.functor.aggregator</code>.
* </p>
* <p>
diff --git a/core/src/main/java/org/apache/commons/functor/core/Constant.java b/core/src/main/java/org/apache/commons/functor/core/Constant.java
index 8c53888..d2c432c 100644
--- a/core/src/main/java/org/apache/commons/functor/core/Constant.java
+++ b/core/src/main/java/org/apache/commons/functor/core/Constant.java
@@ -21,9 +21,9 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
/**
* {@link #evaluate Evaluates} to constant value.
@@ -41,8 +41,8 @@
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class Constant<T> implements Function<T>, UnaryFunction<Object, T>, BinaryFunction<Object, Object, T>,
- Predicate, UnaryPredicate<Object>, BinaryPredicate<Object, Object>, Serializable {
+public final class Constant<T> implements NullaryFunction<T>, Function<Object, T>, BinaryFunction<Object, Object, T>,
+ NullaryPredicate, Predicate<Object>, BinaryPredicate<Object, Object>, Serializable {
// static attributes
// ------------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/commons/functor/core/Identity.java b/core/src/main/java/org/apache/commons/functor/core/Identity.java
index 75aa461..77a7f43 100644
--- a/core/src/main/java/org/apache/commons/functor/core/Identity.java
+++ b/core/src/main/java/org/apache/commons/functor/core/Identity.java
@@ -18,8 +18,8 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
/**
* {@link #evaluate Evaluates} to its input argument.
@@ -33,7 +33,7 @@
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class Identity<T> implements UnaryFunction<T, T>, UnaryPredicate<T>, Serializable {
+public final class Identity<T> implements Function<T, T>, Predicate<T>, Serializable {
// static attributes
// ------------------------------------------------------------------------
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsEqual.java b/core/src/main/java/org/apache/commons/functor/core/IsEqual.java
index 9e24043..718e195 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsEqual.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsEqual.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
/**
@@ -104,13 +104,13 @@
}
/**
- * Get an IsEqual UnaryPredicate.
+ * Get an IsEqual Predicate.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param object bound comparison object
- * @return UnaryPredicate<L>
+ * @return Predicate<L>
*/
- public static <L, R> UnaryPredicate<L> to(R object) {
+ public static <L, R> Predicate<L> to(R object) {
return new RightBoundPredicate<L>(new IsEqual<L, R>(), object);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsInstance.java b/core/src/main/java/org/apache/commons/functor/core/IsInstance.java
index 9985f9b..4b047fb 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsInstance.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsInstance.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
/**
@@ -93,12 +93,12 @@
}
/**
- * Get an IsInstanceOf UnaryPredicate.
+ * Get an IsInstanceOf Predicate.
* @param <T> the object instance has to be tested against the input class.
* @param clazz bound right-side argument
- * @return UnaryPredicate<T>
+ * @return Predicate<T>
*/
- public static <T> UnaryPredicate<T> of(Class<?> clazz) {
+ public static <T> Predicate<T> of(Class<?> clazz) {
return RightBoundPredicate.bind(new IsInstance<T>(), clazz);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsNotEqual.java b/core/src/main/java/org/apache/commons/functor/core/IsNotEqual.java
index 003e6ac..7795654 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsNotEqual.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsNotEqual.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
/**
@@ -102,13 +102,13 @@
}
/**
- * Get an IsNotEqual UnaryPredicate.
+ * Get an IsNotEqual Predicate.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param object bound comparison object
- * @return UnaryPredicate<L>
+ * @return Predicate<L>
*/
- public static <L, R> UnaryPredicate<L> to(R object) {
+ public static <L, R> Predicate<L> to(R object) {
return new RightBoundPredicate<L>(new IsNotEqual<L, R>(), object);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsNotNull.java b/core/src/main/java/org/apache/commons/functor/core/IsNotNull.java
index 35158a2..8baf617 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsNotNull.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsNotNull.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.IgnoreLeftPredicate;
import org.apache.commons.functor.adapter.IgnoreRightPredicate;
@@ -31,7 +31,7 @@
* @param <T> the argument type.
* @version $Revision$ $Date$
*/
-public final class IsNotNull<T> implements UnaryPredicate<T>, Serializable {
+public final class IsNotNull<T> implements Predicate<T>, Serializable {
// static attributes
// ------------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsNotSame.java b/core/src/main/java/org/apache/commons/functor/core/IsNotSame.java
index b6fd271..4047655 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsNotSame.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsNotSame.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
/**
@@ -95,13 +95,13 @@
}
/**
- * Get an IsNotSame UnaryPredicate.
+ * Get an IsNotSame Predicate.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param object bound comparison object
- * @return UnaryPredicate<L>
+ * @return Predicate<L>
*/
- public static <L, R> UnaryPredicate<L> as(R object) {
+ public static <L, R> Predicate<L> as(R object) {
return new RightBoundPredicate<L>(new IsNotSame<L, R>(), object);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsNull.java b/core/src/main/java/org/apache/commons/functor/core/IsNull.java
index a9bcca2..17a75a9 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsNull.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsNull.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.IgnoreLeftPredicate;
import org.apache.commons.functor.adapter.IgnoreRightPredicate;
@@ -31,7 +31,7 @@
* @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class IsNull<A> implements UnaryPredicate<A>, Serializable {
+public final class IsNull<A> implements Predicate<A>, Serializable {
// static attributes
// ------------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/commons/functor/core/IsSame.java b/core/src/main/java/org/apache/commons/functor/core/IsSame.java
index 8d145de..13570c1 100644
--- a/core/src/main/java/org/apache/commons/functor/core/IsSame.java
+++ b/core/src/main/java/org/apache/commons/functor/core/IsSame.java
@@ -19,7 +19,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
/**
@@ -95,13 +95,13 @@
}
/**
- * Get an IsSame UnaryPredicate.
+ * Get an IsSame Predicate.
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param object bound comparison object
- * @return UnaryPredicate<L>
+ * @return Predicate<L>
*/
- public static <L, R> UnaryPredicate<L> as(R object) {
+ public static <L, R> Predicate<L> as(R object) {
return new RightBoundPredicate<L>(new IsSame<L, R>(), object);
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/Limit.java b/core/src/main/java/org/apache/commons/functor/core/Limit.java
index e5451d6..611bc5a 100644
--- a/core/src/main/java/org/apache/commons/functor/core/Limit.java
+++ b/core/src/main/java/org/apache/commons/functor/core/Limit.java
@@ -20,8 +20,8 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
/**
* A predicate that returns <code>true</code>
@@ -31,7 +31,7 @@
* @since 1.0
* @version $Revision$ $Date$
*/
-public final class Limit implements Predicate, UnaryPredicate<Object>, BinaryPredicate<Object, Object>, Serializable {
+public final class Limit implements NullaryPredicate, Predicate<Object>, BinaryPredicate<Object, Object>, Serializable {
// static attributes
// ------------------------------------------------------------------------
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/NoOp.java b/core/src/main/java/org/apache/commons/functor/core/NoOp.java
index 06c2104..0b9cc54 100644
--- a/core/src/main/java/org/apache/commons/functor/core/NoOp.java
+++ b/core/src/main/java/org/apache/commons/functor/core/NoOp.java
@@ -19,18 +19,18 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryProcedure;
/**
* A procedure that does nothing at all.
* <p>
* Note that this class implements {@link Procedure},
- * {@link UnaryProcedure}, and {@link BinaryProcedure}.
+ * {@link Procedure}, and {@link BinaryProcedure}.
* </p>
* @version $Revision$ $Date$
*/
-public final class NoOp implements Procedure, UnaryProcedure<Object>, BinaryProcedure<Object, Object>, Serializable {
+public final class NoOp implements NullaryProcedure, Procedure<Object>, BinaryProcedure<Object, Object>, Serializable {
// static attributes
// ------------------------------------------------------------------------
/**
@@ -105,13 +105,13 @@
}
/**
- * Get a typed NoOp {@link UnaryProcedure}.
+ * Get a typed NoOp {@link Procedure}.
* @param <A> type
- * @return <code>UnaryProcedure<A></code>
+ * @return <code>Procedure<A></code>
*/
@SuppressWarnings("unchecked")
- public static <A> UnaryProcedure<A> unaryInstance() {
- return (UnaryProcedure<A>) INSTANCE;
+ public static <A> Procedure<A> unaryInstance() {
+ return (Procedure<A>) INSTANCE;
}
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/Offset.java b/core/src/main/java/org/apache/commons/functor/core/Offset.java
index cd1c3bf..3d7755a 100644
--- a/core/src/main/java/org/apache/commons/functor/core/Offset.java
+++ b/core/src/main/java/org/apache/commons/functor/core/Offset.java
@@ -19,8 +19,8 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
/**
* A predicate that returns <code>false</code>
@@ -30,7 +30,8 @@
* @since 1.0
* @version $Revision$ $Date$
*/
-public final class Offset implements Predicate, UnaryPredicate<Object>, BinaryPredicate<Object, Object>, Serializable {
+public final class Offset implements NullaryPredicate, Predicate<Object>,
+ BinaryPredicate<Object, Object>, Serializable {
// static attributes
// ------------------------------------------------------------------------
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java
index e51bb41..233e74d 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.functor.core.algorithm;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
* Do-until algorithm (test after).
@@ -36,7 +36,7 @@
* @param body to execute
* @param test whether to keep going
*/
- public DoUntil(Procedure body, Predicate test) {
+ public DoUntil(NullaryProcedure body, NullaryPredicate test) {
super(body, test);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java
index 1f37a3d..aca79d5 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.functor.core.algorithm;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
* Do-while algorithm (test after).
@@ -36,7 +36,7 @@
* @param body to execute
* @param test whether to keep going
*/
- public DoWhile(Procedure body, Predicate test) {
+ public DoWhile(NullaryProcedure body, NullaryPredicate test) {
super(body, test);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java
index 4025fd2..29bd45e 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java
@@ -20,18 +20,18 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
/**
- * Return the first Object in a {@link Generator} matching a {@link UnaryPredicate}.
+ * Return the first Object in a {@link Generator} matching a {@link Predicate}.
*
* @param <E> the arguments type.
* @version $Revision$ $Date$
*/
public final class FindWithinGenerator<E>
- implements BinaryFunction<Generator<? extends E>, UnaryPredicate<? super E>, E>, Serializable {
+ implements BinaryFunction<Generator<? extends E>, Predicate<? super E>, E>, Serializable {
/**
* Basic instance.
@@ -48,7 +48,7 @@
*
* @param <T> the argument type.
*/
- private static class FindProcedure<T> implements UnaryProcedure<T> {
+ private static class FindProcedure<T> implements Procedure<T> {
/**
* The object found, if any.
*/
@@ -60,13 +60,13 @@
/**
* The adapted predicate.
*/
- private UnaryPredicate<? super T> pred;
+ private Predicate<? super T> pred;
/**
* Create a new FindProcedure.
* @param pred the adapted predicate.
*/
- public FindProcedure(UnaryPredicate<? super T> pred) {
+ public FindProcedure(Predicate<? super T> pred) {
this.pred = pred;
}
@@ -82,7 +82,7 @@
}
/**
- * Flag to mark the {@link FindWithinGenerator#evaluate(Generator, UnaryPredicate)} method must return a user
+ * Flag to mark the {@link FindWithinGenerator#evaluate(Generator, Predicate)} method must return a user
* defined object when the adapted procedure does not find any object.
*/
private final boolean useIfNone;
@@ -113,9 +113,9 @@
/**
* {@inheritDoc}
* @param left Generator
- * @param right UnaryPredicate
+ * @param right Predicate
*/
- public E evaluate(Generator<? extends E> left, UnaryPredicate<? super E> right) {
+ public E evaluate(Generator<? extends E> left, Predicate<? super E> right) {
FindProcedure<E> findProcedure = new FindProcedure<E>(right);
left.run(findProcedure);
if (!findProcedure.wasFound) {
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
index c3362f4..37b8482 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java
@@ -19,8 +19,8 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
/**
@@ -32,7 +32,7 @@
* @param <T> the returned evaluation type.
* @version $Revision$ $Date$
*/
-public class FoldLeft<T> implements UnaryFunction<Generator<T>, T>, BinaryFunction<Generator<T>, T, T>, Serializable {
+public class FoldLeft<T> implements Function<Generator<T>, T>, BinaryFunction<Generator<T>, T, T>, Serializable {
/**
* serialVersionUID declaration.
@@ -44,7 +44,7 @@
*
* @param <T> the returned evaluation type.
*/
- private static class FoldLeftHelper<T> implements UnaryProcedure<T> {
+ private static class FoldLeftHelper<T> implements Procedure<T> {
/**
* The wrapped function.
*/
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
index ca80b06..f24c0d7 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldRight.java
@@ -20,8 +20,8 @@
import java.util.Stack;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
/**
@@ -33,7 +33,7 @@
* @param <T> the returned evaluation type.
* @version $Revision$ $Date$
*/
-public class FoldRight<T> implements UnaryFunction<Generator<T>, T>, BinaryFunction<Generator<T>, T, T>, Serializable {
+public class FoldRight<T> implements Function<Generator<T>, T>, BinaryFunction<Generator<T>, T, T>, Serializable {
/**
* serialVersionUID declaration.
@@ -45,7 +45,7 @@
*
* @param <T> the returned evaluation type.
*/
- private static class FoldRightHelper<T> implements UnaryProcedure<T> {
+ private static class FoldRightHelper<T> implements Procedure<T> {
/**
* The stack where storing the wrapped function evaluations.
*/
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
index dcbeabb..280b5da 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/GeneratorContains.java
@@ -19,17 +19,17 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
/**
- * Tests whether a {@link Generator} contains an element that matches a {@link UnaryPredicate}.
+ * Tests whether a {@link Generator} contains an element that matches a {@link Predicate}.
*
* @param <T> the predicate argument type.
* @version $Revision$ $Date$
*/
-public final class GeneratorContains<T> implements BinaryPredicate<Generator<? extends T>, UnaryPredicate<? super T>>,
+public final class GeneratorContains<T> implements BinaryPredicate<Generator<? extends T>, Predicate<? super T>>,
Serializable {
/**
* serialVersionUID declaration.
@@ -45,11 +45,11 @@
*
* @param <T> the predicate argument type.
*/
- private static class ContainsProcedure<T> implements UnaryProcedure<T> {
+ private static class ContainsProcedure<T> implements Procedure<T> {
/**
* The wrapped predicate.
*/
- private final UnaryPredicate<? super T> pred;
+ private final Predicate<? super T> pred;
/**
* Flag to mark if the wrapped predicate succeeded or not.
*/
@@ -60,7 +60,7 @@
*
* @param pred The wrapped predicate
*/
- public ContainsProcedure(UnaryPredicate<? super T> pred) {
+ public ContainsProcedure(Predicate<? super T> pred) {
this.pred = pred;
}
@@ -75,9 +75,9 @@
/**
* {@inheritDoc}
* @param left Generator
- * @param right UnaryPredicate
+ * @param right Predicate
*/
- public boolean test(Generator<? extends T> left, UnaryPredicate<? super T> right) {
+ public boolean test(Generator<? extends T> left, Predicate<? super T> right) {
ContainsProcedure<T> findProcedure = new ContainsProcedure<T>(right);
left.run(findProcedure);
return findProcedure.found;
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java
index e05d87d..2197d7a 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/InPlaceTransform.java
@@ -20,7 +20,7 @@
import java.util.ListIterator;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Implements an in-place transformation of a ListIterator's contents.
@@ -29,7 +29,7 @@
* @version $Revision$ $Date$
*/
public final class InPlaceTransform<T>
- implements BinaryProcedure<ListIterator<T>, UnaryFunction<? super T, ? extends T>>, Serializable {
+ implements BinaryProcedure<ListIterator<T>, Function<? super T, ? extends T>>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -42,9 +42,9 @@
/**
* {@inheritDoc}
* @param left {@link ListIterator}
- * @param right {@link UnaryFunction}
+ * @param right {@link Function}
*/
- public void run(ListIterator<T> left, UnaryFunction<? super T, ? extends T> right) {
+ public void run(ListIterator<T> left, Function<? super T, ? extends T> right) {
while (left.hasNext()) {
left.set(right.evaluate(left.next()));
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
index bca447e..805eb35 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
@@ -19,18 +19,18 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
/**
- * Return the index of the first Object in a {@link Generator} matching a {@link UnaryPredicate}, or -1 if not found.
+ * Return the index of the first Object in a {@link Generator} matching a {@link Predicate}, or -1 if not found.
*
* @param <T> the procedure argument types
* @version $Revision$ $Date$
*/
public final class IndexOfInGenerator<T>
- implements BinaryFunction<Generator<? extends T>, UnaryPredicate<? super T>, Number>, Serializable {
+ implements BinaryFunction<Generator<? extends T>, Predicate<? super T>, Number>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -45,7 +45,7 @@
*
* @param <T> the procedure argument type
*/
- private static class IndexProcedure<T> implements UnaryProcedure<T> {
+ private static class IndexProcedure<T> implements Procedure<T> {
/**
* The wrapped generator.
*/
@@ -53,7 +53,7 @@
/**
* The wrapped predicate.
*/
- private final UnaryPredicate<? super T> pred;
+ private final Predicate<? super T> pred;
/**
* The number of iterations needed before the wrapped predicate found the target,
* {@code -1} means the target was not found.
@@ -70,7 +70,7 @@
* @param generator The wrapped generator
* @param pred The wrapped predicate
*/
- IndexProcedure(Generator<? extends T> generator, UnaryPredicate<? super T> pred) {
+ IndexProcedure(Generator<? extends T> generator, Predicate<? super T> pred) {
this.generator = generator;
this.pred = pred;
}
@@ -90,9 +90,9 @@
/**
* {@inheritDoc}
* @param left Generator
- * @param right UnaryPredicate
+ * @param right Predicate
*/
- public Number evaluate(Generator<? extends T> left, UnaryPredicate<? super T> right) {
+ public Number evaluate(Generator<? extends T> left, Predicate<? super T> right) {
IndexProcedure<T> findProcedure = new IndexProcedure<T>(left, right);
left.run(findProcedure);
return Long.valueOf(findProcedure.index);
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java
index bb710cf..db3a20f 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/PredicatedLoop.java
@@ -18,15 +18,15 @@
import java.io.Serializable;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
* Base class for predicated procedure algorithms.
*
* @version $Revision$ $Date$
*/
-abstract class PredicatedLoop implements Procedure, Serializable {
+abstract class PredicatedLoop implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -34,35 +34,35 @@
/**
* The procedure body to execute.
*/
- private final Procedure body;
+ private final NullaryProcedure body;
/**
* The test wether to keep going.
*/
- private final Predicate test;
+ private final NullaryPredicate test;
/**
* Create a new PredicatedLoop.
* @param body to execute
* @param test whether to keep going
*/
- protected PredicatedLoop(Procedure body, Predicate test) {
+ protected PredicatedLoop(NullaryProcedure body, NullaryPredicate test) {
this.body = body;
this.test = test;
}
/**
* Get the body of this loop.
- * @return Procedure
+ * @return NullaryProcedure
*/
- protected Procedure getBody() {
+ protected NullaryProcedure getBody() {
return body;
}
/**
* Get the test for this loop.
- * @return Predicate
+ * @return NullaryPredicate
*/
- protected Predicate getTest() {
+ protected NullaryPredicate getTest() {
return test;
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
index 66afca8..f4eab48 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/RecursiveEvaluation.java
@@ -18,47 +18,47 @@
import java.io.Serializable;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.lang3.Validate;
/**
- * Tail recursion for {@link Function functions}. If the {@link Function}
+ * Tail recursion for {@link NullaryFunction functions}. If the {@link NullaryFunction}
* returns another function of type <code>functionType</code>, that function
* is executed. Functions are executed until a non function value or a
* function of a type other than that expected is returned.
*/
-public class RecursiveEvaluation implements Function<Object>, Serializable {
+public class RecursiveEvaluation implements NullaryFunction<Object>, Serializable {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -7992078213921938619L;
/**
- * The initial recursive Function type.
+ * The initial recursive NullaryFunction type.
*/
private final Class<?> functionType;
/**
- * The initial, potentially recursive Function.
+ * The initial, potentially recursive NullaryFunction.
*/
- private Function<?> function;
+ private NullaryFunction<?> function;
/**
* Create a new RecursiveEvaluation. Recursion will continue while the
* returned value is of the same runtime class as <code>function</code>.
- * @param function initial, potentially recursive Function
+ * @param function initial, potentially recursive NullaryFunction
*/
- public RecursiveEvaluation(Function<?> function) {
+ public RecursiveEvaluation(NullaryFunction<?> function) {
this(function, getClass(function));
}
/**
* Create a new RecursiveEvaluation.
- * @param function initial, potentially recursive Function
+ * @param function initial, potentially recursive NullaryFunction
* @param functionType as long as result is an instance, keep processing.
*/
- public RecursiveEvaluation(Function<?> function, Class<?> functionType) {
- Validate.notNull(function, "Function argument was null");
- if (!Function.class.isAssignableFrom(functionType)) {
- throw new IllegalArgumentException(Function.class + " is not assignable from " + functionType);
+ public RecursiveEvaluation(NullaryFunction<?> function, Class<?> functionType) {
+ Validate.notNull(function, "NullaryFunction argument was null");
+ if (!NullaryFunction.class.isAssignableFrom(functionType)) {
+ throw new IllegalArgumentException(NullaryFunction.class + " is not assignable from " + functionType);
}
this.function = function;
this.functionType = Validate.notNull(functionType, "FunctionType argument was null");
@@ -74,7 +74,7 @@
while (true) {
result = function.evaluate();
if (functionType.isInstance(result)) {
- function = (Function<?>) result;
+ function = (NullaryFunction<?>) result;
continue;
} else {
break;
@@ -118,7 +118,7 @@
* @param f Object to check
* @return Class found
*/
- private static Class<?> getClass(Function<?> f) {
+ private static Class<?> getClass(NullaryFunction<?> f) {
return f == null ? null : f.getClass();
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java
index 62c1c2d..ad74516 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/RemoveMatching.java
@@ -20,16 +20,16 @@
import java.util.Iterator;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
/**
- * Remove elements from left Iterator that match right UnaryPredicate.
+ * Remove elements from left Iterator that match right Predicate.
*
* @param <T> the procedure argument type.
* @version $Revision$ $Date$
*/
public final class RemoveMatching<T>
- implements BinaryProcedure<Iterator<? extends T>, UnaryPredicate<? super T>>, Serializable {
+ implements BinaryProcedure<Iterator<? extends T>, Predicate<? super T>>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -42,9 +42,9 @@
/**
* {@inheritDoc}
* @param left {@link Iterator}
- * @param right {@link UnaryPredicate}
+ * @param right {@link Predicate}
*/
- public void run(Iterator<? extends T> left, UnaryPredicate<? super T> right) {
+ public void run(Iterator<? extends T> left, Predicate<? super T> right) {
while (left.hasNext()) {
if (right.test(left.next())) {
left.remove();
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java
index 5642757..72c6338 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/RetainMatching.java
@@ -20,17 +20,17 @@
import java.util.Iterator;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.core.composite.UnaryNot;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.core.composite.Not;
/**
- * Retain elements in left Iterator that match right UnaryPredicate.
+ * Retain elements in left Iterator that match right Predicate.
*
* @param <T> the procedure argument type
* @version $Revision$ $Date$
*/
public final class RetainMatching<T>
- implements BinaryProcedure<Iterator<? extends T>, UnaryPredicate<? super T>>, Serializable {
+ implements BinaryProcedure<Iterator<? extends T>, Predicate<? super T>>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -47,10 +47,10 @@
/**
* {@inheritDoc}
* @param left {@link Iterator}
- * @param right {@link UnaryPredicate}
+ * @param right {@link Predicate}
*/
- public void run(Iterator<? extends T> left, UnaryPredicate<? super T> right) {
- removeMatching.run(left, UnaryNot.not(right));
+ public void run(Iterator<? extends T> left, Predicate<? super T> right) {
+ removeMatching.run(left, Not.not(right));
}
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java
index f220d51..b5a301c 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/UntilDo.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.functor.core.algorithm;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
* Until-do algorithm (test before).
@@ -36,7 +36,7 @@
* @param test whether to keep going
* @param body to execute
*/
- public UntilDo(Predicate test, Procedure body) {
+ public UntilDo(NullaryPredicate test, NullaryProcedure body) {
super(body, test);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java b/core/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java
index 0d1ec04..5ccf802 100644
--- a/core/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java
+++ b/core/src/main/java/org/apache/commons/functor/core/algorithm/WhileDo.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.functor.core.algorithm;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
* While-do algorithm (test before).
@@ -36,7 +36,7 @@
* @param test whether to keep going
* @param body to execute
*/
- public WhileDo(Predicate test, Procedure body) {
+ public WhileDo(NullaryPredicate test, NullaryProcedure body) {
super(body, test);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java b/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java
index ea167f5..6594fa2 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java
@@ -19,10 +19,10 @@
import java.util.Collections;
import java.util.Iterator;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.IsInstance;
-import org.apache.commons.functor.core.composite.UnaryAnd;
+import org.apache.commons.functor.core.composite.And;
/**
* Adds a fluent filtering API to any {@link Iterable}.
@@ -50,7 +50,7 @@
* {@inheritDoc}
*/
@Override
- public FilteredIterable retain(UnaryPredicate predicate) {
+ public FilteredIterable retain(Predicate predicate) {
return this;
}
@@ -70,7 +70,7 @@
/**
* The predicate used to test input {@link Iterable} elements.
*/
- private UnaryAnd<T> predicate;
+ private And<T> predicate;
/**
* Create a new FilteredIterable.
@@ -85,7 +85,7 @@
* {@inheritDoc}
*/
public Iterator<T> iterator() {
- UnaryPredicate<T> predicateReference;
+ Predicate<T> predicateReference;
synchronized (this) {
predicateReference = predicate;
}
@@ -105,13 +105,13 @@
* @param filter filter predicate, non-<code>null</code>
* @return <code>this</code>, fluently
*/
- public FilteredIterable<T> retain(UnaryPredicate<? super T> filter) {
+ public FilteredIterable<T> retain(Predicate<? super T> filter) {
if (filter == null) {
throw new NullPointerException("filtering predicate was null");
}
synchronized (this) {
if (this.predicate == null) {
- this.predicate = new UnaryAnd<T>();
+ this.predicate = new And<T>();
}
this.predicate.and(filter);
}
@@ -134,7 +134,7 @@
public Iterator<U> iterator() {
return TransformedIterator.transform(
FilteredIterator.filter(FilteredIterable.this.iterator(), IsInstance.of(type)),
- new UnaryFunction<T, U>() {
+ new Function<T, U>() {
@SuppressWarnings("unchecked")
// this is okay because of the isinstance check
@@ -156,7 +156,7 @@
if (ofType == null) {
throw new NullPointerException("array of filtered types was null");
}
- return retain(new UnaryPredicate<T>() {
+ return retain(new Predicate<T>() {
public boolean test(T obj) {
for (Class<?> type : ofType) {
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java b/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
index c40b31e..c2606ba 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterator.java
@@ -19,12 +19,12 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* Iterator that filters another Iterator by only passing through those elements
- * that are matched by a specified UnaryPredicate.
+ * that are matched by a specified Predicate.
*
* @param <T> the {@link Iterator} generic type
* @version $Revision$ $Date$
@@ -36,7 +36,7 @@
/**
* The predicate used to test this Iterator elements.
*/
- private final UnaryPredicate<? super T> predicate;
+ private final Predicate<? super T> predicate;
/**
* The wrapped iterator.
*/
@@ -62,9 +62,9 @@
* @param iterator to filter
* @param predicate to apply
*/
- public FilteredIterator(Iterator<? extends T> iterator, UnaryPredicate<? super T> predicate) {
+ public FilteredIterator(Iterator<? extends T> iterator, Predicate<? super T> predicate) {
this.iterator = Validate.notNull(iterator, "Iterator argument was null");
- this.predicate = Validate.notNull(predicate, "filtering UnaryPredicate argument was null");
+ this.predicate = Validate.notNull(predicate, "filtering Predicate argument was null");
}
// iterator methods
@@ -148,7 +148,7 @@
* @return Iterator
*/
@SuppressWarnings("unchecked")
- public static <T> Iterator<T> filter(Iterator<? extends T> iter, UnaryPredicate<? super T> pred) {
+ public static <T> Iterator<T> filter(Iterator<? extends T> iter, Predicate<? super T> pred) {
return null == pred ? (Iterator<T>) iter : (null == iter ? null : new FilteredIterator<T>(iter, pred));
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java b/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
index d0c3f6d..5832bac 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java
@@ -21,7 +21,7 @@
import java.util.Collection;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -136,13 +136,13 @@
}
/**
- * Get an IsElementOf(collection|array) UnaryPredicate.
+ * Get an IsElementOf(collection|array) Predicate.
*
- * @param <A> the UnaryPredicate argument generic type
+ * @param <A> the Predicate argument generic type
* @param obj collection/array to search
- * @return UnaryPredicate
+ * @return Predicate
*/
- public static <A> UnaryPredicate<A> instance(Object obj) {
+ public static <A> Predicate<A> instance(Object obj) {
if (null == obj) {
throw new NullPointerException("Argument must not be null");
} else if (obj instanceof Collection<?>) {
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java b/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
index a4d063d..ec8d3cd 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java
@@ -21,14 +21,14 @@
import java.util.Collection;
import java.util.Map;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
* @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-public final class IsEmpty<A> implements UnaryPredicate<A>, Serializable {
+public final class IsEmpty<A> implements Predicate<A>, Serializable {
// class variables
// ------------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/Size.java b/core/src/main/java/org/apache/commons/functor/core/collection/Size.java
index 60e2c7f..d95f6cd 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/Size.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/Size.java
@@ -20,7 +20,7 @@
import java.lang.reflect.Array;
import java.util.Collection;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
@@ -30,7 +30,7 @@
* @param <A> the function argument type.
* @version $Revision$ $Date$
*/
-public final class Size<A> implements UnaryFunction<A, Integer>, Serializable {
+public final class Size<A> implements Function<A, Integer>, Serializable {
/**
* serialVersionUID declaration.
diff --git a/core/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java b/core/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
index eeee07e..6bc2699 100644
--- a/core/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
+++ b/core/src/main/java/org/apache/commons/functor/core/collection/TransformedIterator.java
@@ -18,11 +18,11 @@
import java.util.Iterator;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
- * Iterator that transforms another Iterator by applying a UnaryFunction to each returned element.
+ * Iterator that transforms another Iterator by applying a Function to each returned element.
*
* @param <E> the function argument type
* @param <T> the iterator elements type
@@ -36,7 +36,7 @@
/**
* The function to apply to each iterator element.
*/
- private final UnaryFunction<? super E, ? extends T> function;
+ private final Function<? super E, ? extends T> function;
/**
* The wrapped iterator.
*/
@@ -49,8 +49,8 @@
* @param iterator Iterator to decorate
* @param function to apply
*/
- public TransformedIterator(Iterator<? extends E> iterator, UnaryFunction<? super E, ? extends T> function) {
- this.function = Validate.notNull(function, "filtering UnaryFunction argument was null");
+ public TransformedIterator(Iterator<? extends E> iterator, Function<? super E, ? extends T> function) {
+ this.function = Validate.notNull(function, "filtering Function argument was null");
this.iterator = Validate.notNull(iterator, "Iterator argument was null");
}
@@ -128,7 +128,7 @@
* @param func transforming function, cannot be null
* @return Iterator<T>
*/
- public static <E, T> Iterator<T> transform(Iterator<? extends E> iter, UnaryFunction<? super E, ? extends T> func) {
+ public static <E, T> Iterator<T> transform(Iterator<? extends E> iter, Function<? super E, ? extends T> func) {
if (null == iter) {
return null;
}
@@ -143,7 +143,7 @@
* @param func transforming function, if null result is iter
* @return Iterator<?>
*/
- public static <E> Iterator<?> maybeTransform(Iterator<? extends E> iter, UnaryFunction<? super E, ?> func) {
+ public static <E> Iterator<?> maybeTransform(Iterator<? extends E> iter, Function<? super E, ?> func) {
return null == func ? (null == iter ? null : iter) : new TransformedIterator<E, Object>(iter, func);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
index 45cbc4d..ce17283 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -137,9 +137,9 @@
*
* @param <T> the predicate input type
* @param right argument
- * @return UnaryPredicate
+ * @return Predicate
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(instance(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
index ffa8b86..a8532e3 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -132,13 +132,13 @@
}
/**
- * Get an IsGreaterThan UnaryPredicate.
+ * Get an IsGreaterThan Predicate.
*
* @param <T> the binary predicate input types
* @param right the right side object of the IsGreaterThan comparison
- * @return UnaryPredicate<T>
+ * @return Predicate<T>
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(new IsGreaterThan<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
index 365d654..c68aa4c 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -133,13 +133,13 @@
}
/**
- * Get an IsGreaterThanOrEqual UnaryPredicate.
+ * Get an IsGreaterThanOrEqual Predicate.
*
* @param <T> the binary predicate input types
* @param right the right side object of the IsGreaterThanOrEqual comparison
- * @return UnaryPredicate
+ * @return Predicate
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(new IsGreaterThanOrEqual<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
index 26444dc..d575b2f 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -132,13 +132,13 @@
}
/**
- * Get an IsLessThan UnaryPredicate.
+ * Get an IsLessThan Predicate.
*
* @param <T> the binary predicate input types
* @param right the right side object of the comparison.
- * @return UnaryPredicate
+ * @return Predicate
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(new IsLessThan<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
index 62b0231..70e0f4e 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -132,13 +132,13 @@
}
/**
- * Get an IsLessThanOrEqual UnaryPredicate.
+ * Get an IsLessThanOrEqual Predicate.
*
* @param <T> the binary predicate input types
* @param right the right side object of the comparison.
- * @return UnaryPredicate
+ * @return Predicate
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(new IsLessThanOrEqual<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
index cd84aeb..71690fb 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.RightBoundPredicate;
import org.apache.commons.lang3.Validate;
@@ -133,13 +133,13 @@
}
/**
- * Get an IsNotEquivalent UnaryPredicate.
+ * Get an IsNotEquivalent Predicate.
*
* @param <T> the binary predicate input types
- * @param right Comparable against which UnaryPredicate arguments will be compared.
- * @return UnaryPredicate
+ * @param right Comparable against which Predicate arguments will be compared.
+ * @return Predicate
*/
- public static <T extends Comparable<?>> UnaryPredicate<T> instance(T right) {
+ public static <T extends Comparable<?>> Predicate<T> instance(T right) {
return RightBoundPredicate.bind(instance(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java b/core/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
index c1cd622..71fb2bb 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java
@@ -17,18 +17,18 @@
package org.apache.commons.functor.core.comparator;
import java.io.Serializable;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryPredicate} that tests whether a {@link Comparable} object is
+ * A {@link Predicate} that tests whether a {@link Comparable} object is
* within a range. The range is defined in the constructor.
*
* @since 1.0
* @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-public class IsWithinRange<A extends Comparable<A>> implements UnaryPredicate<A>, Serializable {
+public class IsWithinRange<A extends Comparable<A>> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/Max.java b/core/src/main/java/org/apache/commons/functor/core/comparator/Max.java
index 5569f27..40b553a 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/Max.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/Max.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.RightBoundFunction;
import org.apache.commons.lang3.Validate;
@@ -115,13 +115,13 @@
}
/**
- * Get a Max UnaryFunction.
+ * Get a Max Function.
*
* @param <T> the binary function arguments and return types.
* @param right the right side argument of the Max function
- * @return UnaryFunction<T, T>
+ * @return Function<T, T>
*/
- public static <T extends Comparable<?>> UnaryFunction<T, T> instance(T right) {
+ public static <T extends Comparable<?>> Function<T, T> instance(T right) {
return RightBoundFunction.bind(new Max<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/comparator/Min.java b/core/src/main/java/org/apache/commons/functor/core/comparator/Min.java
index bface4f..cf3211e 100644
--- a/core/src/main/java/org/apache/commons/functor/core/comparator/Min.java
+++ b/core/src/main/java/org/apache/commons/functor/core/comparator/Min.java
@@ -20,7 +20,7 @@
import java.util.Comparator;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.RightBoundFunction;
import org.apache.commons.lang3.Validate;
@@ -115,13 +115,13 @@
}
/**
- * Get a Min UnaryFunction.
+ * Get a Min Function.
*
* @param <T> the binary function arguments and return types.
* @param right the right side argument of the Min function
- * @return UnaryFunction<T, T>
+ * @return Function<T, T>
*/
- public static <T extends Comparable<?>> UnaryFunction<T, T> instance(T right) {
+ public static <T extends Comparable<?>> Function<T, T> instance(T right) {
return RightBoundFunction.bind(new Min<T>(), right);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopNullaryProcedure.java
similarity index 68%
rename from core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopNullaryProcedure.java
index a261153..232f5fd 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/AbstractLoopNullaryProcedure.java
@@ -16,19 +16,19 @@
*/
package org.apache.commons.functor.core.composite;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.lang3.Validate;
import java.io.Serializable;
/**
- * Abstract base class for {@link WhileDoProcedure} and {@link DoWhileProcedure}
+ * Abstract base class for {@link WhileDoNullaryProcedure} and {@link DoWhileNullaryProcedure}
* used to implement loop procedures.
* <p>
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public abstract class AbstractLoopProcedure implements Procedure, Serializable {
+public abstract class AbstractLoopNullaryProcedure implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -41,21 +41,21 @@
* The condition has to be verified that while true,
* forces the action repetition.
*/
- private final Predicate condition;
+ private final NullaryPredicate condition;
/**
* The action to be repeated until the condition is true.
*/
- private final Procedure action;
+ private final NullaryProcedure action;
/**
- * Create a new AbstractLoopProcedure.
+ * Create a new AbstractLoopNullaryProcedure.
* @param condition while true, repeat
* @param action loop body
*/
- protected AbstractLoopProcedure(Predicate condition, Procedure action) {
- this.condition = Validate.notNull(condition, "Predicate argument must not be null");
- this.action = Validate.notNull(action, "Predicate argument must not be null");
+ protected AbstractLoopNullaryProcedure(NullaryPredicate condition, NullaryProcedure action) {
+ this.condition = Validate.notNull(condition, "NullaryProcedure argument must not be null");
+ this.action = Validate.notNull(action, "NullaryProcedure argument must not be null");
}
/**
@@ -66,10 +66,10 @@
if (object == this) {
return true;
}
- if (!(object instanceof AbstractLoopProcedure)) {
+ if (!(object instanceof AbstractLoopNullaryProcedure)) {
return false;
}
- AbstractLoopProcedure that = (AbstractLoopProcedure) object;
+ AbstractLoopNullaryProcedure that = (AbstractLoopNullaryProcedure) object;
return (getCondition().equals(that.getCondition())
&& (getAction().equals(that.getAction())));
}
@@ -79,7 +79,7 @@
*/
@Override
public int hashCode() {
- return hashCode("AbstractLoopProcedure".hashCode());
+ return hashCode("AbstractLoopNullaryProcedure".hashCode());
}
/**
@@ -105,17 +105,17 @@
/**
* Get the condition.
- * @return Predicate
+ * @return NullaryPredicate
*/
- protected final Predicate getCondition() {
+ protected final NullaryPredicate getCondition() {
return condition;
}
/**
* Get the action.
- * @return Procedure
+ * @return NullaryProcedure
*/
- protected final Procedure getAction() {
+ protected final NullaryProcedure getAction() {
return action;
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/And.java b/core/src/main/java/org/apache/commons/functor/core/composite/And.java
index 5af8866..55274ef 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/And.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/And.java
@@ -31,18 +31,18 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-public final class And extends BasePredicateList {
-
- // constructor
- // ------------------------------------------------------------------------
+public final class And<A> extends BasePredicateList<A> {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -6053343095016685571L;
+ private static final long serialVersionUID = 8324861737107307302L;
+ // constructor
+ // ------------------------------------------------------------------------
/**
* Create a new And.
*/
@@ -53,29 +53,29 @@
/**
* Create a new And instance.
*
- * @param predicates the predicates to add
+ * @param predicates the predicates to put in and.
*/
- public And(Iterable<Predicate> predicates) {
+ public And(Iterable<Predicate<? super A>> predicates) {
super(predicates);
}
/**
* Create a new And instance.
*
- * @param predicates the predicates to add
+ * @param predicates the predicates to put in and.
*/
- public And(Predicate... predicates) {
+ public And(Predicate<? super A>... predicates) {
super(predicates);
}
// modifiers
// ------------------------------------------------------------------------
/**
- * Add a Predicate.
+ * Fluently add a Predicate.
* @param p Predicate to add
* @return this
*/
- public And and(Predicate p) {
+ public And<A> and(Predicate<? super A> p) {
super.addPredicate(p);
return this;
}
@@ -85,9 +85,9 @@
/**
* {@inheritDoc}
*/
- public boolean test() {
- for (Predicate p : getPredicateList()) {
- if (!p.test()) {
+ public boolean test(A obj) {
+ for (Predicate<? super A> p : getPredicateList()) {
+ if (!p.test(obj)) {
return false;
}
}
@@ -99,15 +99,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof And && equals((And) that));
+ return that == this || (that instanceof And<?> && equals((And<?>) that));
}
/**
- * Learn whether a given And is equal to this.
- * @param that the And to test
+ * Learn whether another And is equal to this.
+ * @param that And to test
* @return boolean
*/
- public boolean equals(And that) {
+ public boolean equals(And<?> that) {
return getPredicateListEquals(that);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java b/core/src/main/java/org/apache/commons/functor/core/composite/BaseNullaryPredicateList.java
similarity index 61%
rename from core/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/BaseNullaryPredicateList.java
index 302fea8..fd2f719 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/BaseUnaryPredicateList.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/BaseNullaryPredicateList.java
@@ -20,11 +20,11 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
/**
- * Abstract base class for {@link UnaryPredicate UnaryPredicates}
- * composed of a list of {@link UnaryPredicate UnaryPredicates}.
+ * Abstract base class for {@link NullaryPredicate NullaryPredicates}
+ * composed of a list of {@link NullaryPredicate NullaryPredicates}.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -33,55 +33,53 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the predicate argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-abstract class BaseUnaryPredicateList<A> implements UnaryPredicate<A>, Serializable {
-
+abstract class BaseNullaryPredicateList implements NullaryPredicate, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 1467575113401282954L;
+ private static final long serialVersionUID = 7860902316994888181L;
// attributes
// ------------------------------------------------------------------------
/**
* A list where storing the adapted predicates.
*/
- private final List<UnaryPredicate<? super A>> list = new ArrayList<UnaryPredicate<? super A>>();
+ private final List<NullaryPredicate> list = new ArrayList<NullaryPredicate>();
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new BaseUnaryPredicateList.
+ * Create a new BaseNullaryPredicateList instance.
*/
- protected BaseUnaryPredicateList() {
+ protected BaseNullaryPredicateList() {
super();
}
/**
- * Create a new BaseUnaryPredicateList instance.
+ * Create a new BaseNullaryPredicateList instance.
*
* @param predicates to add
*/
- protected BaseUnaryPredicateList(UnaryPredicate<? super A>... predicates) {
+ protected BaseNullaryPredicateList(NullaryPredicate... predicates) {
this();
if (predicates != null) {
- for (UnaryPredicate<? super A> p : predicates) {
- addUnaryPredicate(p);
+ for (NullaryPredicate p : predicates) {
+ addNullaryPredicate(p);
}
}
}
/**
- * Create a new BaseUnaryPredicateList instance.
+ * Create a new BaseNullaryPredicateList instance.
*
* @param predicates to add
*/
- protected BaseUnaryPredicateList(Iterable<UnaryPredicate<? super A>> predicates) {
+ protected BaseNullaryPredicateList(Iterable<NullaryPredicate> predicates) {
this();
if (predicates != null) {
- for (UnaryPredicate<? super A> p : predicates) {
- addUnaryPredicate(p);
+ for (NullaryPredicate p : predicates) {
+ addNullaryPredicate(p);
}
}
}
@@ -109,10 +107,10 @@
// modifiers
// ------------------------------------------------------------------------
/**
- * Add a UnaryPredicate to the list.
- * @param p UnaryPredicate to add
+ * Add a NullaryPredicate to the list.
+ * @param p NullaryPredicate to add
*/
- protected void addUnaryPredicate(UnaryPredicate<? super A> p) {
+ protected void addNullaryPredicate(NullaryPredicate p) {
if (p != null) {
list.add(p);
}
@@ -122,35 +120,35 @@
// ------------------------------------------------------------------------
/**
- * Get the "live" list of contained {@link UnaryPredicate}s.
- * @return List
+ * Get the "live" list of {@link NullaryPredicate}s.
+ * @return List<NullaryPredicate>
*/
- protected List<UnaryPredicate<? super A>> getUnaryPredicateList() {
+ protected List<NullaryPredicate> getNullaryPredicateList() {
return list;
}
/**
- * Learn whether another BaseUnaryPredicateList has content equal to this.
- * @param that the BaseUnaryPredicateList to test
+ * Learn whether the list of another BaseNullaryPredicateList is equal to my list.
+ * @param that BaseNullaryPredicateList to test
* @return boolean
*/
- protected boolean getUnaryPredicateListEquals(BaseUnaryPredicateList<?> that) {
+ protected boolean getNullaryPredicateListEquals(BaseNullaryPredicateList that) {
return (null != that && this.list.equals(that.list));
}
/**
- * Get a hashCode for the list.
+ * Get a hashCode for my list.
* @return int
*/
- protected int getUnaryPredicateListHashCode() {
+ protected int getNullaryPredicateListHashCode() {
return list.hashCode();
}
/**
- * Get a toString for the list.
+ * Get a toString for my list.
* @return String
*/
- protected String getUnaryPredicateListToString() {
+ protected String getNullaryPredicateListToString() {
return String.valueOf(list);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java b/core/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
index b7df971..32b1e55 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/BasePredicateList.java
@@ -33,24 +33,26 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-abstract class BasePredicateList implements Predicate, Serializable {
+abstract class BasePredicateList<A> implements Predicate<A>, Serializable {
+
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 7860902316994888181L;
+ private static final long serialVersionUID = 1467575113401282954L;
// attributes
// ------------------------------------------------------------------------
/**
* A list where storing the adapted predicates.
*/
- private final List<Predicate> list = new ArrayList<Predicate>();
+ private final List<Predicate<? super A>> list = new ArrayList<Predicate<? super A>>();
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new BasePredicateList instance.
+ * Create a new BasePredicateList.
*/
protected BasePredicateList() {
super();
@@ -61,10 +63,10 @@
*
* @param predicates to add
*/
- protected BasePredicateList(Predicate... predicates) {
+ protected BasePredicateList(Predicate<? super A>... predicates) {
this();
if (predicates != null) {
- for (Predicate p : predicates) {
+ for (Predicate<? super A> p : predicates) {
addPredicate(p);
}
}
@@ -75,10 +77,10 @@
*
* @param predicates to add
*/
- protected BasePredicateList(Iterable<Predicate> predicates) {
+ protected BasePredicateList(Iterable<Predicate<? super A>> predicates) {
this();
if (predicates != null) {
- for (Predicate p : predicates) {
+ for (Predicate<? super A> p : predicates) {
addPredicate(p);
}
}
@@ -110,7 +112,7 @@
* Add a Predicate to the list.
* @param p Predicate to add
*/
- protected void addPredicate(Predicate p) {
+ protected void addPredicate(Predicate<? super A> p) {
if (p != null) {
list.add(p);
}
@@ -120,24 +122,24 @@
// ------------------------------------------------------------------------
/**
- * Get the "live" list of {@link Predicate}s.
- * @return List<Predicate>
+ * Get the "live" list of contained {@link Predicate}s.
+ * @return List
*/
- protected List<Predicate> getPredicateList() {
+ protected List<Predicate<? super A>> getPredicateList() {
return list;
}
/**
- * Learn whether the list of another BasePredicateList is equal to my list.
- * @param that BasePredicateList to test
+ * Learn whether another BasePredicateList has content equal to this.
+ * @param that the BasePredicateList to test
* @return boolean
*/
- protected boolean getPredicateListEquals(BasePredicateList that) {
+ protected boolean getPredicateListEquals(BasePredicateList<?> that) {
return (null != that && this.list.equals(that.list));
}
/**
- * Get a hashCode for my list.
+ * Get a hashCode for the list.
* @return int
*/
protected int getPredicateListHashCode() {
@@ -145,7 +147,7 @@
}
/**
- * Get a toString for my list.
+ * Get a toString for the list.
* @return String
*/
protected String getPredicateListToString() {
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/Composite.java b/core/src/main/java/org/apache/commons/functor/core/composite/Composite.java
index 39e0063..11cdaee 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/Composite.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/Composite.java
@@ -18,9 +18,9 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
/**
* Utility/fluent methods for creating composite functors.
@@ -40,49 +40,49 @@
public Composite() { }
/**
- * Create a composite UnaryProcedure.
+ * Create a composite Procedure.
* @param <A> the procedure argument type.
- * @param procedure UnaryProcedure to execute against output of <code>f</code>
- * @return CompositeUnaryProcedure<A>
+ * @param procedure Procedure to execute against output of <code>f</code>
+ * @return CompositeProcedure<A>
*/
- public static <A> CompositeUnaryProcedure<A> procedure(UnaryProcedure<? super A> procedure) {
- return new CompositeUnaryProcedure<A>(procedure);
+ public static <A> CompositeProcedure<A> procedure(Procedure<? super A> procedure) {
+ return new CompositeProcedure<A>(procedure);
}
/**
- * Create a composite UnaryProcedure.
+ * Create a composite Procedure.
* @param <A> the function argument type.
* @param <T> the the procedure argument type and function returned value type.
- * @param procedure UnaryProcedure to execute against output of <code>f</code>
- * @param function UnaryFunction to apply
- * @return CompositeUnaryProcedure<A>
+ * @param procedure Procedure to execute against output of <code>f</code>
+ * @param function Function to apply
+ * @return CompositeProcedure<A>
*/
- public static <A, T> CompositeUnaryProcedure<A> procedure(UnaryProcedure<? super T> procedure,
- UnaryFunction<? super A, ? extends T> function) {
- return new CompositeUnaryProcedure<T>(procedure).of(function);
+ public static <A, T> CompositeProcedure<A> procedure(Procedure<? super T> procedure,
+ Function<? super A, ? extends T> function) {
+ return new CompositeProcedure<T>(procedure).of(function);
}
/**
- * Create a composite UnaryPredicate.
+ * Create a composite Predicate.
* @param <A> the predicate argument type.
- * @param pred UnaryPredicate to test the output of <code>f</code>
- * @return CompositeUnaryPredicate<A>
+ * @param pred Predicate to test the output of <code>f</code>
+ * @return CompositePredicate<A>
*/
- public static <A> CompositeUnaryPredicate<A> predicate(UnaryPredicate<? super A> pred) {
- return new CompositeUnaryPredicate<A>(pred);
+ public static <A> CompositePredicate<A> predicate(Predicate<? super A> pred) {
+ return new CompositePredicate<A>(pred);
}
/**
- * Create a composite UnaryPredicate.
+ * Create a composite Predicate.
* @param <A> the function argument type.
* @param <T> the predicate argument type and the function returned value type.
- * @param predicate UnaryPredicate to test the output of <code>f</code>
- * @param function UnaryFunction to apply
- * @return CompositeUnaryPredicate<A>
+ * @param predicate Predicate to test the output of <code>f</code>
+ * @param function Function to apply
+ * @return CompositePredicate<A>
*/
- public static <A, T> CompositeUnaryPredicate<A> predicate(UnaryPredicate<? super T> predicate,
- UnaryFunction<? super A, ? extends T> function) {
- return new CompositeUnaryPredicate<T>(predicate).of(function);
+ public static <A, T> CompositePredicate<A> predicate(Predicate<? super T> predicate,
+ Function<? super A, ? extends T> function) {
+ return new CompositePredicate<T>(predicate).of(function);
}
/**
@@ -92,73 +92,73 @@
* @param <G> the input functions left argument type.
* @param <H> the input functions right argument type.
* @param p BinaryPredicate to test <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
* @return BinaryPredicate
*/
- public static <L, R, G, H> UnaryCompositeBinaryPredicate<L, R> predicate(
- BinaryPredicate<? super G, ? super H> p, UnaryFunction<? super L, ? extends G> g,
- UnaryFunction<? super R, ? extends H> h) {
- return new UnaryCompositeBinaryPredicate<L, R>(p, g, h);
+ public static <L, R, G, H> CompositeBinaryPredicate<L, R> predicate(
+ BinaryPredicate<? super G, ? super H> p, Function<? super L, ? extends G> g,
+ Function<? super R, ? extends H> h) {
+ return new CompositeBinaryPredicate<L, R>(p, g, h);
}
/**
- * Create a composite UnaryFunction.
+ * Create a composite Function.
* @param <A> the function argument type.
* @param <T> the function returned value type.
- * @param f UnaryFunction to apply to the output of <code>g</code>
- * @return UnaryFunction
+ * @param f Function to apply to the output of <code>g</code>
+ * @return Function
*/
- public static <A, T> CompositeUnaryFunction<A, T> function(UnaryFunction<? super A, ? extends T> f) {
- return new CompositeUnaryFunction<A, T>(f);
+ public static <A, T> CompositeFunction<A, T> function(Function<? super A, ? extends T> f) {
+ return new CompositeFunction<A, T>(f);
}
/**
- * Create a composite UnaryFunction.
+ * Create a composite Function.
* @param <A> the function argument type.
* @param <X> the function argument type.
* @param <T> the function returned value type.
- * @param f UnaryFunction to apply to the output of <code>g</code>
- * @param g UnaryFunction to apply first
- * @return UnaryFunction
+ * @param f Function to apply to the output of <code>g</code>
+ * @param g Function to apply first
+ * @return Function
*/
- public static <A, X, T> CompositeUnaryFunction<A, T> function(UnaryFunction<? super X, ? extends T> f,
- UnaryFunction<? super A, ? extends X> g) {
- return new CompositeUnaryFunction<X, T>(f).of(g);
+ public static <A, X, T> CompositeFunction<A, T> function(Function<? super X, ? extends T> f,
+ Function<? super A, ? extends X> g) {
+ return new CompositeFunction<X, T>(f).of(g);
}
// /**
-// * Chain a BinaryFunction to a UnaryFunction.
+// * Chain a BinaryFunction to a Function.
// * @param <L>
// * @param <R>
// * @param <X>
// * @param <T>
-// * @param f UnaryFunction to apply to the output of <code>g</code>
+// * @param f Function to apply to the output of <code>g</code>
// * @param g BinaryFunction to apply first
// * @return BinaryFunction<L, R, T>
// */
-// public static <L, R, X, T> BinaryFunction<L, R, T> function(UnaryFunction<? super X, ? extends T> f,
+// public static <L, R, X, T> BinaryFunction<L, R, T> function(Function<? super X, ? extends T> f,
// BinaryFunction<? super L,
// ? super R, ? extends X> g) {
-// return new CompositeUnaryFunction<X, T>(f).of(g);
+// return new CompositeFunction<X, T>(f).of(g);
// }
/**
- * Create a composite<UnaryFunction> BinaryFunction.
+ * Create a composite<Function> BinaryFunction.
* @param <L> the output predicate left argument type.
* @param <R> the output predicate right argument type.
* @param <G> the input functions left argument type.
* @param <H> the input functions right argument type.
* @param <T> the function returned value type.
* @param f BinaryFunction to apply to <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
* @return BinaryFunction
*/
- public static <L, R, G, H, T> UnaryCompositeBinaryFunction<L, R, T> function(
- BinaryFunction<? super G, ? super H, ? extends T> f, UnaryFunction<? super L, ? extends G> g,
- UnaryFunction<? super R, ? extends H> h) {
- return new UnaryCompositeBinaryFunction<L, R, T>(f, g, h);
+ public static <L, R, G, H, T> CompositeBinaryFunction<L, R, T> function(
+ BinaryFunction<? super G, ? super H, ? extends T> f, Function<? super L, ? extends G> g,
+ Function<? super R, ? extends H> h) {
+ return new CompositeBinaryFunction<L, R, T>(f, g, h);
}
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java
similarity index 75%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java
index 5489e3a..2e419d5 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryFunction BinaryFunction} composed of
- * one binary function, <i>f</i>, and two unary
+ * one binary function, <i>f</i>, and two
* functions, <i>g</i> and <i>h</i>,
* evaluating the ordered parameters <i>x</i>, <i>y</i>
* to <code><i>f</i>(<i>g</i>(<i>x</i>),<i>h</i>(<i>y</i>))</code>.
@@ -39,9 +39,9 @@
* @param <L> the left argument type.
* @param <R> the right argument type.
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class UnaryCompositeBinaryFunction<L, R, T> implements BinaryFunction<L, R, T>, Serializable {
+public class CompositeBinaryFunction<L, R, T> implements BinaryFunction<L, R, T>, Serializable {
/**
* serialVersionUID declaration.
@@ -72,20 +72,20 @@
/**
* The adapted left function.
*/
- private UnaryFunction<? super L, ? extends G> g;
+ private Function<? super L, ? extends G> g;
/**
* The adapted right function.
*/
- private UnaryFunction<? super R, ? extends H> h;
+ private Function<? super R, ? extends H> h;
/**
* Create a new Helper.
* @param f BinaryFunction to receive <code>(output(g), output(h))</code>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
*/
- public Helper(BinaryFunction<? super G, ? super H, ? extends T> f, UnaryFunction<? super L, ? extends G> g,
- UnaryFunction<? super R, ? extends H> h) {
+ public Helper(BinaryFunction<? super G, ? super H, ? extends T> f, Function<? super L, ? extends G> g,
+ Function<? super R, ? extends H> h) {
this.f = f;
this.g = g;
this.h = h;
@@ -107,20 +107,20 @@
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new UnaryCompositeBinaryFunction.
+ * Create a new CompositeBinaryFunction.
*
* @param <G> the adapted function left argument type.
* @param <H> the adapted function right argument type.
* @param f BinaryFunction to receive <code>(output(g), output(h))</code>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
*/
- public <G, H> UnaryCompositeBinaryFunction(BinaryFunction<? super G, ? super H, ? extends T> f,
- UnaryFunction<? super L, ? extends G> g, UnaryFunction<? super R, ? extends H> h) {
+ public <G, H> CompositeBinaryFunction(BinaryFunction<? super G, ? super H, ? extends T> f,
+ Function<? super L, ? extends G> g, Function<? super R, ? extends H> h) {
this.helper = new Helper<G, H, L, R, T>(
Validate.notNull(f, "BinaryFunction must not be null"),
- Validate.notNull(g, "left UnaryFunction must not be null"),
- Validate.notNull(h, "right UnaryFunction must not be null")
+ Validate.notNull(g, "left Function must not be null"),
+ Validate.notNull(h, "right Function must not be null")
);
}
@@ -138,16 +138,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof UnaryCompositeBinaryFunction<?, ?, ?>
- && equals((UnaryCompositeBinaryFunction<?, ?, ?>) that));
+ return that == this || (that instanceof CompositeBinaryFunction<?, ?, ?>
+ && equals((CompositeBinaryFunction<?, ?, ?>) that));
}
/**
- * Learn whether a given UnaryCompositeBinaryFunction is equal to this.
- * @param that UnaryCompositeBinaryFunction to test
+ * Learn whether a given CompositeBinaryFunction is equal to this.
+ * @param that CompositeBinaryFunction to test
* @return boolean
*/
- public boolean equals(UnaryCompositeBinaryFunction<?, ?, ?> that) {
+ public boolean equals(CompositeBinaryFunction<?, ?, ?> that) {
return null != that
&& helper.f.equals(that.helper.f)
&& helper.g.equals(that.helper.g)
@@ -159,7 +159,7 @@
*/
@Override
public int hashCode() {
- int hash = "UnaryCompositeBinaryFunction".hashCode();
+ int hash = "CompositeBinaryFunction".hashCode();
hash <<= HASH_SHIFT;
hash ^= helper.f.hashCode();
hash <<= HASH_SHIFT;
@@ -174,7 +174,7 @@
*/
@Override
public String toString() {
- return "UnaryCompositeBinaryFunction<" + helper.f + ";" + helper.g + ";" + helper.h + ">";
+ return "CompositeBinaryFunction<" + helper.f + ";" + helper.g + ";" + helper.h + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java
similarity index 73%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java
index eea6e8f..5a067ab 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryCompositeBinaryPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java
@@ -19,12 +19,12 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
* A {@link BinaryPredicate BinaryPredicate} composed of
- * one binary predicate, <i>p</i>, and two unary
+ * one binary predicate, <i>p</i>, and two
* functions, <i>f</i> and <i>g</i>,
* evaluating the ordered parameters <i>x</i>, <i>y</i>
* to <code><i>p</i>(<i>f</i>(<i>x</i>),<i>g</i>(<i>y</i>))</code>.
@@ -38,9 +38,9 @@
* </p>
* @param <L> the left argument type.
* @param <R> the right argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class UnaryCompositeBinaryPredicate<L, R> implements BinaryPredicate<L, R>, Serializable {
+public class CompositeBinaryPredicate<L, R> implements BinaryPredicate<L, R>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -67,22 +67,22 @@
*/
private BinaryPredicate<? super G, ? super H> f;
/**
- * left UnaryFunction.
+ * left Function.
*/
- private UnaryFunction<? super L, ? extends G> g;
+ private Function<? super L, ? extends G> g;
/**
- * right UnaryFunction.
+ * right Function.
*/
- private UnaryFunction<? super R, ? extends H> h;
+ private Function<? super R, ? extends H> h;
/**
* Create a new Helper.
* @param f BinaryPredicate to test <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
*/
- public Helper(BinaryPredicate<? super G, ? super H> f, UnaryFunction<? super L, ? extends G> g,
- UnaryFunction<? super R, ? extends H> h) {
+ public Helper(BinaryPredicate<? super G, ? super H> f, Function<? super L, ? extends G> g,
+ Function<? super R, ? extends H> h) {
this.f = f;
this.g = g;
this.h = h;
@@ -106,20 +106,20 @@
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new UnaryCompositeBinaryPredicate.
+ * Create a new CompositeBinaryPredicate.
*
* @param <G> right function type.
* @param <H> right function type.
* @param f BinaryPredicate to test <i>output(</i><code>f</code><i>), output(</i><code>g</code><i>)</i>
- * @param g left UnaryFunction
- * @param h right UnaryFunction
+ * @param g left Function
+ * @param h right Function
*/
- public <G, H> UnaryCompositeBinaryPredicate(final BinaryPredicate<? super G, ? super H> f,
- final UnaryFunction<? super L, ? extends G> g, final UnaryFunction<? super R, ? extends H> h) {
+ public <G, H> CompositeBinaryPredicate(final BinaryPredicate<? super G, ? super H> f,
+ final Function<? super L, ? extends G> g, final Function<? super R, ? extends H> h) {
helper = new Helper<G, H, L, R>(
Validate.notNull(f, "BinaryPredicate must not be null"),
- Validate.notNull(g, "left UnaryFunction must not be null"),
- Validate.notNull(h, "right UnaryFunction must not be null")
+ Validate.notNull(g, "left Function must not be null"),
+ Validate.notNull(h, "right Function must not be null")
);
}
@@ -137,16 +137,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof UnaryCompositeBinaryPredicate<?, ?>
- && equals((UnaryCompositeBinaryPredicate<?, ?>) that));
+ return that == this || (that instanceof CompositeBinaryPredicate<?, ?>
+ && equals((CompositeBinaryPredicate<?, ?>) that));
}
/**
- * Learn whether another UnaryCompositeBinaryPredicate is equal to this.
- * @param that UnaryCompositeBinaryPredicate to test
+ * Learn whether another CompositeBinaryPredicate is equal to this.
+ * @param that CompositeBinaryPredicate to test
* @return boolean
*/
- public boolean equals(UnaryCompositeBinaryPredicate<?, ?> that) {
+ public boolean equals(CompositeBinaryPredicate<?, ?> that) {
return null != that && helper.f.equals(that.helper.f) && helper.g.equals(that.helper.g)
&& helper.h.equals(that.helper.h);
}
@@ -156,7 +156,7 @@
*/
@Override
public int hashCode() {
- int hash = "UnaryCompositeBinaryPredicate".hashCode();
+ int hash = "CompositeBinaryPredicate".hashCode();
hash <<= HASH_SHIFT;
hash ^= helper.f.hashCode();
hash <<= HASH_SHIFT;
@@ -171,7 +171,7 @@
*/
@Override
public String toString() {
- return "UnaryCompositeBinaryPredicate<" + helper.f + ";" + helper.g + ";" + helper.h + ">";
+ return "CompositeBinaryPredicate<" + helper.f + ";" + helper.g + ";" + helper.h + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeFunction.java
similarity index 65%
rename from core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/CompositeFunction.java
index 234ac5f..4179fff 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeFunction.java
@@ -18,19 +18,19 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryFunction UnaryFunction}
+ * A {@link Function Function}
* representing the composition of
- * {@link UnaryFunction UnaryFunctions},
+ * {@link Function Functions},
* "chaining" the output of one to the input
* of another. For example,
- * <pre>new CompositeUnaryFunction(f).of(g)</pre>
+ * <pre>new CompositeFunction(f).of(g)</pre>
* {@link #evaluate evaluates} to
* <code>f.evaluate(g.evaluate(obj))</code>, and
- * <pre>new CompositeUnaryFunction(f).of(g).of(h)</pre>
+ * <pre>new CompositeFunction(f).of(g).of(h)</pre>
* {@link #evaluate evaluates} to
* <code>f.evaluate(g.evaluate(h.evaluate(obj)))</code>.
* <p>
@@ -47,9 +47,9 @@
* </p>
* @param <A> the argument type.
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class CompositeUnaryFunction<A, T> implements UnaryFunction<A, T>, Serializable {
+public class CompositeFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
@@ -65,7 +65,7 @@
* @param <X> intermediate type
* @param <T> return type
*/
- private static class Helper<X, A, T> implements UnaryFunction<A, T>, Serializable {
+ private static class Helper<X, A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -73,21 +73,21 @@
/**
* The last evaluator function.
*/
- private UnaryFunction<? super X, ? extends T> following;
+ private Function<? super X, ? extends T> following;
/**
* The first evaluator function.
*/
- private UnaryFunction<? super A, ? extends X> preceding;
+ private Function<? super A, ? extends X> preceding;
/**
* Create a new Helper.
- * @param following UnaryFunction<X, Y>
- * @param preceding UnaryFunction<Y, Z>
+ * @param following Function<X, Y>
+ * @param preceding Function<Y, Z>
*/
- public Helper(UnaryFunction<? super X, ? extends T> following,
- UnaryFunction<? super A, ? extends X> preceding) {
- this.following = Validate.notNull(following, "UnaryFunction argument must not be null");
- this.preceding = Validate.notNull(preceding, "UnaryFunction argument must not be null");
+ public Helper(Function<? super X, ? extends T> following,
+ Function<? super A, ? extends X> preceding) {
+ this.following = Validate.notNull(following, "Function argument must not be null");
+ this.preceding = Validate.notNull(preceding, "Function argument must not be null");
}
/**
@@ -120,11 +120,11 @@
*/
@Override
public int hashCode() {
- int result = "CompositeUnaryFunction$Helper".hashCode();
+ int result = "CompositeFunction$Helper".hashCode();
result <<= 2;
- result |= following.hashCode();
+ result ^= following.hashCode();
result <<= 2;
- result |= preceding.hashCode();
+ result ^= preceding.hashCode();
return result;
}
@@ -140,25 +140,25 @@
/**
* The adapted function.
*/
- private final UnaryFunction<? super A, ? extends T> function;
+ private final Function<? super A, ? extends T> function;
/**
- * Create a new CompositeUnaryFunction.
- * @param function UnaryFunction to call
+ * Create a new CompositeFunction.
+ * @param function Function to call
*/
- public CompositeUnaryFunction(UnaryFunction<? super A, ? extends T> function) {
+ public CompositeFunction(Function<? super A, ? extends T> function) {
this.function = Validate.notNull(function, "function must not be null");
}
/**
- * Creates a new {@link CompositeUnaryFunction} instance given the input functions.
+ * Creates a new {@link CompositeFunction} instance given the input functions.
*
* @param <X> the argument type.
* @param following The first evaluator function.
* @param preceding The last evaluator function.
*/
- private <X> CompositeUnaryFunction(UnaryFunction<? super X, ? extends T> following,
- UnaryFunction<? super A, ? extends X> preceding) {
+ private <X> CompositeFunction(Function<? super X, ? extends T> following,
+ Function<? super A, ? extends X> preceding) {
this.function = new Helper<X, A, T>(following, preceding);
}
@@ -170,14 +170,14 @@
}
/**
- * Fluently obtain a CompositeUnaryFunction that is "this function" applied to the specified preceding function.
+ * Fluently obtain a CompositeFunction that is "this function" applied to the specified preceding function.
* @param <P> argument type of the resulting function.
- * @param preceding UnaryFunction
- * @return CompositeUnaryFunction<P, T>
+ * @param preceding Function
+ * @return CompositeFunction<P, T>
*/
- public final <P> CompositeUnaryFunction<P, T> of(UnaryFunction<? super P, ? extends A> preceding) {
+ public final <P> CompositeFunction<P, T> of(Function<? super P, ? extends A> preceding) {
Validate.notNull(preceding, "preceding function was null");
- return new CompositeUnaryFunction<P, T>(function, preceding);
+ return new CompositeFunction<P, T>(function, preceding);
}
/**
@@ -186,15 +186,15 @@
@Override
public final boolean equals(Object that) {
return that == this
- || (that instanceof CompositeUnaryFunction<?, ?> && equals((CompositeUnaryFunction<?, ?>) that));
+ || (that instanceof CompositeFunction<?, ?> && equals((CompositeFunction<?, ?>) that));
}
/**
- * Learn whether another CompositeUnaryFunction is equal to this.
- * @param that CompositeUnaryFunction to test
+ * Learn whether another CompositeFunction is equal to this.
+ * @param that CompositeFunction to test
* @return boolean
*/
- public final boolean equals(CompositeUnaryFunction<?, ?> that) {
+ public final boolean equals(CompositeFunction<?, ?> that) {
// by construction, list is never null
return null != that && function.equals(that.function);
}
@@ -205,7 +205,7 @@
@Override
public int hashCode() {
// by construction, list is never null
- return ("CompositeUnaryFunction".hashCode() << HASH_SHIFT) ^ function.hashCode();
+ return ("CompositeFunction".hashCode() << HASH_SHIFT) ^ function.hashCode();
}
/**
@@ -213,7 +213,7 @@
*/
@Override
public String toString() {
- return "CompositeUnaryFunction<" + function + ">";
+ return "CompositeFunction<" + function + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java b/core/src/main/java/org/apache/commons/functor/core/composite/CompositePredicate.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/CompositePredicate.java
index bddf643..5d2a247 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/CompositePredicate.java
@@ -18,21 +18,21 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.adapter.UnaryPredicateUnaryFunction;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.adapter.PredicateFunction;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryPredicate UnaryPredicate}
+ * A {@link Predicate Predicate}
* representing the composition of
- * {@link UnaryFunction UnaryFunctions},
+ * {@link Function Functions},
* "chaining" the output of one to the input
* of another. For example,
- * <pre>new CompositeUnaryPredicate(p).of(f)</pre>
+ * <pre>new CompositePredicate(p).of(f)</pre>
* {@link #test tests} to
* <code>p.test(f.evaluate(obj))</code>, and
- * <pre>new CompositeUnaryPredicate(p).of(f).of(g)</pre>
+ * <pre>new CompositePredicate(p).of(f).of(g)</pre>
* {@link #test tests} to
* <code>p.test(f.evaluate(g.evaluate(obj)))</code>.
* <p>
@@ -44,9 +44,9 @@
* <code>Serializable</code> will result in an exception.
* </p>
* @param <A> the predicate argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class CompositeUnaryPredicate<A> implements UnaryPredicate<A>, Serializable {
+public final class CompositePredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -56,39 +56,39 @@
/**
* The adapted composite function.
*/
- private final CompositeUnaryFunction<? super A, Boolean> function;
+ private final CompositeFunction<? super A, Boolean> function;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new CompositeUnaryPredicate.
- * @param predicate UnaryPredicate against which the composite functions' output will be tested
+ * Create a new CompositePredicate.
+ * @param predicate Predicate against which the composite functions' output will be tested
*/
- public CompositeUnaryPredicate(UnaryPredicate<? super A> predicate) {
+ public CompositePredicate(Predicate<? super A> predicate) {
this.function =
- new CompositeUnaryFunction<A, Boolean>(
- new UnaryPredicateUnaryFunction<A>(Validate.notNull(predicate,
+ new CompositeFunction<A, Boolean>(
+ new PredicateFunction<A>(Validate.notNull(predicate,
"predicate must not be null")));
}
/**
- * Create a new CompositeUnaryPredicate.
+ * Create a new CompositePredicate.
* @param function delegate
*/
- private CompositeUnaryPredicate(CompositeUnaryFunction<? super A, Boolean> function) {
+ private CompositePredicate(CompositeFunction<? super A, Boolean> function) {
this.function = function;
}
// modifiers
// ------------------------------------------------------------------------
/**
- * Fluently obtain a CompositeUnaryPredicate that applies our predicate to the result of the preceding function.
+ * Fluently obtain a CompositePredicate that applies our predicate to the result of the preceding function.
* @param <P> the input function left argument and output predicate argument types
- * @param preceding UnaryFunction
- * @return CompositeUnaryPredicate<P>
+ * @param preceding Function
+ * @return CompositePredicate<P>
*/
- public <P> CompositeUnaryPredicate<P> of(UnaryFunction<? super P, ? extends A> preceding) {
- return new CompositeUnaryPredicate<P>(function.of(preceding));
+ public <P> CompositePredicate<P> of(Function<? super P, ? extends A> preceding) {
+ return new CompositePredicate<P>(function.of(preceding));
}
// predicate interface
@@ -105,16 +105,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof CompositeUnaryPredicate<?>
- && equals((CompositeUnaryPredicate<?>) that));
+ return that == this || (that instanceof CompositePredicate<?>
+ && equals((CompositePredicate<?>) that));
}
/**
- * Learn whether another CompositeUnaryPredicate is equal to this.
- * @param that CompositeUnaryPredicate to test
+ * Learn whether another CompositePredicate is equal to this.
+ * @param that CompositePredicate to test
* @return boolean
*/
- public boolean equals(CompositeUnaryPredicate<?> that) {
+ public boolean equals(CompositePredicate<?> that) {
return null != that && function.equals(that.function);
}
@@ -123,7 +123,7 @@
*/
@Override
public int hashCode() {
- int hash = "CompositeUnaryPredicate".hashCode();
+ int hash = "CompositePredicate".hashCode();
hash <<= 2;
hash ^= function.hashCode();
return hash;
@@ -134,7 +134,7 @@
*/
@Override
public String toString() {
- return "CompositeUnaryFunction<" + function + ">";
+ return "CompositeFunction<" + function + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeProcedure.java
similarity index 61%
rename from core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/CompositeProcedure.java
index 34d6e2d..f89c2cb 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/CompositeUnaryProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/CompositeProcedure.java
@@ -18,21 +18,21 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.adapter.UnaryProcedureUnaryFunction;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.adapter.ProcedureFunction;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryProcedure UnaryProcedure}
+ * A {@link Procedure Procedure}
* representing the composition of
- * {@link UnaryFunction UnaryFunctions},
+ * {@link Function Functions},
* "chaining" the output of one to the input
* of another. For example,
- * <pre>new CompositeUnaryProcedure(p).of(f)</pre>
+ * <pre>new CompositeProcedure(p).of(f)</pre>
* {@link #run runs} to
* <code>p.run(f.evaluate(obj))</code>, and
- * <pre>new CompositeUnaryProcedure(p).of(f).of(g)</pre>
+ * <pre>new CompositeProcedure(p).of(f).of(g)</pre>
* {@link #run runs}
* <code>p.run(f.evaluate(g.evaluate(obj)))</code>.
* <p>
@@ -44,9 +44,9 @@
* <code>Serializable</code> will result in an exception.
* </p>
* @param <A> the procedure argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class CompositeUnaryProcedure<A> implements UnaryProcedure<A>, Serializable {
+public final class CompositeProcedure<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -56,39 +56,39 @@
/**
* The adapted composite procedure.
*/
- private final CompositeUnaryFunction<? super A, Object> function;
+ private final CompositeFunction<? super A, Object> function;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new CompositeUnaryProcedure.
- * @param procedure final UnaryProcedure to run
+ * Create a new CompositeProcedure.
+ * @param procedure final Procedure to run
*/
- public CompositeUnaryProcedure(UnaryProcedure<? super A> procedure) {
+ public CompositeProcedure(Procedure<? super A> procedure) {
this.function =
- new CompositeUnaryFunction<A, Object>(
- new UnaryProcedureUnaryFunction<A, Object>(Validate.notNull(
+ new CompositeFunction<A, Object>(
+ new ProcedureFunction<A, Object>(Validate.notNull(
procedure, "procedure must not be null")));
}
/**
- * Create a new CompositeUnaryProcedure.
- * @param function final CompositeUnaryFunction to run
+ * Create a new CompositeProcedure.
+ * @param function final CompositeFunction to run
*/
- private CompositeUnaryProcedure(CompositeUnaryFunction<? super A, Object> function) {
+ private CompositeProcedure(CompositeFunction<? super A, Object> function) {
this.function = function;
}
// modifiers
// ------------------------------------------------------------------------
/**
- * Fluently obtain a CompositeUnaryProcedure that runs our procedure against the result of the preceding function.
+ * Fluently obtain a CompositeProcedure that runs our procedure against the result of the preceding function.
* @param <T> the input function left argument and output procedure argument type
- * @param preceding UnaryFunction
- * @return CompositeUnaryProcedure<P>
+ * @param preceding Function
+ * @return CompositeProcedure<P>
*/
- public <T> CompositeUnaryProcedure<T> of(UnaryFunction<? super T, ? extends A> preceding) {
- return new CompositeUnaryProcedure<T>(function.of(preceding));
+ public <T> CompositeProcedure<T> of(Function<? super T, ? extends A> preceding) {
+ return new CompositeProcedure<T>(function.of(preceding));
}
// predicate interface
@@ -105,16 +105,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof CompositeUnaryProcedure<?>
- && equals((CompositeUnaryProcedure<?>) that));
+ return that == this || (that instanceof CompositeProcedure<?>
+ && equals((CompositeProcedure<?>) that));
}
/**
- * Learn whether another CompositeUnaryProcedure is equal to this.
- * @param that CompositeUnaryProcedure to test
+ * Learn whether another CompositeProcedure is equal to this.
+ * @param that CompositeProcedure to test
* @return boolean
*/
- public boolean equals(CompositeUnaryProcedure<?> that) {
+ public boolean equals(CompositeProcedure<?> that) {
return null != that && function.equals(that.function);
}
@@ -123,7 +123,7 @@
*/
@Override
public int hashCode() {
- int hash = "CompositeUnaryProcedure".hashCode();
+ int hash = "CompositeProcedure".hashCode();
hash <<= 2;
hash ^= function.hashCode();
return hash;
@@ -134,7 +134,7 @@
*/
@Override
public String toString() {
- return "CompositeUnaryProcedure<" + function + ">";
+ return "CompositeProcedure<" + function + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/Conditional.java b/core/src/main/java/org/apache/commons/functor/core/composite/Conditional.java
index ba4379d..169dbc0 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/Conditional.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/Conditional.java
@@ -19,12 +19,12 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
/**
* Utility methods for creating conditional functors.
@@ -48,100 +48,101 @@
// ------------------------------------------------------------------------
/**
- * Create a guarded Procedure.
+ * Create a guarded NullaryProcedure.
* @param q if
* @param r then
- * @return Procedure
+ * @return NullaryProcedure
*/
- public static Procedure procedure(Predicate q, Procedure r) {
- return new ConditionalProcedure(q, r);
+ public static NullaryProcedure procedure(NullaryPredicate q, NullaryProcedure r) {
+ return new ConditionalNullaryProcedure(q, r);
}
/**
- * Create a conditional Procedure.
+ * Create a conditional NullaryProcedure.
* @param q if
* @param r then
* @param s else
- * @return Procedure
+ * @return NullaryProcedure
*/
- public static Procedure procedure(Predicate q, Procedure r, Procedure s) {
- return new ConditionalProcedure(q, r, s);
+ public static NullaryProcedure procedure(NullaryPredicate q, NullaryProcedure r, NullaryProcedure s) {
+ return new ConditionalNullaryProcedure(q, r, s);
}
/**
- * Create a conditional Function.
+ * Create a conditional NullaryFunction.
* @param <T> the input functions parameter type
* @param q if
* @param r then
* @param s else
- * @return Function<T>
+ * @return NullaryFunction<T>
*/
- public static <T> Function<T> function(Predicate q, Function<? extends T> r, Function<? extends T> s) {
- return new ConditionalFunction<T>(q, r, s);
+ public static <T> NullaryFunction<T> function(NullaryPredicate q,
+ NullaryFunction<? extends T> r, NullaryFunction<? extends T> s) {
+ return new ConditionalNullaryFunction<T>(q, r, s);
}
/**
- * Create a conditional Predicate.
+ * Create a conditional NullaryPredicate.
* @param q if
* @param r then
* @param s else
- * @return Predicate
+ * @return NullaryPredicate
*/
- public static Predicate predicate(Predicate q, Predicate r, Predicate s) {
- return new ConditionalPredicate(q, r, s);
+ public static NullaryPredicate predicate(NullaryPredicate q, NullaryPredicate r, NullaryPredicate s) {
+ return new ConditionalNullaryPredicate(q, r, s);
}
/**
- * Create a guarded UnaryProcedure.
+ * Create a guarded Procedure.
*
* @param <A> the predicates argument type.
* @param q if
* @param r then
- * @return UnaryProcedure<A>
+ * @return Procedure<A>
*/
- public static <A> UnaryProcedure<A> procedure(UnaryPredicate<? super A> q, UnaryProcedure<? super A> r) {
- return new ConditionalUnaryProcedure<A>(q, r);
+ public static <A> Procedure<A> procedure(Predicate<? super A> q, Procedure<? super A> r) {
+ return new ConditionalProcedure<A>(q, r);
}
/**
- * Create a conditional UnaryProcedure.
+ * Create a conditional Procedure.
*
* @param <A> the predicates argument type.
* @param q if
* @param r then
* @param s else
- * @return UnaryProcedure<A>
+ * @return Procedure<A>
*/
- public static <A> UnaryProcedure<A> procedure(UnaryPredicate<? super A> q, UnaryProcedure<? super A> r,
- UnaryProcedure<? super A> s) {
- return new ConditionalUnaryProcedure<A>(q, r, s);
+ public static <A> Procedure<A> procedure(Predicate<? super A> q, Procedure<? super A> r,
+ Procedure<? super A> s) {
+ return new ConditionalProcedure<A>(q, r, s);
}
/**
- * Create a conditional UnaryFunction.
+ * Create a conditional Function.
* @param <A> the predicates argument type.
* @param <T> the output function returned value type.
* @param q if
* @param r then
* @param s else
- * @return UnaryFunction<A, T>
+ * @return Function<A, T>
*/
- public static <A, T> UnaryFunction<A, T> function(UnaryPredicate<? super A> q,
- UnaryFunction<? super A, ? extends T> r, UnaryFunction<? super A, ? extends T> s) {
- return new ConditionalUnaryFunction<A, T>(q, r, s);
+ public static <A, T> Function<A, T> function(Predicate<? super A> q,
+ Function<? super A, ? extends T> r, Function<? super A, ? extends T> s) {
+ return new ConditionalFunction<A, T>(q, r, s);
}
/**
- * Create a conditional UnaryPredicate.
+ * Create a conditional Predicate.
* @param <A> the predicates argument type.
* @param q if
* @param r then
* @param s else
- * @return UnaryPredicate<A>
+ * @return Predicate<A>
*/
- public static <A> UnaryPredicate<A> predicate(UnaryPredicate<? super A> q, UnaryPredicate<? super A> r,
- UnaryPredicate<? super A> s) {
- return new ConditionalUnaryPredicate<A>(q, r, s);
+ public static <A> Predicate<A> predicate(Predicate<? super A> q, Predicate<? super A> r,
+ Predicate<? super A> s) {
+ return new ConditionalPredicate<A>(q, r, s);
}
/**
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
index 225d743..e057a7c 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalFunction.java
@@ -28,9 +28,9 @@
* or "conditional" operator (<code>? :</code>).
* Given a {@link Predicate predicate}
* <i>p</i> and {@link Function functions}
- * <i>f</i> and <i>g</i>, {@link #evaluate evaluates}
+ * <i>f</i> and <i>g</i>, {@link #evaluate evalautes}
* to
- * <code>p.test() ? f.evaluate() : g.evaluate()</code>.
+ * <code>p.test(x) ? f.evaluate(x) : g.evaluate(x)</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -39,14 +39,15 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the argument type.
* @param <T> the returned value type.
* @version $Revision$ $Date$
*/
-public final class ConditionalFunction<T> implements Function<T>, Serializable {
+public final class ConditionalFunction<A, T> implements Function<A, T>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 4214871352184887792L;
+ private static final long serialVersionUID = -8152490481969255068L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
@@ -55,15 +56,15 @@
/**
* the condition to be evaluated.
*/
- private final Predicate ifPred;
+ private final Predicate<? super A> ifPred;
/**
* the function executed if the condition is satisfied.
*/
- private final Function<? extends T> thenFunc;
+ private final Function<? super A, ? extends T> thenFunc;
/**
* the function executed if the condition is not satisfied.
*/
- private final Function<? extends T> elseFunc;
+ private final Function<? super A, ? extends T> elseFunc;
// constructor
// ------------------------------------------------------------------------
@@ -73,7 +74,8 @@
* @param thenFunc then
* @param elseFunc else
*/
- public ConditionalFunction(Predicate ifPred, Function<? extends T> thenFunc, Function<? extends T> elseFunc) {
+ public ConditionalFunction(Predicate<? super A> ifPred, Function<? super A, ? extends T> thenFunc,
+ Function<? super A, ? extends T> elseFunc) {
this.ifPred = Validate.notNull(ifPred, "Predicate argument was null");
this.thenFunc = Validate.notNull(thenFunc, "'then' Function argument was null");
this.elseFunc = Validate.notNull(elseFunc, "'else' Function argument was null");
@@ -84,11 +86,11 @@
/**
* {@inheritDoc}
*/
- public T evaluate() {
- if (ifPred.test()) {
- return thenFunc.evaluate();
+ public T evaluate(A obj) {
+ if (ifPred.test(obj)) {
+ return thenFunc.evaluate(obj);
} else {
- return elseFunc.evaluate();
+ return elseFunc.evaluate(obj);
}
}
@@ -97,7 +99,8 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalFunction<?> && equals((ConditionalFunction<?>) that));
+ return that == this || (that instanceof ConditionalFunction<?, ?>
+ && equals((ConditionalFunction<?, ?>) that));
}
/**
@@ -105,7 +108,7 @@
* @param that ConditionalFunction to test
* @return boolean
*/
- public boolean equals(ConditionalFunction<?> that) {
+ public boolean equals(ConditionalFunction<?, ?> that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenFunc.equals(that.thenFunc)
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryFunction.java
similarity index 60%
rename from core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryFunction.java
index 13e0841..b5afa44 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryFunction.java
@@ -18,19 +18,19 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryFunction UnaryFunction}
+ * A {@link NullaryFunction NullaryFunction}
* similiar to Java's "ternary"
* or "conditional" operator (<code>? :</code>).
- * Given a {@link UnaryPredicate predicate}
- * <i>p</i> and {@link UnaryFunction functions}
- * <i>f</i> and <i>g</i>, {@link #evaluate evalautes}
+ * Given a {@link NullaryPredicate predicate}
+ * <i>p</i> and {@link NullaryFunction functions}
+ * <i>f</i> and <i>g</i>, {@link #evaluate evaluates}
* to
- * <code>p.test(x) ? f.evaluate(x) : g.evaluate(x)</code>.
+ * <code>p.test() ? f.evaluate() : g.evaluate()</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -39,15 +39,14 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the argument type.
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class ConditionalUnaryFunction<A, T> implements UnaryFunction<A, T>, Serializable {
+public final class ConditionalNullaryFunction<T> implements NullaryFunction<T>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -8152490481969255068L;
+ private static final long serialVersionUID = 4214871352184887792L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
@@ -56,29 +55,29 @@
/**
* the condition to be evaluated.
*/
- private final UnaryPredicate<? super A> ifPred;
+ private final NullaryPredicate ifPred;
/**
* the function executed if the condition is satisfied.
*/
- private final UnaryFunction<? super A, ? extends T> thenFunc;
+ private final NullaryFunction<? extends T> thenFunc;
/**
* the function executed if the condition is not satisfied.
*/
- private final UnaryFunction<? super A, ? extends T> elseFunc;
+ private final NullaryFunction<? extends T> elseFunc;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new ConditionalUnaryFunction.
+ * Create a new ConditionalNullaryFunction.
* @param ifPred if
* @param thenFunc then
* @param elseFunc else
*/
- public ConditionalUnaryFunction(UnaryPredicate<? super A> ifPred, UnaryFunction<? super A, ? extends T> thenFunc,
- UnaryFunction<? super A, ? extends T> elseFunc) {
- this.ifPred = Validate.notNull(ifPred, "UnaryPredicate argument was null");
- this.thenFunc = Validate.notNull(thenFunc, "'then' UnaryFunction argument was null");
- this.elseFunc = Validate.notNull(elseFunc, "'else' UnaryFunction argument was null");
+ public ConditionalNullaryFunction(NullaryPredicate ifPred, NullaryFunction<? extends T> thenFunc,
+ NullaryFunction<? extends T> elseFunc) {
+ this.ifPred = Validate.notNull(ifPred, "NullaryPredicate argument was null");
+ this.thenFunc = Validate.notNull(thenFunc, "'then' NullaryFunction argument was null");
+ this.elseFunc = Validate.notNull(elseFunc, "'else' NullaryFunction argument was null");
}
// predicate interface
@@ -86,11 +85,11 @@
/**
* {@inheritDoc}
*/
- public T evaluate(A obj) {
- if (ifPred.test(obj)) {
- return thenFunc.evaluate(obj);
+ public T evaluate() {
+ if (ifPred.test()) {
+ return thenFunc.evaluate();
} else {
- return elseFunc.evaluate(obj);
+ return elseFunc.evaluate();
}
}
@@ -99,16 +98,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalUnaryFunction<?, ?>
- && equals((ConditionalUnaryFunction<?, ?>) that));
+ return that == this || (that instanceof ConditionalNullaryFunction<?>
+ && equals((ConditionalNullaryFunction<?>) that));
}
/**
- * Learn whether another ConditionalUnaryFunction is equal to this.
- * @param that ConditionalUnaryFunction to test
+ * Learn whether another ConditionalNullaryFunction is equal to this.
+ * @param that ConditionalNullaryFunction to test
* @return boolean
*/
- public boolean equals(ConditionalUnaryFunction<?, ?> that) {
+ public boolean equals(ConditionalNullaryFunction<?> that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenFunc.equals(that.thenFunc)
@@ -120,7 +119,7 @@
*/
@Override
public int hashCode() {
- int hash = "ConditionalUnaryFunction".hashCode();
+ int hash = "ConditionalNullaryFunction".hashCode();
hash <<= HASH_SHIFT;
hash ^= ifPred.hashCode();
hash <<= HASH_SHIFT;
@@ -135,7 +134,7 @@
*/
@Override
public String toString() {
- return "ConditionalUnaryFunction<" + ifPred + "?" + thenFunc + ":" + elseFunc + ">";
+ return "ConditionalNullaryFunction<" + ifPred + "?" + thenFunc + ":" + elseFunc + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryPredicate.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryPredicate.java
index abfd7fc..b3f509c 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryPredicate.java
@@ -18,18 +18,18 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryPredicate UnaryPredicate}
+ * A {@link NullaryPredicate NullaryPredicate}
* similiar to Java's "ternary"
* or "conditional" operator (<code>? :</code>).
- * Given three {@link UnaryPredicate predicate}
+ * Given three {@link NullaryPredicate predicates}
* <i>p</i>, <i>q</i>, <i>r</i>,
* {@link #test tests}
* to
- * <code>p.test(x) ? q.test(x) : r.test(x)</code>.
+ * <code>p.test() ? q.test() : r.test()</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -38,14 +38,13 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the predicate argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class ConditionalUnaryPredicate<A> implements UnaryPredicate<A>, Serializable {
+public final class ConditionalNullaryPredicate implements NullaryPredicate, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 1214714029872180155L;
+ private static final long serialVersionUID = 7333505000745854098L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
@@ -54,29 +53,28 @@
/**
* the condition to be evaluated.
*/
- private final UnaryPredicate<? super A> ifPred;
+ private final NullaryPredicate ifPred;
/**
* the predicate executed if the condition is satisfied.
*/
- private final UnaryPredicate<? super A> thenPred;
+ private final NullaryPredicate thenPred;
/**
* the predicate executed if the condition is not satisfied.
*/
- private final UnaryPredicate<? super A> elsePred;
+ private final NullaryPredicate elsePred;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new ConditionalUnaryPredicate.
+ * Create a new ConditionalNullaryPredicate.
* @param ifPred if
* @param thenPred then
* @param elsePred else
*/
- public ConditionalUnaryPredicate(UnaryPredicate<? super A> ifPred, UnaryPredicate<? super A> thenPred,
- UnaryPredicate<? super A> elsePred) {
- this.ifPred = Validate.notNull(ifPred, "'if' UnaryPredicate argument was null");
- this.thenPred = Validate.notNull(thenPred, "'then' UnaryPredicate argument was null");
- this.elsePred = Validate.notNull(elsePred, "'else' UnaryPredicate argument was null");
+ public ConditionalNullaryPredicate(NullaryPredicate ifPred, NullaryPredicate thenPred, NullaryPredicate elsePred) {
+ this.ifPred = Validate.notNull(ifPred, "'if' NullaryPredicate argument was null");
+ this.thenPred = Validate.notNull(thenPred, "'then' NullaryPredicate argument was null");
+ this.elsePred = Validate.notNull(elsePred, "'else' NullaryPredicate argument was null");
}
// predicate interface
@@ -84,8 +82,8 @@
/**
* {@inheritDoc}
*/
- public boolean test(A obj) {
- return ifPred.test(obj) ? thenPred.test(obj) : elsePred.test(obj);
+ public boolean test() {
+ return ifPred.test() ? thenPred.test() : elsePred.test();
}
/**
@@ -93,16 +91,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalUnaryPredicate<?>
- && equals((ConditionalUnaryPredicate<?>) that));
+ return that == this || (that instanceof ConditionalNullaryPredicate
+ && equals((ConditionalNullaryPredicate) that));
}
/**
- * Learn whether another ConditionalUnaryPredicate is equal to this.
- * @param that ConditionalUnaryPredicate to test
+ * Learn whether another ConditionalNullaryPredicate is equal to this.
+ * @param that ConditionalNullaryPredicate to test
* @return boolean
*/
- public boolean equals(ConditionalUnaryPredicate<?> that) {
+ public boolean equals(ConditionalNullaryPredicate that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenPred.equals(that.thenPred)
@@ -114,7 +112,7 @@
*/
@Override
public int hashCode() {
- int hash = "ConditionalUnaryPredicate".hashCode();
+ int hash = "ConditionalNullaryPredicate".hashCode();
hash <<= HASH_SHIFT;
hash ^= ifPred.hashCode();
hash <<= HASH_SHIFT;
@@ -129,7 +127,7 @@
*/
@Override
public String toString() {
- return "ConditionalUnaryPredicate<" + ifPred + "?" + thenPred + ":" + elsePred + ">";
+ return "ConditionalNullaryPredicate<" + ifPred + "?" + thenPred + ":" + elsePred + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryProcedure.java
similarity index 61%
rename from core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryProcedure.java
index 0d4317f..3e35885 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalUnaryProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalNullaryProcedure.java
@@ -18,19 +18,19 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.NoOp;
import org.apache.commons.lang3.Validate;
/**
- * A {@link UnaryProcedure UnaryProcedure}
+ * A {@link NullaryProcedure NullaryProcedure}
* similiar to Java's "ternary"
* or "conditional" operator (<code>? :</code>).
- * Given a {@link UnaryPredicate predicate}
- * <i>p</i> and {@link UnaryProcedure procedures}
+ * Given a {@link NullaryPredicate predicate}
+ * <i>p</i> and {@link NullaryProcedure procedures}
* <i>q</i> and <i>r</i>, {@link #run runs}
- * <code>if (p.test(x)) { q.run(x); } else { r.run(x); }</code>.
+ * <code>if (p.test()) { q.run(); } else { r.run(); }</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -39,55 +39,53 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class ConditionalUnaryProcedure<A> implements UnaryProcedure<A>, Serializable {
+public final class ConditionalNullaryProcedure implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -895833369740247391L;
+ private static final long serialVersionUID = -4228632798836328605L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
+
// attributes
// ------------------------------------------------------------------------
/**
* the condition to be evaluated.
*/
- private final UnaryPredicate<? super A> ifPred;
+ private final NullaryPredicate ifPred;
/**
* the procedure executed if the condition is satisfied.
*/
- private final UnaryProcedure<? super A> thenProc;
+ private final NullaryProcedure thenProc;
/**
* the procedure executed if the condition is not satisfied.
*/
- private final UnaryProcedure<? super A> elseProc;
+ private final NullaryProcedure elseProc;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new ConditionalUnaryProcedure.
+ * Create a new ConditionalNullaryProcedure.
* @param ifPred if
* @param thenProc then
*/
- public ConditionalUnaryProcedure(UnaryPredicate<? super A> ifPred, UnaryProcedure<? super A> thenProc) {
+ public ConditionalNullaryProcedure(NullaryPredicate ifPred, NullaryProcedure thenProc) {
this(ifPred, thenProc, NoOp.instance());
}
/**
- * Create a new ConditionalUnaryProcedure.
+ * Create a new ConditionalNullaryProcedure.
* @param ifPred if
* @param thenProc then
* @param elseProc else
*/
- public ConditionalUnaryProcedure(UnaryPredicate<? super A> ifPred,
- UnaryProcedure<? super A> thenProc,
- UnaryProcedure<? super A> elseProc) {
- this.ifPred = Validate.notNull(ifPred, "UnaryPredicate argument was null");
- this.thenProc = Validate.notNull(thenProc, "'then' UnaryProcedure argument was null");
- this.elseProc = Validate.notNull(elseProc, "'else' UnaryProcedure argument was null");
+ public ConditionalNullaryProcedure(NullaryPredicate ifPred, NullaryProcedure thenProc, NullaryProcedure elseProc) {
+ this.ifPred = Validate.notNull(ifPred, "NullaryPredicate argument was null");
+ this.thenProc = Validate.notNull(thenProc, "'then' NullaryProcedure argument was null");
+ this.elseProc = Validate.notNull(elseProc, "'else' NullaryProcedure argument was null");
}
// predicate interface
@@ -95,11 +93,11 @@
/**
* {@inheritDoc}
*/
- public void run(A obj) {
- if (ifPred.test(obj)) {
- thenProc.run(obj);
+ public void run() {
+ if (ifPred.test()) {
+ thenProc.run();
} else {
- elseProc.run(obj);
+ elseProc.run();
}
}
@@ -108,16 +106,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalUnaryProcedure<?>
- && equals((ConditionalUnaryProcedure<?>) that));
+ return that == this || (that instanceof ConditionalNullaryProcedure
+ && equals((ConditionalNullaryProcedure) that));
}
/**
- * Learn whether another ConditionalUnaryProcedure is equal to this.
- * @param that ConditionalUnaryProcedure to test
+ * Learn whether another ConditionalProcecure is equal to this.
+ * @param that the ConditionalNullaryProcedure to test
* @return boolean
*/
- public boolean equals(ConditionalUnaryProcedure<?> that) {
+ public boolean equals(ConditionalNullaryProcedure that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenProc.equals(that.thenProc)
@@ -129,7 +127,7 @@
*/
@Override
public int hashCode() {
- int hash = "ConditionalUnaryProcedure".hashCode();
+ int hash = "ConditionalNullaryProcedure".hashCode();
hash <<= HASH_SHIFT;
hash ^= ifPred.hashCode();
hash <<= HASH_SHIFT;
@@ -144,7 +142,7 @@
*/
@Override
public String toString() {
- return "ConditionalUnaryProcedure<" + ifPred + "?" + thenProc + ":" + elseProc + ">";
+ return "ConditionalNullaryProcedure<" + ifPred + "?" + thenProc + ":" + elseProc + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
index 1390b7f..a9e8502 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalPredicate.java
@@ -25,11 +25,11 @@
* A {@link Predicate Predicate}
* similiar to Java's "ternary"
* or "conditional" operator (<code>? :</code>).
- * Given three {@link Predicate predicates}
+ * Given three {@link Predicate predicate}
* <i>p</i>, <i>q</i>, <i>r</i>,
* {@link #test tests}
* to
- * <code>p.test() ? q.test() : r.test()</code>.
+ * <code>p.test(x) ? q.test(x) : r.test(x)</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -38,13 +38,14 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-public final class ConditionalPredicate implements Predicate, Serializable {
+public final class ConditionalPredicate<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 7333505000745854098L;
+ private static final long serialVersionUID = 1214714029872180155L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
@@ -53,15 +54,15 @@
/**
* the condition to be evaluated.
*/
- private final Predicate ifPred;
+ private final Predicate<? super A> ifPred;
/**
* the predicate executed if the condition is satisfied.
*/
- private final Predicate thenPred;
+ private final Predicate<? super A> thenPred;
/**
* the predicate executed if the condition is not satisfied.
*/
- private final Predicate elsePred;
+ private final Predicate<? super A> elsePred;
// constructor
// ------------------------------------------------------------------------
@@ -71,7 +72,8 @@
* @param thenPred then
* @param elsePred else
*/
- public ConditionalPredicate(Predicate ifPred, Predicate thenPred, Predicate elsePred) {
+ public ConditionalPredicate(Predicate<? super A> ifPred, Predicate<? super A> thenPred,
+ Predicate<? super A> elsePred) {
this.ifPred = Validate.notNull(ifPred, "'if' Predicate argument was null");
this.thenPred = Validate.notNull(thenPred, "'then' Predicate argument was null");
this.elsePred = Validate.notNull(elsePred, "'else' Predicate argument was null");
@@ -82,8 +84,8 @@
/**
* {@inheritDoc}
*/
- public boolean test() {
- return ifPred.test() ? thenPred.test() : elsePred.test();
+ public boolean test(A obj) {
+ return ifPred.test(obj) ? thenPred.test(obj) : elsePred.test(obj);
}
/**
@@ -91,7 +93,8 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalPredicate && equals((ConditionalPredicate) that));
+ return that == this || (that instanceof ConditionalPredicate<?>
+ && equals((ConditionalPredicate<?>) that));
}
/**
@@ -99,7 +102,7 @@
* @param that ConditionalPredicate to test
* @return boolean
*/
- public boolean equals(ConditionalPredicate that) {
+ public boolean equals(ConditionalPredicate<?> that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenPred.equals(that.thenPred)
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
index cc1a41c..73f24b5 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/ConditionalProcedure.java
@@ -30,7 +30,7 @@
* Given a {@link Predicate predicate}
* <i>p</i> and {@link Procedure procedures}
* <i>q</i> and <i>r</i>, {@link #run runs}
- * <code>if (p.test()) { q.run(); } else { r.run(); }</code>.
+ * <code>if (p.test(x)) { q.run(x); } else { r.run(x); }</code>.
* <p>
* Note that although this class implements
* {@link Serializable}, a given instance will
@@ -39,31 +39,31 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class ConditionalProcedure implements Procedure, Serializable {
+public final class ConditionalProcedure<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -4228632798836328605L;
+ private static final long serialVersionUID = -895833369740247391L;
/** Base hash integer used to shift hash. */
private static final int HASH_SHIFT = 4;
-
// attributes
// ------------------------------------------------------------------------
/**
* the condition to be evaluated.
*/
- private final Predicate ifPred;
+ private final Predicate<? super A> ifPred;
/**
* the procedure executed if the condition is satisfied.
*/
- private final Procedure thenProc;
+ private final Procedure<? super A> thenProc;
/**
* the procedure executed if the condition is not satisfied.
*/
- private final Procedure elseProc;
+ private final Procedure<? super A> elseProc;
// constructor
// ------------------------------------------------------------------------
@@ -72,7 +72,7 @@
* @param ifPred if
* @param thenProc then
*/
- public ConditionalProcedure(Predicate ifPred, Procedure thenProc) {
+ public ConditionalProcedure(Predicate<? super A> ifPred, Procedure<? super A> thenProc) {
this(ifPred, thenProc, NoOp.instance());
}
@@ -82,7 +82,9 @@
* @param thenProc then
* @param elseProc else
*/
- public ConditionalProcedure(Predicate ifPred, Procedure thenProc, Procedure elseProc) {
+ public ConditionalProcedure(Predicate<? super A> ifPred,
+ Procedure<? super A> thenProc,
+ Procedure<? super A> elseProc) {
this.ifPred = Validate.notNull(ifPred, "Predicate argument was null");
this.thenProc = Validate.notNull(thenProc, "'then' Procedure argument was null");
this.elseProc = Validate.notNull(elseProc, "'else' Procedure argument was null");
@@ -93,11 +95,11 @@
/**
* {@inheritDoc}
*/
- public void run() {
- if (ifPred.test()) {
- thenProc.run();
+ public void run(A obj) {
+ if (ifPred.test(obj)) {
+ thenProc.run(obj);
} else {
- elseProc.run();
+ elseProc.run(obj);
}
}
@@ -106,15 +108,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof ConditionalProcedure && equals((ConditionalProcedure) that));
+ return that == this || (that instanceof ConditionalProcedure<?>
+ && equals((ConditionalProcedure<?>) that));
}
/**
- * Learn whether another ConditionalProcecure is equal to this.
- * @param that the ConditionalProcedure to test
+ * Learn whether another ConditionalProcedure is equal to this.
+ * @param that ConditionalProcedure to test
* @return boolean
*/
- public boolean equals(ConditionalProcedure that) {
+ public boolean equals(ConditionalProcedure<?> that) {
return null != that
&& ifPred.equals(that.ifPred)
&& thenProc.equals(that.thenProc)
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/DoWhileNullaryProcedure.java
similarity index 72%
rename from core/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/DoWhileNullaryProcedure.java
index 7cedd69..e764931 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/DoWhileProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/DoWhileNullaryProcedure.java
@@ -16,13 +16,13 @@
*/
package org.apache.commons.functor.core.composite;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
- * A {@link Procedure} implementation of a while loop. Given a {@link Predicate}
- * <i>c</i> and an {@link Procedure} <i>p</i>, {@link #run runs}
+ * A {@link NullaryProcedure} implementation of a while loop. Given a {@link NullaryPredicate}
+ * <i>c</i> and an {@link NullaryProcedure} <i>p</i>, {@link #run runs}
* <code>do { p.run(); } while(c.test())</code>.
* <p>
* Note that although this class implements
@@ -32,20 +32,20 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class DoWhileProcedure extends AbstractLoopProcedure {
+public class DoWhileNullaryProcedure extends AbstractLoopNullaryProcedure {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = -6064417600588553892L;
/**
- * Create a new DoWhileProcedure.
+ * Create a new DoWhileNullaryProcedure.
* @param action to do
* @param condition while true
*/
- public DoWhileProcedure(Procedure action, Predicate condition) {
+ public DoWhileNullaryProcedure(NullaryProcedure action, NullaryPredicate condition) {
super(condition, action);
}
@@ -63,6 +63,6 @@
*/
@Override
public String toString() {
- return "DoWhileProcedure<do(" + getAction() + ") while(" + getCondition() + ")>";
+ return "DoWhileNullaryProcedure<do(" + getAction() + ") while(" + getCondition() + ")>";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/Not.java b/core/src/main/java/org/apache/commons/functor/core/composite/Not.java
index 9f49d4e..939343e 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/Not.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/Not.java
@@ -32,20 +32,20 @@
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public final class Not implements Predicate, Serializable {
-
+public final class Not<A> implements Predicate<A>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 8268713706856765874L;
+ private static final long serialVersionUID = -97785102566566058L;
// attributes
// ------------------------------------------------------------------------
/**
- * The adapted predicate has to be negated.
+ * The adapted predicate.
*/
- private final Predicate predicate;
+ private final Predicate<? super A> predicate;
// constructor
// ------------------------------------------------------------------------
@@ -53,7 +53,7 @@
* Create a new Not.
* @param predicate Predicate to negate
*/
- public Not(Predicate predicate) {
+ public Not(Predicate<? super A> predicate) {
this.predicate = Validate.notNull(predicate, "Predicate argument was null");
}
@@ -62,8 +62,8 @@
/**
* {@inheritDoc}
*/
- public boolean test() {
- return !(predicate.test());
+ public boolean test(A obj) {
+ return !(predicate.test(obj));
}
/**
@@ -71,15 +71,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof Not && equals((Not) that));
+ return that == this || (that instanceof Not<?> && equals((Not<?>) that));
}
/**
* Learn whether another Not is equal to this.
- * @param that the Not to test
+ * @param that Not to test
* @return boolean
*/
- public boolean equals(Not that) {
+ public boolean equals(Not<?> that) {
return null != that && predicate.equals(that.predicate);
}
@@ -104,11 +104,13 @@
// static
// ------------------------------------------------------------------------
/**
- * Get a Not instance for <code>that</code>.
- * @param that Predicate to negate
- * @return Not
+ * Invert a Predicate.
+ * @param <A> the argument type.
+ * @param pred Predicate to invert
+ * @return Predicate<A>
*/
- public static Predicate not(Predicate that) {
- return null == that ? null : new Not(that);
+ public static <A> Predicate<A> not(Predicate<? super A> pred) {
+ return null == pred ? null : new Not<A>(pred);
}
+
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryAnd.java b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryAnd.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnaryAnd.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/NullaryAnd.java
index 142f4db..9b0f67d 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryAnd.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryAnd.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.core.composite;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
/**
* {@link #test Tests} <code>true</code> iff
@@ -31,52 +31,52 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the predicate argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class UnaryAnd<A> extends BaseUnaryPredicateList<A> {
+public final class NullaryAnd extends BaseNullaryPredicateList {
+
+ // constructor
+ // ------------------------------------------------------------------------
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 8324861737107307302L;
+ private static final long serialVersionUID = -6053343095016685571L;
- // constructor
- // ------------------------------------------------------------------------
/**
- * Create a new UnaryAnd.
+ * Create a new NullaryAnd.
*/
- public UnaryAnd() {
+ public NullaryAnd() {
super();
}
/**
- * Create a new UnaryAnd instance.
+ * Create a new NullaryAnd instance.
*
- * @param predicates the predicates to put in unary and.
+ * @param predicates the predicates to add
*/
- public UnaryAnd(Iterable<UnaryPredicate<? super A>> predicates) {
+ public NullaryAnd(Iterable<NullaryPredicate> predicates) {
super(predicates);
}
/**
- * Create a new UnaryAnd instance.
+ * Create a new NullaryAnd instance.
*
- * @param predicates the predicates to put in unary and.
+ * @param predicates the predicates to add
*/
- public UnaryAnd(UnaryPredicate<? super A>... predicates) {
+ public NullaryAnd(NullaryPredicate... predicates) {
super(predicates);
}
// modifiers
// ------------------------------------------------------------------------
/**
- * Fluently add a UnaryPredicate.
- * @param p UnaryPredicate to add
+ * Add a Predicate.
+ * @param p Predicate to add
* @return this
*/
- public UnaryAnd<A> and(UnaryPredicate<? super A> p) {
- super.addUnaryPredicate(p);
+ public NullaryAnd and(NullaryPredicate p) {
+ super.addNullaryPredicate(p);
return this;
}
@@ -85,9 +85,9 @@
/**
* {@inheritDoc}
*/
- public boolean test(A obj) {
- for (UnaryPredicate<? super A> p : getUnaryPredicateList()) {
- if (!p.test(obj)) {
+ public boolean test() {
+ for (NullaryPredicate p : getNullaryPredicateList()) {
+ if (!p.test()) {
return false;
}
}
@@ -99,16 +99,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof UnaryAnd<?> && equals((UnaryAnd<?>) that));
+ return that == this || (that instanceof NullaryAnd && equals((NullaryAnd) that));
}
/**
- * Learn whether another UnaryAnd is equal to this.
- * @param that UnaryAnd to test
+ * Learn whether a given And is equal to this.
+ * @param that the And to test
* @return boolean
*/
- public boolean equals(UnaryAnd<?> that) {
- return getUnaryPredicateListEquals(that);
+ public boolean equals(NullaryAnd that) {
+ return getNullaryPredicateListEquals(that);
}
/**
@@ -116,7 +116,7 @@
*/
@Override
public int hashCode() {
- return "UnaryAnd".hashCode() ^ getUnaryPredicateListHashCode();
+ return "And".hashCode() ^ getNullaryPredicateListHashCode();
}
/**
@@ -124,7 +124,7 @@
*/
@Override
public String toString() {
- return "UnaryAnd<" + getUnaryPredicateListToString() + ">";
+ return "And<" + getNullaryPredicateListToString() + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java
similarity index 65%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java
index a76c6d6..ba973b3 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryNot.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java
@@ -18,7 +18,7 @@
import java.io.Serializable;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.lang3.Validate;
/**
@@ -32,29 +32,29 @@
* an instance whose delegate is not
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public final class UnaryNot<A> implements UnaryPredicate<A>, Serializable {
+public final class NullaryNot implements NullaryPredicate, Serializable {
+
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -97785102566566058L;
+ private static final long serialVersionUID = 8268713706856765874L;
// attributes
// ------------------------------------------------------------------------
/**
- * The adapted predicate.
+ * The adapted predicate has to be negated.
*/
- private final UnaryPredicate<? super A> predicate;
+ private final NullaryPredicate predicate;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new UnaryNot.
- * @param predicate UnaryPredicate to negate
+ * Create a new NullaryNot.
+ * @param predicate NullaryPredicate to negate
*/
- public UnaryNot(UnaryPredicate<? super A> predicate) {
- this.predicate = Validate.notNull(predicate, "UnaryPredicate argument was null");
+ public NullaryNot(NullaryPredicate predicate) {
+ this.predicate = Validate.notNull(predicate, "NullaryPredicate argument was null");
}
// predicate interface
@@ -62,8 +62,8 @@
/**
* {@inheritDoc}
*/
- public boolean test(A obj) {
- return !(predicate.test(obj));
+ public boolean test() {
+ return !(predicate.test());
}
/**
@@ -71,15 +71,15 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof UnaryNot<?> && equals((UnaryNot<?>) that));
+ return that == this || (that instanceof NullaryNot && equals((NullaryNot) that));
}
/**
- * Learn whether another UnaryNot is equal to this.
- * @param that UnaryNot to test
+ * Learn whether another NullaryNot is equal to this.
+ * @param that the NullaryNot to test
* @return boolean
*/
- public boolean equals(UnaryNot<?> that) {
+ public boolean equals(NullaryNot that) {
return null != that && predicate.equals(that.predicate);
}
@@ -88,7 +88,7 @@
*/
@Override
public int hashCode() {
- int hash = "UnaryNot".hashCode();
+ int hash = "Not".hashCode();
hash ^= predicate.hashCode();
return hash;
}
@@ -98,19 +98,17 @@
*/
@Override
public String toString() {
- return "UnaryNot<" + predicate + ">";
+ return "Not<" + predicate + ">";
}
// static
// ------------------------------------------------------------------------
/**
- * Invert a UnaryPredicate.
- * @param <A> the argument type.
- * @param pred UnaryPredicate to invert
- * @return UnaryPredicate<A>
+ * Get a NullaryNot instance for <code>that</code>.
+ * @param that Predicate to negate
+ * @return NullaryNot
*/
- public static <A> UnaryPredicate<A> not(UnaryPredicate<? super A> pred) {
- return null == pred ? null : new UnaryNot<A>(pred);
+ public static NullaryPredicate not(NullaryPredicate that) {
+ return null == that ? null : new NullaryNot(that);
}
-
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryOr.java b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryOr.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnaryOr.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/NullaryOr.java
index 6122916..02f10c5 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnaryOr.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/NullaryOr.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.core.composite;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
/**
* {@link #test Tests} <code>true</code> iff
@@ -31,52 +31,49 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the predicate argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public final class UnaryOr<A> extends BaseUnaryPredicateList<A> {
+public final class NullaryOr extends BaseNullaryPredicateList {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -4072936447932983645L;
+ private static final long serialVersionUID = -1636233158061690073L;
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new UnaryOr.
+ * Create a new NullaryOr.
*/
- public UnaryOr() {
+ public NullaryOr() {
super();
}
/**
- * Create a new UnaryOr instance.
+ * Create a new NullaryOr instance.
*
- * @param predicates the predicates to put in unary or.
+ * @param predicates predicates have to be put in nullary or condition.
*/
- public UnaryOr(Iterable<UnaryPredicate<? super A>> predicates) {
+ public NullaryOr(Iterable<NullaryPredicate> predicates) {
super(predicates);
}
/**
- * Create a new UnaryOr instance.
+ * Create a new NullaryOr instance.
*
- * @param predicates the predicates to put in unary or.
+ * @param predicates predicates have to be put in nullary or condition.
*/
- public UnaryOr(UnaryPredicate<? super A>... predicates) {
+ public NullaryOr(NullaryPredicate... predicates) {
super(predicates);
}
- // modifiers
- // ------------------------------------------------------------------------
/**
- * Fluently add a Predicate.
- * @param p Predicate to add
+ * Fluently add a NullaryPredicate.
+ * @param p NullaryPredicate to add
* @return this
*/
- public UnaryOr<A> or(UnaryPredicate<? super A> p) {
- super.addUnaryPredicate(p);
+ public NullaryOr or(NullaryPredicate p) {
+ super.addNullaryPredicate(p);
return this;
}
@@ -85,9 +82,9 @@
/**
* {@inheritDoc}
*/
- public boolean test(A a) {
- for (UnaryPredicate<? super A> p : getUnaryPredicateList()) {
- if (p.test(a)) {
+ public boolean test() {
+ for (NullaryPredicate p : getNullaryPredicateList()) {
+ if (p.test()) {
return true;
}
}
@@ -99,16 +96,16 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof UnaryOr<?> && equals((UnaryOr<?>) that));
+ return that == this || (that instanceof NullaryOr && equals((NullaryOr) that));
}
/**
- * Learn whether another UnaryOr is equal to this.
- * @param that UnaryOr to test
+ * Learn whether another NullaryOr is equal to this.
+ * @param that NullaryOr to test
* @return boolean
*/
- public boolean equals(UnaryOr<?> that) {
- return getUnaryPredicateListEquals(that);
+ public boolean equals(NullaryOr that) {
+ return getNullaryPredicateListEquals(that);
}
/**
@@ -116,7 +113,7 @@
*/
@Override
public int hashCode() {
- return "UnaryOr".hashCode() ^ getUnaryPredicateListHashCode();
+ return "NullaryOr".hashCode() ^ getNullaryPredicateListHashCode();
}
/**
@@ -124,7 +121,7 @@
*/
@Override
public String toString() {
- return "UnaryOr<" + getUnaryPredicateListToString() + ">";
+ return "NullaryOr<" + getNullaryPredicateListToString() + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java b/core/src/main/java/org/apache/commons/functor/core/composite/NullarySequence.java
similarity index 62%
rename from core/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/NullarySequence.java
index 05c6de8..ced5b45 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/NullarySequence.java
@@ -21,12 +21,12 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
/**
- * A {@link UnaryProcedure UnaryProcedure}
- * that {@link UnaryProcedure#run runs} an ordered
- * sequence of {@link UnaryProcedure UnaryProcedures}.
+ * A {@link NullaryProcedure NullaryProcedure}
+ * that {@link NullaryProcedure#run runs} an ordered
+ * sequence of {@link NullaryProcedure NullaryProcedures}.
* When the sequence is empty, this procedure is does
* nothing.
* <p>
@@ -37,54 +37,53 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @param <A> the argument type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class UnarySequence<A> implements UnaryProcedure<A>, Serializable {
+public class NullarySequence implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 9194268249717820246L;
+ private static final long serialVersionUID = 8041703589149547883L;
// attributes
// ------------------------------------------------------------------------
/**
- * The data structure to store the procedure sequence.
+ * The data structure where storing procedures sequence.
*/
- private final List<UnaryProcedure<? super A>> list = new ArrayList<UnaryProcedure<? super A>>();
+ private List<NullaryProcedure> list = new ArrayList<NullaryProcedure>();
// constructor
// ------------------------------------------------------------------------
/**
- * Create a new UnarySequence.
+ * Create a new NullarySequence.
*/
- public UnarySequence() {
+ public NullarySequence() {
super();
}
/**
- * Create a new UnarySequence instance.
+ * Create a new NullarySequence instance.
*
* @param procedures to run sequentially
*/
- public UnarySequence(UnaryProcedure<? super A>... procedures) {
+ public NullarySequence(NullaryProcedure... procedures) {
this();
if (procedures != null) {
- for (UnaryProcedure<? super A> p : procedures) {
+ for (NullaryProcedure p : procedures) {
then(p);
}
}
}
/**
- * Create a new UnarySequence instance.
+ * Create a new NullarySequence instance.
*
* @param procedures to run sequentially
*/
- public UnarySequence(Iterable<UnaryProcedure<? super A>> procedures) {
+ public NullarySequence(Iterable<NullaryProcedure> procedures) {
this();
if (procedures != null) {
- for (UnaryProcedure<? super A> p : procedures) {
+ for (NullaryProcedure p : procedures) {
then(p);
}
}
@@ -93,11 +92,11 @@
// modifiers
// ------------------------------------------------------------------------
/**
- * Fluently add a UnaryProcedure to the sequence.
- * @param p UnaryProcedure to add
+ * Fluently add a NullaryProcedure.
+ * @param p NullaryProcedure to add
* @return this
*/
- public UnarySequence<A> then(UnaryProcedure<? super A> p) {
+ public final NullarySequence then(NullaryProcedure p) {
if (p != null) {
list.add(p);
}
@@ -109,9 +108,9 @@
/**
* {@inheritDoc}
*/
- public void run(A obj) {
- for (Iterator<UnaryProcedure<? super A>> iter = list.iterator(); iter.hasNext();) {
- iter.next().run(obj);
+ public final void run() {
+ for (Iterator<NullaryProcedure> iter = list.iterator(); iter.hasNext();) {
+ iter.next().run();
}
}
@@ -119,16 +118,16 @@
* {@inheritDoc}
*/
@Override
- public boolean equals(Object that) {
- return that == this || (that instanceof UnarySequence<?> && equals((UnarySequence<?>) that));
+ public final boolean equals(Object that) {
+ return that == this || (that instanceof NullarySequence && equals((NullarySequence) that));
}
/**
- * Learn whether another UnarySequence is equal to this.
- * @param that UnarySequence to test
+ * Learn whether a given NullarySequence is equal to this.
+ * @param that NullarySequence to test
* @return boolean
*/
- public boolean equals(UnarySequence<?> that) {
+ public boolean equals(NullarySequence that) {
// by construction, list is never null
return null != that && list.equals(that.list);
}
@@ -139,7 +138,7 @@
@Override
public int hashCode() {
// by construction, list is never null
- return "UnarySequence".hashCode() ^ list.hashCode();
+ return "NullarySequence".hashCode() ^ list.hashCode();
}
/**
@@ -147,7 +146,7 @@
*/
@Override
public String toString() {
- return "UnarySequence<" + list + ">";
+ return "NullarySequence<" + list + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/Or.java b/core/src/main/java/org/apache/commons/functor/core/composite/Or.java
index a734197..56dd3a8 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/Or.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/Or.java
@@ -31,14 +31,15 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the predicate argument type.
* @version $Revision$ $Date$
*/
-public final class Or extends BasePredicateList {
+public final class Or<A> extends BasePredicateList<A> {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = -1636233158061690073L;
+ private static final long serialVersionUID = -4072936447932983645L;
// constructor
// ------------------------------------------------------------------------
@@ -52,27 +53,29 @@
/**
* Create a new Or instance.
*
- * @param predicates predicates have to be put in or condition.
+ * @param predicates the predicates to put in or.
*/
- public Or(Iterable<Predicate> predicates) {
+ public Or(Iterable<Predicate<? super A>> predicates) {
super(predicates);
}
/**
* Create a new Or instance.
*
- * @param predicates predicates have to be put in or condition.
+ * @param predicates the predicates to put in or.
*/
- public Or(Predicate... predicates) {
+ public Or(Predicate<? super A>... predicates) {
super(predicates);
}
+ // modifiers
+ // ------------------------------------------------------------------------
/**
* Fluently add a Predicate.
* @param p Predicate to add
* @return this
*/
- public Or or(Predicate p) {
+ public Or<A> or(Predicate<? super A> p) {
super.addPredicate(p);
return this;
}
@@ -82,9 +85,9 @@
/**
* {@inheritDoc}
*/
- public boolean test() {
- for (Predicate p : getPredicateList()) {
- if (p.test()) {
+ public boolean test(A a) {
+ for (Predicate<? super A> p : getPredicateList()) {
+ if (p.test(a)) {
return true;
}
}
@@ -96,7 +99,7 @@
*/
@Override
public boolean equals(Object that) {
- return that == this || (that instanceof Or && equals((Or) that));
+ return that == this || (that instanceof Or<?> && equals((Or<?>) that));
}
/**
@@ -104,7 +107,7 @@
* @param that Or to test
* @return boolean
*/
- public boolean equals(Or that) {
+ public boolean equals(Or<?> that) {
return getPredicateListEquals(that);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/Sequence.java b/core/src/main/java/org/apache/commons/functor/core/composite/Sequence.java
index 434b33b..fc9d911 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/Sequence.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/Sequence.java
@@ -37,20 +37,21 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
+ * @param <A> the argument type.
* @version $Revision$ $Date$
*/
-public class Sequence implements Procedure, Serializable {
+public class Sequence<A> implements Procedure<A>, Serializable {
/**
* serialVersionUID declaration.
*/
- private static final long serialVersionUID = 8041703589149547883L;
+ private static final long serialVersionUID = 9194268249717820246L;
// attributes
// ------------------------------------------------------------------------
/**
- * The data structure where storing procedures sequence.
+ * The data structure to store the procedure sequence.
*/
- private List<Procedure> list = new ArrayList<Procedure>();
+ private final List<Procedure<? super A>> list = new ArrayList<Procedure<? super A>>();
// constructor
// ------------------------------------------------------------------------
@@ -66,10 +67,10 @@
*
* @param procedures to run sequentially
*/
- public Sequence(Procedure... procedures) {
+ public Sequence(Procedure<? super A>... procedures) {
this();
if (procedures != null) {
- for (Procedure p : procedures) {
+ for (Procedure<? super A> p : procedures) {
then(p);
}
}
@@ -80,10 +81,10 @@
*
* @param procedures to run sequentially
*/
- public Sequence(Iterable<Procedure> procedures) {
+ public Sequence(Iterable<Procedure<? super A>> procedures) {
this();
if (procedures != null) {
- for (Procedure p : procedures) {
+ for (Procedure<? super A> p : procedures) {
then(p);
}
}
@@ -92,11 +93,11 @@
// modifiers
// ------------------------------------------------------------------------
/**
- * Fluently add a Procedure.
+ * Fluently add a Procedure to the sequence.
* @param p Procedure to add
* @return this
*/
- public final Sequence then(Procedure p) {
+ public Sequence<A> then(Procedure<? super A> p) {
if (p != null) {
list.add(p);
}
@@ -108,9 +109,9 @@
/**
* {@inheritDoc}
*/
- public final void run() {
- for (Iterator<Procedure> iter = list.iterator(); iter.hasNext();) {
- iter.next().run();
+ public void run(A obj) {
+ for (Iterator<Procedure<? super A>> iter = list.iterator(); iter.hasNext();) {
+ iter.next().run(obj);
}
}
@@ -118,16 +119,16 @@
* {@inheritDoc}
*/
@Override
- public final boolean equals(Object that) {
- return that == this || (that instanceof Sequence && equals((Sequence) that));
+ public boolean equals(Object that) {
+ return that == this || (that instanceof Sequence<?> && equals((Sequence<?>) that));
}
/**
- * Learn whether a given Sequence is equal to this.
+ * Learn whether another Sequence is equal to this.
* @param that Sequence to test
* @return boolean
*/
- public boolean equals(Sequence that) {
+ public boolean equals(Sequence<?> that) {
// by construction, list is never null
return null != that && list.equals(that.list);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryFunction.java
index 5424fb6..25504f7 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryFunction.java
@@ -19,11 +19,11 @@
import java.io.Serializable;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.lang3.Validate;
/**
- * A BinaryFunction whose result is then run through a UnaryFunction.
+ * A BinaryFunction whose result is then run through a Function.
*
* @param <L> the left argument type.
* @param <R> the right argument type.
@@ -53,17 +53,17 @@
/**
* The following function.
*/
- private UnaryFunction<? super X, ? extends T> following;
+ private Function<? super X, ? extends T> following;
/**
* Create a new Helper.
* @param preceding BinaryFunction
- * @param following UnaryFunction
+ * @param following Function
*/
private Helper(BinaryFunction<? super L, ? super R, ? extends X> preceding,
- UnaryFunction<? super X, ? extends T> following) {
+ Function<? super X, ? extends T> following) {
this.preceding = Validate.notNull(preceding, "BinaryFunction argument was null");
- this.following = Validate.notNull(following, "UnaryFunction argument was null");
+ this.following = Validate.notNull(following, "Function argument was null");
}
/**
@@ -83,10 +83,10 @@
* Create a new TransformedBinaryFunction.
* @param <X> the following function left argument.
* @param preceding BinaryFunction
- * @param following UnaryFunction
+ * @param following Function
*/
public <X> TransformedBinaryFunction(BinaryFunction<? super L, ? super R, ? extends X> preceding,
- UnaryFunction<? super X, ? extends T> following) {
+ Function<? super X, ? extends T> following) {
this.helper = new Helper<X, L, R, T>(preceding, following);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryProcedure.java
index 503d71b..c3f1012 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedBinaryProcedure.java
@@ -20,11 +20,11 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * A BinaryProcedure composed of a BinaryFunction whose result is then run through a UnaryProcedure.
+ * A BinaryProcedure composed of a BinaryFunction whose result is then run through a Procedure.
*
* @param <L> the left argument type.
* @param <R> the right argument type.
@@ -53,17 +53,17 @@
/**
* The wrapped procedure.
*/
- private UnaryProcedure<? super X> procedure;
+ private Procedure<? super X> procedure;
/**
* Create a new Helper.
* @param function BinaryFunction
- * @param procedure UnaryFunction
+ * @param procedure Function
*/
private Helper(BinaryFunction<? super L, ? super R, ? extends X> function,
- UnaryProcedure<? super X> procedure) {
+ Procedure<? super X> procedure) {
this.function = Validate.notNull(function, "BinaryFunction argument was null");
- this.procedure = Validate.notNull(procedure, "UnaryProcedure argument was null");
+ this.procedure = Validate.notNull(procedure, "Procedure argument was null");
}
/**
@@ -83,10 +83,10 @@
* Create a new TransformedBinaryProcedure.
* @param <X> the wrapped procedure argument.
* @param function BinaryFunction
- * @param procedure UnaryProcedure
+ * @param procedure Procedure
*/
public <X> TransformedBinaryProcedure(BinaryFunction<? super L, ? super R, ? extends X> function,
- UnaryProcedure<? super X> procedure) {
+ Procedure<? super X> procedure) {
this.helper = new Helper<X, L, R>(function, procedure);
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedFunction.java b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryFunction.java
similarity index 64%
rename from core/src/main/java/org/apache/commons/functor/core/composite/TransformedFunction.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryFunction.java
index 0e921e2..d4766e6 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedFunction.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryFunction.java
@@ -18,17 +18,17 @@
import java.io.Serializable;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.Function;
-import org.apache.commons.functor.UnaryFunction;
import org.apache.commons.lang3.Validate;
/**
- * A Function whose result is then run through a UnaryFunction.
+ * A NullaryFunction whose result is then run through a Function.
*
* @param <T> the returned value type.
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TransformedFunction<T> implements Function<T>, Serializable {
+public class TransformedNullaryFunction<T> implements NullaryFunction<T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -39,7 +39,7 @@
*
* @param <X> the adapted function argument type
*/
- private static final class Helper<X, T> implements Function<T>, Serializable {
+ private static final class Helper<X, T> implements NullaryFunction<T>, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -47,20 +47,20 @@
/**
* The preceding function.
*/
- private Function<? extends X> preceding;
+ private NullaryFunction<? extends X> preceding;
/**
* The following function.
*/
- private UnaryFunction<? super X, ? extends T> following;
+ private Function<? super X, ? extends T> following;
/**
* Create a new Helper.
- * @param preceding Function
- * @param following UnaryFunction
+ * @param preceding NullaryFunction
+ * @param following Function
*/
- private Helper(Function<? extends X> preceding, UnaryFunction<? super X, ? extends T> following) {
- this.preceding = Validate.notNull(preceding, "Function argument was null");
- this.following = Validate.notNull(following, "UnaryFunction argument was null");
+ private Helper(NullaryFunction<? extends X> preceding, Function<? super X, ? extends T> following) {
+ this.preceding = Validate.notNull(preceding, "NullaryFunction argument was null");
+ this.following = Validate.notNull(following, "Function argument was null");
}
/**
@@ -77,13 +77,13 @@
private final Helper<?, T> helper;
/**
- * Create a new TransformedFunction.
+ * Create a new TransformedNullaryFunction.
* @param <X> the preceding function argument type.
- * @param preceding Function
- * @param following UnaryFunction
+ * @param preceding NullaryFunction
+ * @param following Function
*/
- public <X> TransformedFunction(Function<? extends X> preceding,
- UnaryFunction<? super X, ? extends T> following) {
+ public <X> TransformedNullaryFunction(NullaryFunction<? extends X> preceding,
+ Function<? super X, ? extends T> following) {
this.helper = new Helper<X, T>(preceding, following);
}
@@ -99,15 +99,16 @@
*/
@Override
public final boolean equals(Object obj) {
- return obj == this || obj instanceof TransformedFunction<?> && equals((TransformedFunction<?>) obj);
+ return obj == this || obj instanceof TransformedNullaryFunction<?>
+ && equals((TransformedNullaryFunction<?>) obj);
}
/**
- * Learn whether another TransformedFunction is equal to <code>this</code>.
+ * Learn whether another TransformedNullaryFunction is equal to <code>this</code>.
* @param that instance to test
* @return whether equal
*/
- public final boolean equals(TransformedFunction<?> that) {
+ public final boolean equals(TransformedNullaryFunction<?> that) {
return that != null && that.helper.preceding.equals(this.helper.preceding)
&& that.helper.following.equals(this.helper.following);
}
@@ -117,7 +118,7 @@
*/
@Override
public int hashCode() {
- int result = "TransformedFunction".hashCode();
+ int result = "TransformedNullaryFunction".hashCode();
result <<= 2;
result |= helper.following.hashCode();
result <<= 2;
@@ -130,6 +131,6 @@
*/
@Override
public String toString() {
- return "TransformedFunction<" + helper.preceding + "; " + helper.following + ">";
+ return "TransformedNullaryFunction<" + helper.preceding + "; " + helper.following + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryProcedure.java
similarity index 63%
rename from core/src/main/java/org/apache/commons/functor/core/composite/TransformedProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryProcedure.java
index 2915ddd..4d5a760 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/TransformedProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/TransformedNullaryProcedure.java
@@ -18,16 +18,16 @@
import java.io.Serializable;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.lang3.Validate;
/**
- * A Procedure composed of a Function whose result is then run through a UnaryProcedure.
- * @version $Revision$ $Date$
+ * A NullaryProcedure composed of a NullaryFunction whose result is then run through a Procedure.
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TransformedProcedure implements Procedure, Serializable {
+public class TransformedNullaryProcedure implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -40,7 +40,7 @@
* Type-remembering helper.
* @param <X> the adapted function argument type.
*/
- private static final class Helper<X> implements Procedure, Serializable {
+ private static final class Helper<X> implements NullaryProcedure, Serializable {
/**
* serialVersionUID declaration.
*/
@@ -48,20 +48,20 @@
/**
* The adapted function.
*/
- private Function<? extends X> function;
+ private NullaryFunction<? extends X> function;
/**
* The adapted procedure.
*/
- private UnaryProcedure<? super X> procedure;
+ private Procedure<? super X> procedure;
/**
* Create a new Helper.
- * @param function Function
- * @param procedure UnaryFunction
+ * @param function NullaryFunction
+ * @param procedure Procedure
*/
- private Helper(Function<? extends X> function, UnaryProcedure<? super X> procedure) {
- this.function = Validate.notNull(function, "Function argument must not be null");
- this.procedure = Validate.notNull(procedure, "UnaryProcedure argument must not be null");
+ private Helper(NullaryFunction<? extends X> function, Procedure<? super X> procedure) {
+ this.function = Validate.notNull(function, "NullaryFunction argument must not be null");
+ this.procedure = Validate.notNull(procedure, "Procedure argument must not be null");
}
/**
@@ -78,12 +78,12 @@
private final Helper<?> helper;
/**
- * Create a new TransformedProcedure.
+ * Create a new TransformedNullaryProcedure.
* @param <X> the adapted function argument type.
- * @param function Function
- * @param procedure UnaryProcedure
+ * @param function NullaryFunction
+ * @param procedure Procedure
*/
- public <X> TransformedProcedure(Function<? extends X> function, UnaryProcedure<? super X> procedure) {
+ public <X> TransformedNullaryProcedure(NullaryFunction<? extends X> function, Procedure<? super X> procedure) {
this.helper = new Helper<X>(function, procedure);
}
@@ -99,16 +99,16 @@
*/
@Override
public final boolean equals(Object obj) {
- return obj == this || obj instanceof TransformedProcedure
- && equals((TransformedProcedure) obj);
+ return obj == this || obj instanceof TransformedNullaryProcedure
+ && equals((TransformedNullaryProcedure) obj);
}
/**
- * Learn whether another TransformedProcedure is equal to <code>this</code>.
+ * Learn whether another TransformedNullaryProcedure is equal to <code>this</code>.
* @param that instance to test
* @return whether equal
*/
- public final boolean equals(TransformedProcedure that) {
+ public final boolean equals(TransformedNullaryProcedure that) {
return that != null && that.helper.function.equals(this.helper.function)
&& that.helper.procedure.equals(this.helper.procedure);
}
@@ -118,7 +118,7 @@
*/
@Override
public int hashCode() {
- int result = "TransformedProcedure".hashCode();
+ int result = "TransformedNullaryProcedure".hashCode();
result <<= HASH_SHIFT;
result |= helper.procedure.hashCode();
result <<= HASH_SHIFT;
@@ -131,6 +131,6 @@
*/
@Override
public String toString() {
- return "TransformedProcedure<" + helper.function + "; " + helper.procedure + ">";
+ return "TransformedNullaryProcedure<" + helper.function + "; " + helper.procedure + ">";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/core/composite/WhileDoProcedure.java b/core/src/main/java/org/apache/commons/functor/core/composite/WhileDoNullaryProcedure.java
similarity index 71%
rename from core/src/main/java/org/apache/commons/functor/core/composite/WhileDoProcedure.java
rename to core/src/main/java/org/apache/commons/functor/core/composite/WhileDoNullaryProcedure.java
index d0a62f1..0499194 100644
--- a/core/src/main/java/org/apache/commons/functor/core/composite/WhileDoProcedure.java
+++ b/core/src/main/java/org/apache/commons/functor/core/composite/WhileDoNullaryProcedure.java
@@ -16,13 +16,13 @@
*/
package org.apache.commons.functor.core.composite;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
/**
- * A {@link Procedure} implementation of a while loop. Given a {@link Predicate}
- * <i>c</i> and an {@link Procedure} <i>p</i>, {@link #run runs}
+ * A {@link NullaryProcedure} implementation of a while loop. Given a {@link NullaryPredicate}
+ * <i>c</i> and an {@link NullaryProcedure} <i>p</i>, {@link #run runs}
* <code>while(c.test()) { p.run(); }</code>.
* <p>
* Note that although this class implements
@@ -32,20 +32,20 @@
* an instance whose delegates are not all
* <code>Serializable</code> will result in an exception.
* </p>
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class WhileDoProcedure extends AbstractLoopProcedure {
+public class WhileDoNullaryProcedure extends AbstractLoopNullaryProcedure {
/**
* serialVersionUID declaration.
*/
private static final long serialVersionUID = 8157389586531784657L;
/**
- * Create a new WhileDoProcedure.
+ * Create a new WhileDoNullaryProcedure.
* @param condition while
* @param action to do
*/
- public WhileDoProcedure(Predicate condition, Procedure action) {
+ public WhileDoNullaryProcedure(NullaryPredicate condition, NullaryProcedure action) {
super(condition, action);
}
@@ -63,6 +63,6 @@
*/
@Override
public String toString() {
- return "WhileDoProcedure<while(" + getCondition() + ") do(" + getAction() + ")>";
+ return "WhileDoNullaryProcedure<while(" + getCondition() + ") do(" + getAction() + ")>";
}
}
diff --git a/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java b/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
index ed4a1ce..f9802fe 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
@@ -16,7 +16,7 @@
import java.util.Collection;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.generator.util.CollectionTransformer;
/**
@@ -80,10 +80,10 @@
/**
* {@inheritDoc}
* Transforms this generator using the passed in
- * UnaryFunction. An example function might turn the contents of the
+ * Function. An example function might turn the contents of the
* generator into a {@link Collection} of elements.
*/
- public final <T> T to(UnaryFunction<Generator<? extends E>, ? extends T> transformer) {
+ public final <T> T to(Function<Generator<? extends E>, ? extends T> transformer) {
return transformer.evaluate(this);
}
diff --git a/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java b/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
index 244bba8..7fbf870 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
@@ -16,14 +16,14 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.core.composite.ConditionalUnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.core.composite.ConditionalProcedure;
import org.apache.commons.lang3.Validate;
/**
* Generator that filters another Generator by only passing through those elements
- * that are matched by a specified UnaryPredicate.
+ * that are matched by a specified Predicate.
*
* @param <E> the type of elements held in this generator.
* @version $Revision$ $Date$
@@ -33,23 +33,23 @@
/**
* The wrapped generator.
*/
- private final UnaryPredicate<? super E> pred;
+ private final Predicate<? super E> pred;
/**
* Create a new FilteredGenerator.
* @param wrapped Generator to wrap
- * @param pred filtering UnaryPredicate
+ * @param pred filtering Predicate
*/
- public FilteredGenerator(Generator<? extends E> wrapped, UnaryPredicate<? super E> pred) {
+ public FilteredGenerator(Generator<? extends E> wrapped, Predicate<? super E> pred) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.pred = Validate.notNull(pred, "UnaryPredicate argument was null");
+ this.pred = Validate.notNull(pred, "Predicate argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new ConditionalUnaryProcedure<E>(pred, proc));
+ public void run(Procedure<? super E> proc) {
+ getWrappedGenerator().run(new ConditionalProcedure<E>(pred, proc));
}
/**
diff --git a/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java b/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
index eefccf4..92a8519 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} terminates once
+ * Wrap another {@link Generator} such that {@link #run(Procedure)} terminates once
* a condition has been satisfied (test after).
*
* @param <E> the type of elements held in this generator.
@@ -32,23 +32,23 @@
/**
* The condition has to verified in order to execute the generation.
*/
- private final UnaryPredicate<? super E> test;
+ private final Predicate<? super E> test;
/**
* Create a new GenerateUntil.
* @param wrapped {@link Generator}
- * @param test {@link UnaryPredicate}
+ * @param test {@link Predicate}
*/
- public GenerateUntil(Generator<? extends E> wrapped, UnaryPredicate<? super E> test) {
+ public GenerateUntil(Generator<? extends E> wrapped, Predicate<? super E> test) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.test = Validate.notNull(test, "UnaryPredicate argument was null");
+ this.test = Validate.notNull(test, "Predicate argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<E>() {
+ public void run(final Procedure<? super E> proc) {
+ getWrappedGenerator().run(new Procedure<E>() {
public void run(E obj) {
proc.run(obj);
if (test.test(obj)) {
diff --git a/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java b/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
index 44a3ed4..337846e 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} continues
+ * Wrap another {@link Generator} such that {@link #run(Procedure)} continues
* as long as a condition is true (test after).
*
* @param <E> the type of elements held in this generator.
@@ -32,23 +32,23 @@
/**
* The condition has to verified in order to execute the generation.
*/
- private final UnaryPredicate<? super E> test;
+ private final Predicate<? super E> test;
/**
* Create a new GenerateWhile.
* @param wrapped {@link Generator}
- * @param test {@link UnaryPredicate}
+ * @param test {@link Predicate}
*/
- public GenerateWhile(Generator<? extends E> wrapped, UnaryPredicate<? super E> test) {
+ public GenerateWhile(Generator<? extends E> wrapped, Predicate<? super E> test) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.test = Validate.notNull(test, "UnaryPredicate argument was null");
+ this.test = Validate.notNull(test, "Predicate argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<E>() {
+ public void run(final Procedure<? super E> proc) {
+ getWrappedGenerator().run(new Procedure<E>() {
public void run(E obj) {
proc.run(obj);
if (!test.test(obj)) {
diff --git a/core/src/main/java/org/apache/commons/functor/generator/Generator.java b/core/src/main/java/org/apache/commons/functor/generator/Generator.java
index 21e362d..ab21031 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/Generator.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/Generator.java
@@ -15,11 +15,11 @@
import java.util.Collection;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
/**
- * The Generator interface defines a number of useful actions applying UnaryFunctors
+ * The Generator interface defines a number of useful actions applying Procedures
* to each in a series of argument Objects.
*
* @param <E> the type of elements held in this generator.
@@ -28,9 +28,9 @@
public interface Generator<E> {
/**
* Generators must implement this method.
- * @param proc UnaryProcedure to run
+ * @param proc Procedure to run
*/
- void run(UnaryProcedure<? super E> proc);
+ void run(Procedure<? super E> proc);
/**
* Stop the generator. Will stop the wrapped generator if one was set.
@@ -47,11 +47,11 @@
* Transforms this generator using the passed in
* transformer. An example transformer might turn the contents of the
* generator into a {@link Collection} of elements.
- * @param <Z> the returned value type of the input {@link UnaryFunction}.
- * @param transformer UnaryFunction to apply to this
+ * @param <Z> the returned value type of the input {@link Function}.
+ * @param transformer Function to apply to this
* @return transformation result
*/
- <Z> Z to(UnaryFunction<Generator<? extends E>, ? extends Z> transformer);
+ <Z> Z to(Function<Generator<? extends E>, ? extends Z> transformer);
/**
* Same as to(new CollectionTransformer(collection)).
diff --git a/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java b/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
index 26841f9..e5debb1 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
@@ -14,7 +14,7 @@
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
import java.util.Iterator;
@@ -50,7 +50,7 @@
/**
* {@inheritDoc}
*/
- public void run(UnaryProcedure<? super E> proc) {
+ public void run(Procedure<? super E> proc) {
while (iter.hasNext()) {
proc.run(iter.next());
if (isStopped()) {
diff --git a/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java b/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
index c47b747..e015b36 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
@@ -16,8 +16,8 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
@@ -30,25 +30,25 @@
public class TransformedGenerator<I, E> extends BaseGenerator<E> {
/**
- * The UnaryFunction to apply to each element.
+ * The Function to apply to each element.
*/
- private final UnaryFunction<? super I, ? extends E> func;
+ private final Function<? super I, ? extends E> func;
/**
* Create a new TransformedGenerator.
* @param wrapped Generator to transform
- * @param func UnaryFunction to apply to each element
+ * @param func Function to apply to each element
*/
- public TransformedGenerator(Generator<? extends I> wrapped, UnaryFunction<? super I, ? extends E> func) {
+ public TransformedGenerator(Generator<? extends I> wrapped, Function<? super I, ? extends E> func) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.func = Validate.notNull(func, "UnaryFunction argument was null");
+ this.func = Validate.notNull(func, "Function argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<I>() {
+ public void run(final Procedure<? super E> proc) {
+ getWrappedGenerator().run(new Procedure<I>() {
public void run(I obj) {
proc.run(func.evaluate(obj));
}
diff --git a/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java b/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
index 38c837c..600940b 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} terminates once
+ * Wrap another {@link Generator} such that {@link #run(Procedure)} terminates once
* a condition has been satisfied.
*
* @param <E> the type of elements held in this generator.
@@ -32,23 +32,23 @@
/**
* The condition has to verified in order to execute the generation.
*/
- private final UnaryPredicate<? super E> test;
+ private final Predicate<? super E> test;
/**
* Create a new UntilGenerate.
* @param wrapped {@link Generator}
- * @param test {@link UnaryPredicate}
+ * @param test {@link Predicate}
*/
- public UntilGenerate(UnaryPredicate<? super E> test, Generator<? extends E> wrapped) {
+ public UntilGenerate(Predicate<? super E> test, Generator<? extends E> wrapped) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.test = Validate.notNull(test, "UnaryPredicate argument was null");
+ this.test = Validate.notNull(test, "Predicate argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<E>() {
+ public void run(final Procedure<? super E> proc) {
+ getWrappedGenerator().run(new Procedure<E>() {
public void run(E obj) {
if (test.test(obj)) {
getWrappedGenerator().stop();
diff --git a/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java b/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
index 09d014f..d3881fc 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.functor.generator;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.lang3.Validate;
/**
- * Wrap another {@link Generator} such that {@link #run(UnaryProcedure)} continues
+ * Wrap another {@link Generator} such that {@link #run(Procedure)} continues
* as long as a condition is true (test before).
*
* @param <E> the type of elements held in this generator.
@@ -32,23 +32,23 @@
/**
* The condition has to verified in order to execute the generation.
*/
- private final UnaryPredicate<? super E> test;
+ private final Predicate<? super E> test;
/**
* Create a new WhileGenerate.
- * @param test {@link UnaryPredicate}
+ * @param test {@link Predicate}
* @param wrapped {@link Generator}
*/
- public WhileGenerate(UnaryPredicate<? super E> test, Generator<? extends E> wrapped) {
+ public WhileGenerate(Predicate<? super E> test, Generator<? extends E> wrapped) {
super(Validate.notNull(wrapped, "Generator argument was null"));
- this.test = Validate.notNull(test, "UnaryPredicate argument was null");
+ this.test = Validate.notNull(test, "Predicate argument was null");
}
/**
* {@inheritDoc}
*/
- public void run(final UnaryProcedure<? super E> proc) {
- getWrappedGenerator().run(new UnaryProcedure<E>() {
+ public void run(final Procedure<? super E> proc) {
+ getWrappedGenerator().run(new Procedure<E>() {
public void run(E obj) {
if (!test.test(obj)) {
getWrappedGenerator().stop();
diff --git a/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java b/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
index 4b69afb..4ac7416 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
@@ -17,8 +17,8 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.Generator;
import org.apache.commons.lang3.Validate;
@@ -30,7 +30,7 @@
* @since 1.0
* @version $Revision$ $Date$
*/
-public class CollectionTransformer<E, C extends Collection<? super E>> implements UnaryFunction<Generator<? extends E>, C> {
+public class CollectionTransformer<E, C extends Collection<? super E>> implements Function<Generator<? extends E>, C> {
/*
* TODO revisit this class... it could stand a more-descriptive name. Also, it's a little
* hard to say whether, for an instance constructed without a specific target collection,
@@ -62,7 +62,7 @@
* {@inheritDoc}
*/
public C evaluate(Generator<? extends E> generator) {
- generator.run(new UnaryProcedure<E>() {
+ generator.run(new Procedure<E>() {
public void run(E obj) {
toFill.add(obj);
}
diff --git a/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java b/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java
index c2c1c7c..4acb1b5 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java
@@ -14,7 +14,7 @@
package org.apache.commons.functor.generator.util;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.BaseGenerator;
@@ -93,7 +93,7 @@
/**
* {@inheritDoc}
*/
- public void run(UnaryProcedure<? super Integer> proc) {
+ public void run(Procedure<? super Integer> proc) {
if (signOf(step) == -1) {
for (int i = from; i > to; i += step) {
proc.run(Integer.valueOf(i));
diff --git a/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java b/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java
index c82956f..0d9c30b 100644
--- a/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java
+++ b/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java
@@ -14,7 +14,7 @@
package org.apache.commons.functor.generator.util;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.BaseGenerator;
/**
@@ -92,7 +92,7 @@
/**
* {@inheritDoc}
*/
- public void run(UnaryProcedure<? super Long> proc) {
+ public void run(Procedure<? super Long> proc) {
if (signOf(step) == -1L) {
for (long i = from; i > to; i += step) {
proc.run(Long.valueOf(i));
diff --git a/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java b/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
index 8d8221e..ea235b6 100644
--- a/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
+++ b/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
@@ -29,7 +29,7 @@
import java.util.Set;
import org.apache.commons.functor.core.Identity;
-import org.apache.commons.functor.core.composite.UnaryNot;
+import org.apache.commons.functor.core.composite.Not;
import org.apache.commons.functor.generator.FilteredGenerator;
import org.apache.commons.functor.generator.Generator;
import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
@@ -102,7 +102,7 @@
@Test
public void testReject1() {
- Collection<Integer> result = new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new UnaryNot<Integer>(isOdd)).toCollection();
+ Collection<Integer> result = new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new Not<Integer>(isOdd)).toCollection();
assertNotNull(result);
assertEquals(evens,result);
}
@@ -110,7 +110,7 @@
@Test
public void testReject2() {
List<Object> result = new ArrayList<Object>();
- assertSame(result,new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new UnaryNot<Integer>(isOdd)).to(result));
+ assertSame(result,new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new Not<Integer>(isOdd)).to(result));
assertEquals(evens,result);
}
@@ -161,12 +161,12 @@
private List<Integer> evens = null;
private List<Integer> listWithDuplicates = null;
private int sum = 0;
- private UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj.intValue() % 2 == 0;
}
};
- private UnaryPredicate<Integer> isOdd = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isOdd = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj.intValue() % 2 != 0;
}
@@ -175,21 +175,21 @@
// Classes
// ------------------------------------------------------------------------
- static class Counter implements Procedure {
+ static class Counter implements NullaryProcedure {
public void run() {
count++;
}
public int count = 0;
}
- static class Summer implements UnaryProcedure<Integer> {
+ static class Summer implements Procedure<Integer> {
public void run(Integer that) {
sum += that.intValue();
}
public int sum = 0;
}
- static class Doubler implements UnaryFunction<Integer, Integer> {
+ static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
return new Integer(2* obj.intValue());
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionFunction.java
similarity index 65%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionFunction.java
index c0274e1..933e60a 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionFunction.java
@@ -19,23 +19,23 @@
import static org.junit.Assert.*;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.IsNotSame;
import org.apache.commons.functor.core.IsSame;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class TestBinaryFunctionUnaryFunction extends BaseFunctorTest {
+public class TestBinaryFunctionFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BinaryFunctionUnaryFunction<Object, Object>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
+ return new BinaryFunctionFunction<Object, Object>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
}
// Tests
@@ -43,32 +43,32 @@
@Test
public void testTestWhenTrue() throws Exception {
- UnaryFunction<Object, Boolean> f = new BinaryFunctionUnaryFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
+ Function<Object, Boolean> f = new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
assertEquals(Boolean.TRUE, f.evaluate(null));
}
@Test
public void testTestWhenFalse() throws Exception {
- UnaryFunction<Object, Boolean> f = new BinaryFunctionUnaryFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsNotSame.INSTANCE));
+ Function<Object, Boolean> f = new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsNotSame.INSTANCE));
assertEquals(Boolean.FALSE, f.evaluate(null));
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Boolean> f = new BinaryFunctionUnaryFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
+ Function<Object, Boolean> f = new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE));
assertEquals(f, f);
- assertObjectsAreEqual(f, new BinaryFunctionUnaryFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE)));
+ assertObjectsAreEqual(f, new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE)));
assertObjectsAreNotEqual(f, Constant.truePredicate());
- assertObjectsAreNotEqual(f, new BinaryFunctionUnaryFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsNotSame.INSTANCE)));
+ assertObjectsAreNotEqual(f, new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsNotSame.INSTANCE)));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BinaryFunctionUnaryFunction.adapt(null));
+ assertNull(BinaryFunctionFunction.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BinaryFunctionUnaryFunction.adapt(Constant.TRUE));
+ assertNotNull(BinaryFunctionFunction.adapt(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicatePredicate.java
similarity index 70%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicatePredicate.java
index bd1271d..229873a 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicateUnaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryPredicatePredicate.java
@@ -23,23 +23,23 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.IsNotSame;
import org.apache.commons.functor.core.IsSame;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class TestBinaryPredicateUnaryPredicate extends BaseFunctorTest {
+public class TestBinaryPredicatePredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BinaryPredicateUnaryPredicate<Object>(IsSame.INSTANCE);
+ return new BinaryPredicatePredicate<Object>(IsSame.INSTANCE);
}
// Tests
@@ -47,32 +47,32 @@
@Test
public void testTestWhenTrue() throws Exception {
- UnaryPredicate<Object> p = new BinaryPredicateUnaryPredicate<Object>(IsSame.INSTANCE);
+ Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE);
assertTrue(p.test(null));
}
@Test
public void testTestWhenFalse() throws Exception {
- UnaryPredicate<Object> p = new BinaryPredicateUnaryPredicate<Object>(IsNotSame.INSTANCE);
+ Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE);
assertFalse(p.test(null));
}
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Object> p = new BinaryPredicateUnaryPredicate<Object>(IsSame.INSTANCE);
+ Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE);
assertEquals(p, p);
- assertObjectsAreEqual(p, new BinaryPredicateUnaryPredicate<Object>(IsSame.INSTANCE));
+ assertObjectsAreEqual(p, new BinaryPredicatePredicate<Object>(IsSame.INSTANCE));
assertObjectsAreNotEqual(p, Constant.truePredicate());
- assertObjectsAreNotEqual(p, new BinaryPredicateUnaryPredicate<Object>(IsNotSame.INSTANCE));
+ assertObjectsAreNotEqual(p, new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BinaryPredicateUnaryPredicate.adapt(null));
+ assertNull(BinaryPredicatePredicate.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BinaryPredicateUnaryPredicate.adapt(Constant.TRUE));
+ assertNotNull(BinaryPredicatePredicate.adapt(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureProcedure.java
similarity index 70%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureProcedure.java
index 6a51f0d..2d8c614 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureUnaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryProcedureProcedure.java
@@ -22,21 +22,21 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestBinaryProcedureUnaryProcedure extends BaseFunctorTest {
+public class TestBinaryProcedureProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BinaryProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
+ return new BinaryProcedureProcedure<Object>(NoOp.INSTANCE);
}
// Tests
@@ -44,27 +44,27 @@
@Test
public void testRun() throws Exception {
- UnaryProcedure<Object> p = new BinaryProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
+ Procedure<Object> p = new BinaryProcedureProcedure<Object>(NoOp.INSTANCE);
p.run(null);
}
@Test
public void testEquals() throws Exception {
- UnaryProcedure<Object> p = new BinaryProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
+ Procedure<Object> p = new BinaryProcedureProcedure<Object>(NoOp.INSTANCE);
assertEquals(p, p);
- assertObjectsAreEqual(p, new BinaryProcedureUnaryProcedure<Object>(NoOp.INSTANCE));
+ assertObjectsAreEqual(p, new BinaryProcedureProcedure<Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(p, NoOp.INSTANCE);
- assertObjectsAreNotEqual(p, new BinaryProcedureUnaryProcedure<Object>(IgnoreLeftProcedure.adapt(NoOp.INSTANCE)));
+ assertObjectsAreNotEqual(p, new BinaryProcedureProcedure<Object>(IgnoreLeftProcedure.adapt(NoOp.INSTANCE)));
assertTrue(!p.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BinaryProcedureUnaryProcedure.adapt(null));
+ assertNull(BinaryProcedureProcedure.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BinaryProcedureUnaryProcedure.adapt(NoOp.INSTANCE));
+ assertNotNull(BinaryProcedureProcedure.adapt(NoOp.INSTANCE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryFunction.java
similarity index 64%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBoundFunction.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryFunction.java
index b29a0dc..6d68cf5 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryFunction.java
@@ -22,22 +22,22 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestBoundFunction extends BaseFunctorTest {
+public class TestBoundNullaryFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BoundFunction<Object>(Identity.INSTANCE,"xyzzy");
+ return new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy");
}
// Tests
@@ -45,30 +45,30 @@
@Test
public void testEvaluate() throws Exception {
- Function<Object> f = new BoundFunction<Object>(Identity.INSTANCE,"xyzzy");
+ NullaryFunction<Object> f = new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy");
assertEquals("xyzzy",f.evaluate());
}
@Test
public void testEquals() throws Exception {
- Function<Object> f = new BoundFunction<Object>(Identity.INSTANCE,"xyzzy");
+ NullaryFunction<Object> f = new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy");
assertEquals(f,f);
- assertObjectsAreEqual(f,new BoundFunction<Object>(Identity.INSTANCE,"xyzzy"));
+ assertObjectsAreEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy"));
assertObjectsAreNotEqual(f,Constant.of("xyzzy"));
- assertObjectsAreNotEqual(f,new BoundFunction<Object>(Identity.INSTANCE,"foo"));
- assertObjectsAreNotEqual(f,new BoundFunction<Object>(Constant.of("xyzzy"),"foo"));
- assertObjectsAreNotEqual(f,new BoundFunction<Object>(Identity.INSTANCE,null));
+ assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,"foo"));
+ assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Constant.of("xyzzy"),"foo"));
+ assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,null));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BoundFunction.bind(null,"xyzzy"));
+ assertNull(BoundNullaryFunction.bind(null,"xyzzy"));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BoundFunction.bind(Identity.INSTANCE,"xyzzy"));
- assertNotNull(BoundFunction.bind(Identity.INSTANCE,null));
+ assertNotNull(BoundNullaryFunction.bind(Identity.INSTANCE,"xyzzy"));
+ assertNotNull(BoundNullaryFunction.bind(Identity.INSTANCE,null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryPredicate.java
similarity index 61%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBoundPredicate.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryPredicate.java
index bac5a39..fdf3854 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryPredicate.java
@@ -23,22 +23,22 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestBoundPredicate extends BaseFunctorTest {
+public class TestBoundNullaryPredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BoundPredicate(Constant.TRUE,"xyzzy");
+ return new BoundNullaryPredicate(Constant.TRUE,"xyzzy");
}
// Tests
@@ -47,36 +47,36 @@
@Test
public void testTest() throws Exception {
{
- Predicate p = new BoundPredicate(new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.TRUE);
+ NullaryPredicate p = new BoundNullaryPredicate(new FunctionPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.TRUE);
assertTrue(p.test());
}
{
- Predicate p = new BoundPredicate(new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.FALSE);
+ NullaryPredicate p = new BoundNullaryPredicate(new FunctionPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.FALSE);
assertFalse(p.test());
}
}
@Test
public void testEquals() throws Exception {
- Predicate f = new BoundPredicate(Constant.TRUE,"xyzzy");
+ NullaryPredicate f = new BoundNullaryPredicate(Constant.TRUE,"xyzzy");
assertEquals(f,f);
- assertObjectsAreEqual(f,new BoundPredicate(Constant.TRUE,"xyzzy"));
+ assertObjectsAreEqual(f,new BoundNullaryPredicate(Constant.TRUE,"xyzzy"));
assertObjectsAreNotEqual(f,Constant.TRUE);
- assertObjectsAreNotEqual(f,new BoundPredicate(Constant.TRUE,"foo"));
- assertObjectsAreNotEqual(f,new BoundPredicate(Constant.FALSE,"xyzzy"));
- assertObjectsAreNotEqual(f,new BoundPredicate(Constant.TRUE,null));
- assertObjectsAreEqual(new BoundPredicate(Constant.TRUE,null),new BoundPredicate(Constant.TRUE,null));
+ assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.TRUE,"foo"));
+ assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.FALSE,"xyzzy"));
+ assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.TRUE,null));
+ assertObjectsAreEqual(new BoundNullaryPredicate(Constant.TRUE,null),new BoundNullaryPredicate(Constant.TRUE,null));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BoundPredicate.bind(null,"xyzzy"));
+ assertNull(BoundNullaryPredicate.bind(null,"xyzzy"));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BoundPredicate.bind(Constant.TRUE,"xyzzy"));
- assertNotNull(BoundPredicate.bind(Constant.TRUE,null));
+ assertNotNull(BoundNullaryPredicate.bind(Constant.TRUE,"xyzzy"));
+ assertNotNull(BoundNullaryPredicate.bind(Constant.TRUE,null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryProcedure.java
similarity index 61%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestBoundProcedure.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryProcedure.java
index 915b62c..f01c8ec 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBoundProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBoundNullaryProcedure.java
@@ -22,22 +22,22 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestBoundProcedure extends BaseFunctorTest {
+public class TestBoundNullaryProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new BoundProcedure(NoOp.INSTANCE,"xyzzy");
+ return new BoundNullaryProcedure(NoOp.INSTANCE,"xyzzy");
}
// Tests
@@ -45,31 +45,31 @@
@Test
public void testRun() throws Exception {
- Procedure p = new BoundProcedure(new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE),Boolean.TRUE);
+ NullaryProcedure p = new BoundNullaryProcedure(new FunctionProcedure<Object>(Identity.INSTANCE),Boolean.TRUE);
p.run();
}
@Test
public void testEquals() throws Exception {
- Procedure f = new BoundProcedure(NoOp.INSTANCE,"xyzzy");
+ NullaryProcedure f = new BoundNullaryProcedure(NoOp.INSTANCE,"xyzzy");
assertEquals(f,f);
- assertObjectsAreEqual(f,new BoundProcedure(NoOp.INSTANCE,"xyzzy"));
+ assertObjectsAreEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,"xyzzy"));
assertObjectsAreNotEqual(f,NoOp.INSTANCE);
- assertObjectsAreNotEqual(f,new BoundProcedure(NoOp.INSTANCE,"foo"));
- assertObjectsAreNotEqual(f,new BoundProcedure(new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE),"xyzzy"));
- assertObjectsAreNotEqual(f,new BoundProcedure(NoOp.INSTANCE,null));
- assertObjectsAreEqual(new BoundProcedure(NoOp.INSTANCE,null),new BoundProcedure(NoOp.INSTANCE,null));
+ assertObjectsAreNotEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,"foo"));
+ assertObjectsAreNotEqual(f,new BoundNullaryProcedure(new FunctionProcedure<Object>(Identity.INSTANCE),"xyzzy"));
+ assertObjectsAreNotEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,null));
+ assertObjectsAreEqual(new BoundNullaryProcedure(NoOp.INSTANCE,null),new BoundNullaryProcedure(NoOp.INSTANCE,null));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(BoundProcedure.bind(null,"xyzzy"));
+ assertNull(BoundNullaryProcedure.bind(null,"xyzzy"));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(BoundProcedure.bind(new NoOp(),"xyzzy"));
- assertNotNull(BoundProcedure.bind(new NoOp(),null));
+ assertNotNull(BoundNullaryProcedure.bind(new NoOp(),"xyzzy"));
+ assertNotNull(BoundNullaryProcedure.bind(new NoOp(),null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
deleted file mode 100644
index 43a5dc5..0000000
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundFunction.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Function;
-import org.apache.commons.functor.core.Constant;
-import org.apache.commons.functor.core.LeftIdentity;
-import org.apache.commons.functor.core.RightIdentity;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-public class TestFullyBoundFunction extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy");
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testEvaluate() throws Exception {
- Function<Object> f = new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "foo");
- assertEquals("foo", f.evaluate());
- }
-
- @Test
- public void testEquals() throws Exception {
- Function<Object> f = new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy");
- assertEquals(f, f);
- assertObjectsAreEqual(f, new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy"));
- assertObjectsAreEqual(new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"),
- new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"));
- assertObjectsAreEqual(new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", null),
- new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", null));
- assertObjectsAreNotEqual(f, Constant.of("xyzzy"));
- assertObjectsAreNotEqual(f, new FullyBoundFunction<Object>(LeftIdentity.FUNCTION, null, "xyzzy"));
- assertObjectsAreNotEqual(f, new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"));
- assertObjectsAreNotEqual(f, new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "bar"));
- assertObjectsAreNotEqual(f, new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, null));
- assertObjectsAreNotEqual(new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundFunction<Object>(RightIdentity.FUNCTION, null, "bar"));
- assertObjectsAreNotEqual(new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundFunction<Object>(RightIdentity.FUNCTION, "bar", "bar"));
- assertTrue(!f.equals(null));
- }
-
- @Test
- public void testAdaptNull() throws Exception {
- assertNull(FullyBoundFunction.bind(null, null, "xyzzy"));
- }
-
- @Test
- public void testAdapt() throws Exception {
- assertNotNull(FullyBoundFunction.bind(RightIdentity.FUNCTION, "xyzzy", "foobar"));
- assertNotNull(FullyBoundFunction.bind(RightIdentity.FUNCTION, null, null));
- }
-}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryFunction.java
new file mode 100644
index 0000000..c8f90eb
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryFunction.java
@@ -0,0 +1,82 @@
+/*
+ * 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.functor.adapter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.LeftIdentity;
+import org.apache.commons.functor.core.RightIdentity;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestFullyBoundNullaryFunction extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy");
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testEvaluate() throws Exception {
+ NullaryFunction<Object> f = new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "foo");
+ assertEquals("foo", f.evaluate());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ NullaryFunction<Object> f = new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy");
+ assertEquals(f, f);
+ assertObjectsAreEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy"));
+ assertObjectsAreEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"),
+ new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"));
+ assertObjectsAreEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", null),
+ new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", null));
+ assertObjectsAreNotEqual(f, Constant.of("xyzzy"));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(LeftIdentity.FUNCTION, null, "xyzzy"));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "bar"));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, null));
+ assertObjectsAreNotEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "bar"));
+ assertObjectsAreNotEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "bar"));
+ assertTrue(!f.equals(null));
+ }
+
+ @Test
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundNullaryFunction.bind(null, null, "xyzzy"));
+ }
+
+ @Test
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundNullaryFunction.bind(RightIdentity.FUNCTION, "xyzzy", "foobar"));
+ assertNotNull(FullyBoundNullaryFunction.bind(RightIdentity.FUNCTION, null, null));
+ }
+}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryPredicate.java
new file mode 100644
index 0000000..3784f9f
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryPredicate.java
@@ -0,0 +1,78 @@
+/*
+ * 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.functor.adapter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.RightIdentity;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestFullyBoundNullaryPredicate extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new FullyBoundNullaryPredicate(Constant.TRUE, null, "xyzzy");
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testTest() throws Exception {
+ NullaryPredicate p = new FullyBoundNullaryPredicate(
+ new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo",
+ Boolean.TRUE);
+ assertTrue(p.test());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ NullaryPredicate p = new FullyBoundNullaryPredicate(Constant.TRUE, "xyzzy", null);
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new FullyBoundNullaryPredicate(Constant.TRUE, "xyzzy", null));
+ assertObjectsAreNotEqual(p, Constant.TRUE);
+ assertObjectsAreNotEqual(p, new FullyBoundNullaryPredicate(Constant.FALSE, "xyzzy", null));
+ assertObjectsAreNotEqual(p, new FullyBoundNullaryPredicate(Constant.TRUE, "foo", null));
+ assertObjectsAreNotEqual(p, new FullyBoundNullaryPredicate(Constant.TRUE, null, "xyzzy"));
+ assertObjectsAreNotEqual(new FullyBoundNullaryPredicate(Constant.TRUE, null, "xyzzy"), new FullyBoundNullaryPredicate(Constant.TRUE, null, null));
+ assertObjectsAreEqual(new FullyBoundNullaryPredicate(Constant.TRUE, "foo", "xyzzy"), new FullyBoundNullaryPredicate(Constant.TRUE, "foo", "xyzzy"));
+ assertTrue(!p.equals(null));
+ }
+
+ @Test
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundNullaryPredicate.bind(null, "xyzzy", null));
+ }
+
+ @Test
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundNullaryPredicate.bind(Constant.FALSE, "xyzzy", "foobar"));
+ assertNotNull(FullyBoundNullaryPredicate.bind(Constant.FALSE, null, null));
+ }
+}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryProcedure.java
new file mode 100644
index 0000000..7b80a54
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundNullaryProcedure.java
@@ -0,0 +1,81 @@
+/*
+ * 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.functor.adapter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.functor.core.NoOp;
+import org.apache.commons.functor.core.RightIdentity;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestFullyBoundNullaryProcedure extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null);
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testRun() throws Exception {
+ NullaryProcedure p = new FullyBoundNullaryProcedure(new BinaryFunctionBinaryProcedure<Object, Object>(
+ RightIdentity.FUNCTION), "foo", null);
+ p.run();
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ NullaryProcedure f = new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null);
+ assertEquals(f, f);
+ assertObjectsAreEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null));
+ assertObjectsAreNotEqual(f, new NoOp());
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(
+ new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "xyzzy", null));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx"));
+ assertObjectsAreNotEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx"), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null));
+ assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null));
+ assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null), new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null));
+ assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null));
+ assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", "xyzzy"), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", "xyzzy"));
+ assertTrue(!f.equals(null));
+ }
+
+ @Test
+ public void testAdaptNull() throws Exception {
+ assertNull(FullyBoundNullaryProcedure.bind(null, "xyzzy", null));
+ }
+
+ @Test
+ public void testAdapt() throws Exception {
+ assertNotNull(FullyBoundNullaryProcedure.bind(new NoOp(), "xyzzy", "foobar"));
+ assertNotNull(FullyBoundNullaryProcedure.bind(new NoOp(), null, null));
+ }
+}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
deleted file mode 100644
index e352ffd..0000000
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundPredicate.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.core.Constant;
-import org.apache.commons.functor.core.RightIdentity;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-public class TestFullyBoundPredicate extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new FullyBoundPredicate(Constant.TRUE, null, "xyzzy");
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testTest() throws Exception {
- Predicate p = new FullyBoundPredicate(
- new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo",
- Boolean.TRUE);
- assertTrue(p.test());
- }
-
- @Test
- public void testEquals() throws Exception {
- Predicate p = new FullyBoundPredicate(Constant.TRUE, "xyzzy", null);
- assertEquals(p, p);
- assertObjectsAreEqual(p, new FullyBoundPredicate(Constant.TRUE, "xyzzy", null));
- assertObjectsAreNotEqual(p, Constant.TRUE);
- assertObjectsAreNotEqual(p, new FullyBoundPredicate(Constant.FALSE, "xyzzy", null));
- assertObjectsAreNotEqual(p, new FullyBoundPredicate(Constant.TRUE, "foo", null));
- assertObjectsAreNotEqual(p, new FullyBoundPredicate(Constant.TRUE, null, "xyzzy"));
- assertObjectsAreNotEqual(new FullyBoundPredicate(Constant.TRUE, null, "xyzzy"), new FullyBoundPredicate(Constant.TRUE, null, null));
- assertObjectsAreEqual(new FullyBoundPredicate(Constant.TRUE, "foo", "xyzzy"), new FullyBoundPredicate(Constant.TRUE, "foo", "xyzzy"));
- assertTrue(!p.equals(null));
- }
-
- @Test
- public void testAdaptNull() throws Exception {
- assertNull(FullyBoundPredicate.bind(null, "xyzzy", null));
- }
-
- @Test
- public void testAdapt() throws Exception {
- assertNotNull(FullyBoundPredicate.bind(Constant.FALSE, "xyzzy", "foobar"));
- assertNotNull(FullyBoundPredicate.bind(Constant.FALSE, null, null));
- }
-}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
deleted file mode 100644
index 1021e4d..0000000
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFullyBoundProcedure.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.functor.adapter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.core.NoOp;
-import org.apache.commons.functor.core.RightIdentity;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-public class TestFullyBoundProcedure extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", null);
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testRun() throws Exception {
- Procedure p = new FullyBoundProcedure(new BinaryFunctionBinaryProcedure<Object, Object>(
- RightIdentity.FUNCTION), "foo", null);
- p.run();
- }
-
- @Test
- public void testEquals() throws Exception {
- Procedure f = new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", null);
- assertEquals(f, f);
- assertObjectsAreEqual(f, new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", null));
- assertObjectsAreNotEqual(f, new NoOp());
- assertObjectsAreNotEqual(f, new FullyBoundProcedure(
- new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "xyzzy", null));
- assertObjectsAreNotEqual(f, new FullyBoundProcedure(NoOp.INSTANCE, "foo", null));
- assertObjectsAreNotEqual(f, new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx"));
- assertObjectsAreNotEqual(new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx"), new FullyBoundProcedure(NoOp.INSTANCE, "xyzzy", null));
- assertObjectsAreNotEqual(f, new FullyBoundProcedure(NoOp.INSTANCE, null, null));
- assertObjectsAreEqual(new FullyBoundProcedure(NoOp.INSTANCE, null, null), new FullyBoundProcedure(NoOp.INSTANCE, null, null));
- assertObjectsAreEqual(new FullyBoundProcedure(NoOp.INSTANCE, "foo", null), new FullyBoundProcedure(NoOp.INSTANCE, "foo", null));
- assertObjectsAreEqual(new FullyBoundProcedure(NoOp.INSTANCE, "foo", "xyzzy"), new FullyBoundProcedure(NoOp.INSTANCE, "foo", "xyzzy"));
- assertTrue(!f.equals(null));
- }
-
- @Test
- public void testAdaptNull() throws Exception {
- assertNull(FullyBoundProcedure.bind(null, "xyzzy", null));
- }
-
- @Test
- public void testAdapt() throws Exception {
- assertNotNull(FullyBoundProcedure.bind(new NoOp(), "xyzzy", "foobar"));
- assertNotNull(FullyBoundProcedure.bind(new NoOp(), null, null));
- }
-}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionPredicate.java
index f613e96..e006302 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionPredicate.java
@@ -36,7 +36,7 @@
@Override
protected Object makeFunctor() {
- return new FunctionPredicate(Constant.TRUE);
+ return new FunctionPredicate<Object>(Constant.TRUE);
}
// Tests
@@ -44,23 +44,23 @@
@Test
public void testTestWhenTrue() throws Exception {
- Predicate p = new FunctionPredicate(Constant.TRUE);
- assertTrue(p.test());
+ Predicate<Object> p = new FunctionPredicate<Object>(Constant.TRUE);
+ assertTrue(p.test(null));
}
@Test
public void testTestWhenFalse() throws Exception {
- Predicate p = new FunctionPredicate(Constant.FALSE);
- assertTrue(!p.test());
+ Predicate<Object> p = new FunctionPredicate<Object>(Constant.FALSE);
+ assertTrue(!p.test(null));
}
@Test
public void testEquals() throws Exception {
- Predicate p = new FunctionPredicate(Constant.TRUE);
+ Predicate<Object> p = new FunctionPredicate<Object>(Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new FunctionPredicate(Constant.TRUE));
+ assertObjectsAreEqual(p,new FunctionPredicate<Object>(Constant.TRUE));
assertObjectsAreNotEqual(p,Constant.TRUE);
- assertObjectsAreNotEqual(p,new FunctionPredicate(Constant.FALSE));
+ assertObjectsAreNotEqual(p,new FunctionPredicate<Object>(Constant.FALSE));
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
index 4bca526..b6f2424 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
@@ -38,7 +38,7 @@
@Override
protected Object makeFunctor() {
- return new FunctionProcedure(Constant.of("K"));
+ return new FunctionProcedure<Object>(Constant.of("K"));
}
// Tests
@@ -46,26 +46,26 @@
@Test
public void testRun() throws Exception {
- class EvaluateCounter implements Function<Integer> {
+ class EvaluateCounter implements Function<Object, Integer> {
int count = 0;
- public Integer evaluate() { return Integer.valueOf(count++); }
+ public Integer evaluate(Object a) { return Integer.valueOf(count++); }
}
EvaluateCounter counter = new EvaluateCounter();
- Procedure p = new FunctionProcedure(counter);
+ Procedure<Object> p = new FunctionProcedure<Object>(counter);
assertEquals(0,counter.count);
- p.run();
+ p.run(null);
assertEquals(1,counter.count);
- p.run();
+ p.run("x");
assertEquals(2,counter.count);
}
@Test
public void testEquals() throws Exception {
- Procedure p = new FunctionProcedure(Constant.of("K"));
+ Procedure<Object> p = new FunctionProcedure<Object>(Constant.of("K"));
assertEquals(p,p);
- assertObjectsAreEqual(p,new FunctionProcedure(Constant.of("K")));
+ assertObjectsAreEqual(p,new FunctionProcedure<Object>(Constant.of("K")));
assertObjectsAreNotEqual(p,NoOp.INSTANCE);
- assertObjectsAreNotEqual(p,new FunctionProcedure(Constant.of("J")));
+ assertObjectsAreNotEqual(p,new FunctionProcedure<Object>(Constant.of("J")));
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
index 830b65a..554a61c 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftPredicate.java
@@ -46,7 +46,7 @@
@Test
public void testEvaluate() throws Exception {
BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance()));
assertTrue(p.test(null,Boolean.TRUE));
assertTrue(!p.test(null,Boolean.FALSE));
}
@@ -54,10 +54,10 @@
@Test
public void testEquals() throws Exception {
BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance()));
assertEquals(p,p);
assertObjectsAreEqual(p,new IgnoreLeftPredicate<Object, Boolean>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance())));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance())));
assertObjectsAreNotEqual(p,Constant.TRUE);
assertObjectsAreNotEqual(p,new IgnoreLeftPredicate<Object, Object>(Constant.FALSE));
assertObjectsAreNotEqual(p,Constant.FALSE);
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
index 32cc698..cf40364 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreLeftProcedure.java
@@ -25,7 +25,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.NoOp;
-import org.apache.commons.functor.core.composite.UnarySequence;
+import org.apache.commons.functor.core.composite.Sequence;
import org.junit.Test;
/**
@@ -47,7 +47,7 @@
@Test
public void testEvaluate() throws Exception {
BinaryProcedure<Object, Object> p = new IgnoreLeftProcedure<Object, Object>(
- new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE));
+ new FunctionProcedure<Object>(Identity.INSTANCE));
p.run(null,Boolean.TRUE);
}
@@ -57,7 +57,7 @@
assertEquals(p,p);
assertObjectsAreEqual(p,new IgnoreLeftProcedure<Object, Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(p,NoOp.INSTANCE);
- assertObjectsAreNotEqual(p,new IgnoreLeftProcedure<Object, Object>(new UnarySequence<Object>()));
+ assertObjectsAreNotEqual(p,new IgnoreLeftProcedure<Object, Object>(new Sequence<Object>()));
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java
index 225d8d7..b0ff1fe 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightPredicate.java
@@ -46,7 +46,7 @@
@Test
public void testEvaluate() throws Exception {
BinaryPredicate<Boolean, Object> p = new IgnoreRightPredicate<Boolean, Object>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance()));
assertTrue(p.test(Boolean.TRUE,null));
assertTrue(!p.test(Boolean.FALSE,null));
}
@@ -54,10 +54,10 @@
@Test
public void testEquals() throws Exception {
BinaryPredicate<Boolean, Object> p = new IgnoreRightPredicate<Boolean, Object>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance()));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance()));
assertEquals(p,p);
assertObjectsAreEqual(p,new IgnoreRightPredicate<Boolean, Object>(
- new UnaryFunctionUnaryPredicate<Boolean>(Identity.<Boolean> instance())));
+ new FunctionPredicate<Boolean>(Identity.<Boolean> instance())));
assertObjectsAreNotEqual(p,Constant.TRUE);
assertObjectsAreNotEqual(p,new IgnoreRightPredicate<Boolean, Object>(Constant.FALSE));
assertObjectsAreNotEqual(p,Constant.FALSE);
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
index 2638228..4103643 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestIgnoreRightProcedure.java
@@ -23,7 +23,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
@@ -47,7 +47,7 @@
@Test
public void testEvaluate() throws Exception {
BinaryProcedure<Object, Object> p = new IgnoreRightProcedure<Object, Object>(
- new UnaryFunctionUnaryProcedure<Object>(Identity.INSTANCE));
+ new FunctionProcedure<Object>(Identity.INSTANCE));
p.run(Boolean.TRUE,null);
}
@@ -57,7 +57,7 @@
assertEquals(p,p);
assertObjectsAreEqual(p,new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(p,NoOp.INSTANCE);
- assertObjectsAreNotEqual(p,new IgnoreRightProcedure<Object, Object>(new UnaryProcedure<Object>() {
+ assertObjectsAreNotEqual(p,new IgnoreRightProcedure<Object, Object>(new Procedure<Object>() {
public void run(Object obj) {
// Do nothing
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundFunction.java
index ef3f27d..dd9f56a 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundFunction.java
@@ -22,7 +22,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.LeftIdentity;
import org.apache.commons.functor.core.RightIdentity;
@@ -46,13 +46,13 @@
@Test
public void testEvaluate() throws Exception {
- UnaryFunction<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"foo");
+ Function<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"foo");
assertEquals("xyzzy",f.evaluate("xyzzy"));
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy");
+ Function<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy");
assertEquals(f,f);
assertObjectsAreEqual(f,new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy"));
assertObjectsAreNotEqual(f,Constant.of("xyzzy"));
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java
index 040651d..830ce46 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundPredicate.java
@@ -23,7 +23,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.RightIdentity;
import org.junit.Test;
@@ -46,7 +46,7 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Boolean> p = new LeftBoundPredicate<Boolean>(
+ Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(
new BinaryFunctionBinaryPredicate<Object, Boolean>(RightIdentity.<Object, Boolean> function()), "foo");
assertTrue(p.test(Boolean.TRUE));
assertFalse(p.test(Boolean.FALSE));
@@ -54,7 +54,7 @@
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Boolean> p = new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy");
+ Predicate<Boolean> p = new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy");
assertEquals(p,p);
assertObjectsAreEqual(p,new LeftBoundPredicate<Boolean>(Constant.TRUE,"xyzzy"));
assertObjectsAreNotEqual(p,Constant.TRUE);
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java
index 9c90b4b..cf74ca1 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestLeftBoundProcedure.java
@@ -22,7 +22,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.NoOp;
import org.apache.commons.functor.core.RightIdentity;
import org.junit.Test;
@@ -45,7 +45,7 @@
@Test
public void testRun() throws Exception {
- UnaryProcedure<Object> p = new LeftBoundProcedure<Object>(
+ Procedure<Object> p = new LeftBoundProcedure<Object>(
new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "foo");
p.run(Boolean.TRUE);
p.run(Boolean.FALSE);
@@ -53,7 +53,7 @@
@Test
public void testEquals() throws Exception {
- UnaryProcedure<Object> f = new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy");
+ Procedure<Object> f = new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy");
assertEquals(f, f);
assertObjectsAreEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy"));
assertObjectsAreNotEqual(f, new NoOp());
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionFunction.java
similarity index 70%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionFunction.java
index ddb7e8f..873d441 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionFunction.java
@@ -22,21 +22,21 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestFunctionUnaryFunction extends BaseFunctorTest {
+public class TestNullaryFunctionFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
+ return new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy"));
}
// Tests
@@ -44,29 +44,29 @@
@Test
public void testEvaluate() throws Exception {
- UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
+ Function<Object, Object> f = new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy"));
assertEquals("xyzzy",f.evaluate(null));
assertEquals("xyzzy",f.evaluate("abc"));
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
+ Function<Object, Object> f = new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy"));
assertEquals(f,f);
- assertObjectsAreEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy")));
+ assertObjectsAreEqual(f,new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy")));
assertObjectsAreNotEqual(f,Constant.of("x"));
- assertObjectsAreNotEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of(null)));
+ assertObjectsAreNotEqual(f,new NullaryFunctionFunction<Object, Object>(Constant.of(null)));
assertObjectsAreNotEqual(f,Constant.of(null));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(FunctionUnaryFunction.adapt(null));
+ assertNull(NullaryFunctionFunction.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(FunctionUnaryFunction.adapt(Constant.of("xyzzy")));
+ assertNotNull(NullaryFunctionFunction.adapt(Constant.of("xyzzy")));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryPredicate.java
similarity index 67%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryPredicate.java
index 8546584..66dbd9b 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryPredicate.java
@@ -22,21 +22,21 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryFunctionUnaryPredicate extends BaseFunctorTest {
+public class TestNullaryFunctionNullaryPredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
+ return new NullaryFunctionNullaryPredicate(Constant.TRUE);
}
// Tests
@@ -44,33 +44,33 @@
@Test
public void testTestWhenTrue() throws Exception {
- UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
- assertTrue(p.test(null));
+ NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.TRUE);
+ assertTrue(p.test());
}
@Test
public void testTestWhenFalse() throws Exception {
- UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.FALSE);
- assertTrue(!p.test(null));
+ NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.FALSE);
+ assertTrue(!p.test());
}
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Object> p = new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE);
+ NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new UnaryFunctionUnaryPredicate<Object>(Constant.TRUE));
+ assertObjectsAreEqual(p,new NullaryFunctionNullaryPredicate(Constant.TRUE));
assertObjectsAreNotEqual(p,Constant.TRUE);
- assertObjectsAreNotEqual(p,new UnaryFunctionUnaryPredicate<Object>(Constant.FALSE));
+ assertObjectsAreNotEqual(p,new NullaryFunctionNullaryPredicate(Constant.FALSE));
assertTrue(!p.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(UnaryFunctionUnaryPredicate.adapt(null));
+ assertNull(NullaryFunctionNullaryPredicate.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(UnaryFunctionUnaryPredicate.adapt(Constant.TRUE));
+ assertNotNull(NullaryFunctionNullaryPredicate.adapt(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryProcedure.java
similarity index 67%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryProcedure.java
index 3689ff6..6128fa3 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryFunctionUnaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryFunctionNullaryProcedure.java
@@ -22,23 +22,23 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryFunctionUnaryProcedure extends BaseFunctorTest {
+public class TestNullaryFunctionNullaryProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryFunctionUnaryProcedure<Object>(Constant.of("K"));
+ return new NullaryFunctionNullaryProcedure(Constant.of("K"));
}
// Tests
@@ -46,36 +46,36 @@
@Test
public void testRun() throws Exception {
- class EvaluateCounter implements UnaryFunction<Object, Integer> {
+ class EvaluateCounter implements NullaryFunction<Integer> {
int count = 0;
- public Integer evaluate(Object a) { return Integer.valueOf(count++); }
+ public Integer evaluate() { return Integer.valueOf(count++); }
}
EvaluateCounter counter = new EvaluateCounter();
- UnaryProcedure<Object> p = new UnaryFunctionUnaryProcedure<Object>(counter);
+ NullaryProcedure p = new NullaryFunctionNullaryProcedure(counter);
assertEquals(0,counter.count);
- p.run(null);
+ p.run();
assertEquals(1,counter.count);
- p.run("x");
+ p.run();
assertEquals(2,counter.count);
}
@Test
public void testEquals() throws Exception {
- UnaryProcedure<Object> p = new UnaryFunctionUnaryProcedure<Object>(Constant.of("K"));
+ NullaryProcedure p = new NullaryFunctionNullaryProcedure(Constant.of("K"));
assertEquals(p,p);
- assertObjectsAreEqual(p,new UnaryFunctionUnaryProcedure<Object>(Constant.of("K")));
+ assertObjectsAreEqual(p,new NullaryFunctionNullaryProcedure(Constant.of("K")));
assertObjectsAreNotEqual(p,NoOp.INSTANCE);
- assertObjectsAreNotEqual(p,new UnaryFunctionUnaryProcedure<Object>(Constant.of("J")));
+ assertObjectsAreNotEqual(p,new NullaryFunctionNullaryProcedure(Constant.of("J")));
assertTrue(!p.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(UnaryFunctionUnaryProcedure.adapt(null));
+ assertNull(NullaryFunctionNullaryProcedure.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(UnaryFunctionUnaryProcedure.adapt(Constant.of("K")));
+ assertNotNull(NullaryFunctionNullaryProcedure.adapt(Constant.of("K")));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryPredicateUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicateNullaryFunction.java
similarity index 65%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestUnaryPredicateUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicateNullaryFunction.java
index 48b8eda..0091969 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryPredicateUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicateNullaryFunction.java
@@ -22,21 +22,21 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryPredicateUnaryFunction extends BaseFunctorTest {
+public class TestNullaryPredicateNullaryFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryPredicateUnaryFunction<Object>(Constant.TRUE);
+ return new NullaryPredicateNullaryFunction(Constant.of(Boolean.TRUE));
}
// Tests
@@ -44,33 +44,33 @@
@Test
public void testTestWhenTrue() throws Exception {
- UnaryFunction<Object, Boolean> f = new UnaryPredicateUnaryFunction<Object>(Constant.TRUE);
- assertEquals(Boolean.TRUE,f.evaluate(null));
+ NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.TRUE);
+ assertEquals(Boolean.TRUE,f.evaluate());
}
@Test
public void testTestWhenFalse() throws Exception {
- UnaryFunction<Object, Boolean> f = new UnaryPredicateUnaryFunction<Object>(Constant.FALSE);
- assertEquals(Boolean.FALSE,f.evaluate(null));
+ NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.FALSE);
+ assertEquals(Boolean.FALSE,f.evaluate());
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Boolean> f = new UnaryPredicateUnaryFunction<Object>(Constant.TRUE);
+ NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.TRUE);
assertEquals(f,f);
- assertObjectsAreEqual(f,new UnaryPredicateUnaryFunction<Object>(Constant.TRUE));
+ assertObjectsAreEqual(f,new NullaryPredicateNullaryFunction(Constant.TRUE));
assertObjectsAreNotEqual(f,Constant.of("x"));
- assertObjectsAreNotEqual(f,new UnaryPredicateUnaryFunction<Object>(Constant.FALSE));
+ assertObjectsAreNotEqual(f,new NullaryPredicateNullaryFunction(Constant.FALSE));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(UnaryPredicateUnaryFunction.adapt(null));
+ assertNull(NullaryPredicateNullaryFunction.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(UnaryPredicateUnaryFunction.adapt(Constant.TRUE));
+ assertNotNull(NullaryPredicateNullaryFunction.adapt(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicatePredicate.java
similarity index 71%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicatePredicate.java
index f8f1fd2..f7dc165 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateUnaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryPredicatePredicate.java
@@ -22,21 +22,21 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestPredicateUnaryPredicate extends BaseFunctorTest {
+public class TestNullaryPredicatePredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new PredicateUnaryPredicate<Object>(Constant.TRUE);
+ return new NullaryPredicatePredicate<Object>(Constant.TRUE);
}
// Tests
@@ -44,28 +44,28 @@
@Test
public void testEvaluate() throws Exception {
- UnaryPredicate<Object> p = new PredicateUnaryPredicate<Object>(Constant.TRUE);
+ Predicate<Object> p = new NullaryPredicatePredicate<Object>(Constant.TRUE);
assertTrue(p.test(null));
}
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Object> p = new PredicateUnaryPredicate<Object>(Constant.TRUE);
+ Predicate<Object> p = new NullaryPredicatePredicate<Object>(Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new PredicateUnaryPredicate<Object>(Constant.TRUE));
+ assertObjectsAreEqual(p,new NullaryPredicatePredicate<Object>(Constant.TRUE));
assertObjectsAreNotEqual(p,Constant.TRUE);
- assertObjectsAreNotEqual(p,new PredicateUnaryPredicate<Object>(Constant.FALSE));
+ assertObjectsAreNotEqual(p,new NullaryPredicatePredicate<Object>(Constant.FALSE));
assertObjectsAreNotEqual(p,Constant.FALSE);
assertTrue(!p.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(PredicateUnaryPredicate.adapt(null));
+ assertNull(NullaryPredicatePredicate.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(PredicateUnaryPredicate.adapt(Constant.TRUE));
+ assertNotNull(NullaryPredicatePredicate.adapt(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryProcedureUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryProcedureNullaryFunction.java
similarity index 67%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestUnaryProcedureUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestNullaryProcedureNullaryFunction.java
index bc75356..9d74460 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestUnaryProcedureUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestNullaryProcedureNullaryFunction.java
@@ -22,23 +22,23 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryProcedureUnaryFunction extends BaseFunctorTest {
+public class TestNullaryProcedureNullaryFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryProcedureUnaryFunction<Object, Object>(NoOp.INSTANCE);
+ return new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE);
}
// Tests
@@ -46,31 +46,28 @@
@Test
public void testEvaluate() throws Exception {
- UnaryFunction<Object, Object> f = new UnaryProcedureUnaryFunction<Object, Object>(NoOp.INSTANCE);
- assertNull(f.evaluate(null));
+ NullaryFunction<Object> f = new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE);
+ assertNull(f.evaluate());
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Object> f = new UnaryProcedureUnaryFunction<Object, Object>(NoOp.INSTANCE);
+ NullaryFunction<Object> f = new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE);
assertEquals(f,f);
- assertObjectsAreEqual(f,new UnaryProcedureUnaryFunction<Object, Object>(NoOp.INSTANCE));
+ assertObjectsAreEqual(f,new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(f,Constant.of("x"));
- assertObjectsAreNotEqual(f, new UnaryProcedureUnaryFunction<Object, Object>(new UnaryProcedure<Object>() {
- public void run(Object a) {
- }
- }));
+ assertObjectsAreNotEqual(f,new NullaryProcedureNullaryFunction<Object>(new NullaryProcedure() { public void run() { } }));
assertObjectsAreNotEqual(f,Constant.of(null));
assertTrue(!f.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(UnaryProcedureUnaryFunction.adapt(null));
+ assertNull(NullaryProcedureNullaryFunction.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(UnaryProcedureUnaryFunction.adapt(new NoOp()));
+ assertNotNull(NullaryProcedureNullaryFunction.adapt(new NoOp()));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
index 9fe29f1..2f74b30 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestPredicateFunction.java
@@ -36,7 +36,7 @@
@Override
protected Object makeFunctor() {
- return new PredicateFunction(Constant.of(Boolean.TRUE));
+ return new PredicateFunction<Object>(Constant.TRUE);
}
// Tests
@@ -44,23 +44,23 @@
@Test
public void testTestWhenTrue() throws Exception {
- Function<Boolean> f = new PredicateFunction(Constant.TRUE);
- assertEquals(Boolean.TRUE,f.evaluate());
+ Function<Object, Boolean> f = new PredicateFunction<Object>(Constant.TRUE);
+ assertEquals(Boolean.TRUE,f.evaluate(null));
}
@Test
public void testTestWhenFalse() throws Exception {
- Function<Boolean> f = new PredicateFunction(Constant.FALSE);
- assertEquals(Boolean.FALSE,f.evaluate());
+ Function<Object, Boolean> f = new PredicateFunction<Object>(Constant.FALSE);
+ assertEquals(Boolean.FALSE,f.evaluate(null));
}
@Test
public void testEquals() throws Exception {
- Function<Boolean> f = new PredicateFunction(Constant.TRUE);
+ Function<Object, Boolean> f = new PredicateFunction<Object>(Constant.TRUE);
assertEquals(f,f);
- assertObjectsAreEqual(f,new PredicateFunction(Constant.TRUE));
+ assertObjectsAreEqual(f,new PredicateFunction<Object>(Constant.TRUE));
assertObjectsAreNotEqual(f,Constant.of("x"));
- assertObjectsAreNotEqual(f,new PredicateFunction(Constant.FALSE));
+ assertObjectsAreNotEqual(f,new PredicateFunction<Object>(Constant.FALSE));
assertTrue(!f.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
index 118bc72..bbf7317 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureFunction.java
@@ -38,7 +38,7 @@
@Override
protected Object makeFunctor() {
- return new ProcedureFunction<Object>(NoOp.INSTANCE);
+ return new ProcedureFunction<Object, Object>(NoOp.INSTANCE);
}
// Tests
@@ -46,17 +46,20 @@
@Test
public void testEvaluate() throws Exception {
- Function<Object> f = new ProcedureFunction<Object>(NoOp.INSTANCE);
- assertNull(f.evaluate());
+ Function<Object, Object> f = new ProcedureFunction<Object, Object>(NoOp.INSTANCE);
+ assertNull(f.evaluate(null));
}
@Test
public void testEquals() throws Exception {
- Function<Object> f = new ProcedureFunction<Object>(NoOp.INSTANCE);
+ Function<Object, Object> f = new ProcedureFunction<Object, Object>(NoOp.INSTANCE);
assertEquals(f,f);
- assertObjectsAreEqual(f,new ProcedureFunction<Object>(NoOp.INSTANCE));
+ assertObjectsAreEqual(f,new ProcedureFunction<Object, Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(f,Constant.of("x"));
- assertObjectsAreNotEqual(f,new ProcedureFunction<Object>(new Procedure() { public void run() { } }));
+ assertObjectsAreNotEqual(f, new ProcedureFunction<Object, Object>(new Procedure<Object>() {
+ public void run(Object a) {
+ }
+ }));
assertObjectsAreNotEqual(f,Constant.of(null));
assertTrue(!f.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureProcedure.java
similarity index 68%
rename from core/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
rename to core/src/test/java/org/apache/commons/functor/adapter/TestProcedureProcedure.java
index d7ae328..7467ab4 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestProcedureProcedure.java
@@ -22,23 +22,23 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
-import org.apache.commons.functor.core.composite.Sequence;
+import org.apache.commons.functor.core.composite.NullarySequence;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestProcedureUnaryProcedure extends BaseFunctorTest {
+public class TestProcedureProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
+ return new NullaryProcedureProcedure<Object>(NoOp.INSTANCE);
}
// Tests
@@ -46,27 +46,27 @@
@Test
public void testEvaluate() throws Exception {
- UnaryProcedure<Object> p = new ProcedureUnaryProcedure<Object>(new FunctionProcedure(Constant.of(null)));
+ Procedure<Object> p = new NullaryProcedureProcedure<Object>(new NullaryFunctionNullaryProcedure(Constant.of(null)));
p.run(Boolean.TRUE);
}
@Test
public void testEquals() throws Exception {
- UnaryProcedure<Object> p = new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE);
+ Procedure<Object> p = new NullaryProcedureProcedure<Object>(NoOp.INSTANCE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ProcedureUnaryProcedure<Object>(NoOp.INSTANCE));
+ assertObjectsAreEqual(p,new NullaryProcedureProcedure<Object>(NoOp.INSTANCE));
assertObjectsAreNotEqual(p,NoOp.INSTANCE);
- assertObjectsAreNotEqual(p,new ProcedureUnaryProcedure<Object>(new Sequence()));
+ assertObjectsAreNotEqual(p,new NullaryProcedureProcedure<Object>(new NullarySequence()));
assertTrue(!p.equals(null));
}
@Test
public void testAdaptNull() throws Exception {
- assertNull(ProcedureUnaryProcedure.adapt(null));
+ assertNull(NullaryProcedureProcedure.adapt(null));
}
@Test
public void testAdapt() throws Exception {
- assertNotNull(ProcedureUnaryProcedure.adapt(NoOp.INSTANCE));
+ assertNotNull(NullaryProcedureProcedure.adapt(NoOp.INSTANCE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java
index b64525e..a2da587 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java
@@ -22,7 +22,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.LeftIdentity;
import org.apache.commons.functor.core.RightIdentity;
@@ -46,13 +46,13 @@
@Test
public void testEvaluate() throws Exception {
- UnaryFunction<String, String> f = RightBoundFunction.bind(LeftIdentity.<String, String>function(),"foo");
+ Function<String, String> f = RightBoundFunction.bind(LeftIdentity.<String, String>function(),"foo");
assertEquals("xyzzy",f.evaluate("xyzzy"));
}
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Object> f = RightBoundFunction.bind(LeftIdentity.FUNCTION,"xyzzy");
+ Function<Object, Object> f = RightBoundFunction.bind(LeftIdentity.FUNCTION,"xyzzy");
assertEquals(f,f);
assertObjectsAreEqual(f,new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,"xyzzy"));
assertObjectsAreNotEqual(f,Constant.of("xyzzy"));
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java
index 1033ecb..1b338fc 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java
@@ -23,7 +23,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.LeftIdentity;
import org.junit.Test;
@@ -46,7 +46,7 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Boolean> f = new RightBoundPredicate<Boolean>(
+ Predicate<Boolean> f = new RightBoundPredicate<Boolean>(
new BinaryFunctionBinaryPredicate<Boolean, Object>(LeftIdentity.<Boolean, Object> function()), "foo");
assertTrue(f.test(Boolean.TRUE));
assertFalse(f.test(Boolean.FALSE));
@@ -54,7 +54,7 @@
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Boolean> f = new RightBoundPredicate<Boolean>(Constant.TRUE, "xyzzy");
+ Predicate<Boolean> f = new RightBoundPredicate<Boolean>(Constant.TRUE, "xyzzy");
assertEquals(f, f);
assertObjectsAreEqual(f, new RightBoundPredicate<Boolean>(Constant.TRUE, "xyzzy"));
assertObjectsAreNotEqual(f, Constant.TRUE);
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java
index 13801b2..609827a 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java
@@ -22,7 +22,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.LeftIdentity;
import org.apache.commons.functor.core.NoOp;
import org.apache.commons.functor.core.composite.BinarySequence;
@@ -46,7 +46,7 @@
@Test
public void testRun() throws Exception {
- UnaryProcedure<Object> p = new RightBoundProcedure<Object>(
+ Procedure<Object> p = new RightBoundProcedure<Object>(
new BinaryFunctionBinaryProcedure<Object, Object>(LeftIdentity.FUNCTION), "foo");
p.run(Boolean.TRUE);
p.run(Boolean.FALSE);
@@ -54,7 +54,7 @@
@Test
public void testEquals() throws Exception {
- UnaryProcedure<Object> f = new RightBoundProcedure<Object>(NoOp.INSTANCE,"xyzzy");
+ Procedure<Object> f = new RightBoundProcedure<Object>(NoOp.INSTANCE,"xyzzy");
assertEquals(f,f);
assertObjectsAreEqual(f,new RightBoundProcedure<Object>(NoOp.INSTANCE,"xyzzy"));
assertObjectsAreNotEqual(f,NoOp.INSTANCE);
diff --git a/core/src/test/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregatorTest.java b/core/src/test/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregatorTest.java
index 0d1eddb..cf39f63 100644
--- a/core/src/test/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregatorTest.java
+++ b/core/src/test/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregatorTest.java
@@ -26,7 +26,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.aggregator.AbstractListBackedAggregator;
import org.junit.Test;
@@ -85,7 +85,7 @@
public void testEvaluate() throws Exception {
@SuppressWarnings("unchecked")
TestListBackedAggregator<Object> fct = (TestListBackedAggregator<Object>) makeFunctor();
- TestUnaryFunction<Object> agg = (TestUnaryFunction<Object>) fct.getAggregationFunction();
+ TestFunction<Object> agg = (TestFunction<Object>) fct.getAggregationFunction();
int calls = 31; // nearly 10 pies :)
// test first without throwing an exception
for (int i = 1; i <= calls; i++) {
@@ -123,7 +123,7 @@
public void testAddEvaluateReset() throws Exception {
@SuppressWarnings("unchecked")
TestListBackedAggregator<Object> fct = (TestListBackedAggregator<Object>) makeFunctor();
- TestUnaryFunction<Object> agg = (TestUnaryFunction<Object>) fct.getAggregationFunction();
+ TestFunction<Object> agg = (TestFunction<Object>) fct.getAggregationFunction();
int callsAdd = 31; // nearly 10 pies :)
int callsEvaluate = 2; // circumference (i.e. 2 pies)
int callsReset = 17;
@@ -166,10 +166,10 @@
}
/**
- * Dummy UnaryFunction which counts the number of calls to
+ * Dummy Function which counts the number of calls to
* {@link #evaluate(List)}.
*/
- class TestUnaryFunction<T> implements UnaryFunction<List<T>, T> {
+ class TestFunction<T> implements Function<List<T>, T> {
int calls = 0;
boolean exception = false; // when set to true, evaluate will throw an
// exception
@@ -189,7 +189,7 @@
int callsCreateList;
public TestListBackedAggregator() {
- super(new TestUnaryFunction<T>());
+ super(new TestFunction<T>());
resetUsage();
}
@@ -199,7 +199,7 @@
*/
public void resetUsage() {
callsCreateList = 0;
- TestUnaryFunction<T> fct = (TestUnaryFunction<T>) getAggregationFunction();
+ TestFunction<T> fct = (TestFunction<T>) getAggregationFunction();
fct.calls = 0;
}
diff --git a/core/src/test/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregatorTest.java b/core/src/test/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregatorTest.java
index c1b0c0f..9150145 100644
--- a/core/src/test/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregatorTest.java
+++ b/core/src/test/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregatorTest.java
@@ -24,7 +24,7 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.aggregator.ArrayListBackedAggregator;
import org.junit.Test;
@@ -35,7 +35,7 @@
public class ArrayListBackedAggregatorTest extends BaseFunctorTest {
@Override
protected Object makeFunctor() throws Exception {
- return new ArrayListBackedAggregator<Object>(new SelectFirstUnaryFunction<Object>());
+ return new ArrayListBackedAggregator<Object>(new SelectFirstFunction<Object>());
}
@Test
@@ -47,18 +47,18 @@
assertEquals(fct.getSeries().size(), 0);
// NOTE: would be good to be able to check the ArrayList capacity!
int initialSize = 31; // nearly 10 pies
- fct = new ArrayListBackedAggregator<Object>(new SelectFirstUnaryFunction<Object>(), initialSize);
+ fct = new ArrayListBackedAggregator<Object>(new SelectFirstFunction<Object>(), initialSize);
assertNotNull(fct.getSeries());
assertTrue(fct.getSeries() instanceof ArrayList);
assertEquals(fct.getSeries().size(), 0);
}
/**
- * Dummy UnaryFunction which counts the number of calls to
+ * Dummy Function which counts the number of calls to
* {@link #evaluate(List)} and always selects the first item in the given
* list or null if list is null or empty.
*/
- class SelectFirstUnaryFunction<T> implements UnaryFunction<List<T>, T> {
+ class SelectFirstFunction<T> implements Function<List<T>, T> {
int calls = 0;
boolean exception = false; // when set to true, evaluate will throw an
// exception
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java b/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
index 01047c7..c0430bf 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
@@ -23,8 +23,8 @@
import static org.junit.Assert.fail;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -45,7 +45,7 @@
@Test
public void testEvaluate() throws Exception {
- UnaryFunction<Object, Object> f = new Identity<Object>();
+ Function<Object, Object> f = new Identity<Object>();
assertNull(f.evaluate(null));
assertEquals("xyzzy",f.evaluate("xyzzy"));
assertEquals(new Integer(3),f.evaluate(new Integer(3)));
@@ -55,7 +55,7 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Object> p = new Identity<Object>();
+ Predicate<Object> p = new Identity<Object>();
assertTrue(p.test(Boolean.TRUE));
assertTrue(!p.test(Boolean.FALSE));
try {
@@ -74,7 +74,7 @@
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Object> f = new Identity<Object>();
+ Function<Object, Object> f = new Identity<Object>();
assertEquals(f,f);
assertObjectsAreEqual(f,new Identity<Object>());
assertObjectsAreEqual(f,Identity.instance());
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java b/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
index 82656a7..4d6db9b 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
@@ -24,7 +24,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -78,8 +78,8 @@
}
@Test
- public void testToUnaryPredicate() {
- UnaryPredicate<Integer> isEqual = IsEqual.to(new Integer(1));
+ public void testToPredicate() {
+ Predicate<Integer> isEqual = IsEqual.to(new Integer(1));
assertTrue(isEqual.test(new Integer(1)));
assertFalse(isEqual.test(new Integer(2)));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsInstance.java b/core/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
index 6aa4c8c..f02aa80 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
@@ -23,7 +23,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -53,7 +53,7 @@
@Test
public void testBoundTest() throws Exception {
- UnaryPredicate<Object> p = IsInstance.of(Number.class);
+ Predicate<Object> p = IsInstance.of(Number.class);
assertFalse(p.test(null));
assertFalse(p.test("foo"));
assertTrue(p.test(3));
@@ -81,7 +81,7 @@
@Test
public void testBoundEquals() throws Exception {
- UnaryPredicate<Object> p = IsInstance.of(Object.class);
+ Predicate<Object> p = IsInstance.of(Object.class);
assertEquals(p,p);
assertObjectsAreEqual(p,IsInstance.of(Object.class));
assertObjectsAreNotEqual(p,Constant.truePredicate());
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
index 252e1fd..fc24eae 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
@@ -22,7 +22,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -73,8 +73,8 @@
}
@Test
- public void testToUnaryPredicate() {
- UnaryPredicate<Integer> isNotEqual = IsNotEqual.to(new Integer(1));
+ public void testToPredicate() {
+ Predicate<Integer> isNotEqual = IsNotEqual.to(new Integer(1));
assertTrue(isNotEqual.test(new Integer(2)));
assertFalse(isNotEqual.test(new Integer(1)));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
index 7e5173f..74137e9 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
@@ -20,7 +20,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -41,7 +41,7 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Object> p = new IsNotNull<Object>();
+ Predicate<Object> p = new IsNotNull<Object>();
assertTrue(!p.test(null));
assertTrue(p.test("foo"));
assertTrue(p.test(new Integer(3)));
@@ -49,7 +49,7 @@
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Object> p = new IsNotNull<Object>();
+ Predicate<Object> p = new IsNotNull<Object>();
assertEquals(p,p);
assertObjectsAreEqual(p,new IsNotNull<Object>());
assertObjectsAreEqual(p,IsNotNull.instance());
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
index 094088a..751674d 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
@@ -24,7 +24,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -78,9 +78,9 @@
}
@Test
- public void testAsUnaryPredicate() {
+ public void testAsPredicate() {
Integer one = new Integer(1);
- UnaryPredicate<Integer> isNotSame = IsNotSame.as(one);
+ Predicate<Integer> isNotSame = IsNotSame.as(one);
assertTrue(isNotSame.test(new Integer(2)));
assertFalse(isNotSame.test(one));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
index 7004c46..8696e97 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
@@ -21,7 +21,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -42,7 +42,7 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Object> p = new IsNull<Object>();
+ Predicate<Object> p = new IsNull<Object>();
assertTrue(p.test(null));
assertFalse(p.test("foo"));
assertFalse(p.test(new Integer(3)));
@@ -58,7 +58,7 @@
@Test
public void testEquals() throws Exception {
- UnaryPredicate<Object> p = new IsNull<Object>();
+ Predicate<Object> p = new IsNull<Object>();
assertEquals(p,p);
assertObjectsAreEqual(p,new IsNull<Object>());
assertObjectsAreEqual(p,IsNull.instance());
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java b/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
index 3c10c51..259a5f9 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
@@ -24,7 +24,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.junit.Test;
/**
@@ -78,9 +78,9 @@
}
@Test
- public void testAsUnaryPredicate() {
+ public void testAsPredicate() {
Integer one = new Integer(1);
- UnaryPredicate<Integer> isSame = IsSame.as(one);
+ Predicate<Integer> isSame = IsSame.as(one);
assertTrue(isSame.test(one));
assertFalse(isSame.test(new Integer(2)));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestLimit.java b/core/src/test/java/org/apache/commons/functor/core/TestLimit.java
index 00e6495..7ebbb2e 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestLimit.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestLimit.java
@@ -22,8 +22,8 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
import org.junit.Test;
/**
@@ -45,7 +45,7 @@
@Test
public void testZero() throws Exception {
- Predicate p = new Limit(0);
+ NullaryPredicate p = new Limit(0);
assertTrue(! p.test());
assertTrue(! p.test());
assertTrue(! p.test());
@@ -63,7 +63,7 @@
@Test
public void testTestNullary() throws Exception {
- Predicate p = new Limit(3);
+ NullaryPredicate p = new Limit(3);
assertTrue(p.test());
assertTrue(p.test());
assertTrue(p.test());
@@ -72,7 +72,7 @@
@Test
public void testTestUnary() throws Exception {
- UnaryPredicate<Object> p = new Limit(3);
+ Predicate<Object> p = new Limit(3);
assertTrue(p.test(null));
assertTrue(p.test(null));
assertTrue(p.test(null));
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestNoOp.java b/core/src/test/java/org/apache/commons/functor/core/TestNoOp.java
index 49a1b53..c877963 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestNoOp.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestNoOp.java
@@ -21,8 +21,8 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryProcedure;
import org.junit.Test;
/**
@@ -59,8 +59,8 @@
assertEquals(p,p);
assertObjectsAreEqual(p,new NoOp());
assertObjectsAreEqual(p,NoOp.instance());
- assertObjectsAreNotEqual(p,new Procedure() { public void run() { } });
- assertObjectsAreNotEqual(p,new UnaryProcedure<Object>() { public void run(Object a) { } });
+ assertObjectsAreNotEqual(p,new NullaryProcedure() { public void run() { } });
+ assertObjectsAreNotEqual(p,new Procedure<Object>() { public void run(Object a) { } });
assertObjectsAreNotEqual(p,new BinaryProcedure<Object, Object>() { public void run(Object a, Object b) { } });
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestOffset.java b/core/src/test/java/org/apache/commons/functor/core/TestOffset.java
index 682a45e..4bb4c10 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestOffset.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestOffset.java
@@ -21,8 +21,8 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.UnaryPredicate;
import org.junit.Test;
/**
@@ -46,7 +46,7 @@
@Test
public void testZero() throws Exception {
- Predicate p = new Offset(0);
+ NullaryPredicate p = new Offset(0);
assertTrue( p.test());
assertTrue( p.test());
assertTrue( p.test());
@@ -64,7 +64,7 @@
@Test
public void testTestNullary() throws Exception {
- Predicate p = new Offset(3);
+ NullaryPredicate p = new Offset(3);
assertTrue(!p.test());
assertTrue(!p.test());
assertTrue(!p.test());
@@ -73,7 +73,7 @@
@Test
public void testTestUnary() throws Exception {
- UnaryPredicate<Object> p = new Offset(3);
+ Predicate<Object> p = new Offset(3);
assertTrue(!p.test(null));
assertTrue(!p.test(null));
assertTrue(!p.test(null));
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java
index 408b199..52c1554 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java
@@ -21,7 +21,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Offset;
import org.junit.Test;
@@ -51,7 +51,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Counter implements Procedure, Serializable {
+ static class Counter implements NullaryProcedure, Serializable {
private static final long serialVersionUID = 1L;
public void run() {
count++;
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java
index 9c9faa2..f74dade 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java
@@ -21,7 +21,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Limit;
import org.junit.Test;
@@ -51,7 +51,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Counter implements Procedure, Serializable {
+ static class Counter implements NullaryProcedure, Serializable {
private static final long serialVersionUID = 1L;
public void run() {
count++;
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
index c6837d0..d1a0aed 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
@@ -25,7 +25,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
@@ -105,8 +105,8 @@
private List<Integer> numbers = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
private List<String> strings = Arrays.asList("Zyx", "xxyZ");
- private UnaryPredicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
- private UnaryPredicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
- private UnaryPredicate<String> equalsXyZ = LeftBoundPredicate.bind(IsEqual.instance(),"xyZ");
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
+ private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
+ private Predicate<String> equalsXyZ = LeftBoundPredicate.bind(IsEqual.instance(),"xyZ");
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
index f9bf5cf..9eeb61f 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
@@ -23,7 +23,7 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
import org.apache.commons.functor.core.algorithm.GeneratorContains;
@@ -50,7 +50,7 @@
// ------------------------------------------------------------------------
private List<Integer> list = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
- private UnaryPredicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
- private UnaryPredicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
+ private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
index 579ee59..66f0fa7 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
@@ -23,7 +23,7 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.algorithm.InPlaceTransform;
import org.junit.After;
import org.junit.Before;
@@ -65,7 +65,7 @@
public void testTransform() {
new InPlaceTransform<Integer>().run(
list.listIterator(),
- new UnaryFunction<Integer, Integer>() {
+ new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return new Integer(obj*2);
}
@@ -86,7 +86,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Doubler implements UnaryFunction<Integer, Integer> {
+ static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
return new Integer(2*obj);
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
index df6f807..095a4ae 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
@@ -22,7 +22,7 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.LeftBoundPredicate;
import org.apache.commons.functor.core.IsEqual;
import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
@@ -47,6 +47,6 @@
// ------------------------------------------------------------------------
private List<Integer> list = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
- private UnaryPredicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
index 45b2e45..367dfb7 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
@@ -22,7 +22,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Function;
+import org.apache.commons.functor.NullaryFunction;
import org.junit.Test;
/**
@@ -42,7 +42,7 @@
// this version will return a function. since it is not the same type
// as RecFunc recursion will end.
@SuppressWarnings({ "unchecked", "rawtypes" })
- Function<Object> func = (Function) new RecursiveEvaluation(new RecFunc(0, true)).evaluate();
+ NullaryFunction<Object> func = (NullaryFunction) new RecursiveEvaluation(new RecFunc(0, true)).evaluate();
assertEquals(new Integer(5), func.evaluate());
}
@@ -62,7 +62,7 @@
// ------------------------------------------------------------------------
/** Recursive function for test. */
- static class RecFunc implements Function<Object>, Serializable {
+ static class RecFunc implements NullaryFunction<Object>, Serializable {
private static final long serialVersionUID = 1L;
int times = 0;
@@ -78,7 +78,7 @@
return new RecFunc(++times, returnFunc);
} else {
if (returnFunc) {
- return new InnerFunction(times);
+ return new InnerNullaryFunction(times);
} else {
return new Integer(times);
}
@@ -103,12 +103,12 @@
}
/** Inner function called from recursive function */
- static class InnerFunction implements Function<Object>, Serializable {
+ static class InnerNullaryFunction implements NullaryFunction<Object>, Serializable {
private static final long serialVersionUID = 1L;
private int times;
- public InnerFunction(int times) {
+ public InnerNullaryFunction(int times) {
this.times = times;
}
@@ -121,15 +121,15 @@
if(this == obj) {
return true;
}
- if(obj == null || ! (obj instanceof InnerFunction)) {
+ if(obj == null || ! (obj instanceof InnerNullaryFunction)) {
return false;
}
- return this.times == ((InnerFunction)obj).times;
+ return this.times == ((InnerNullaryFunction)obj).times;
}
@Override
public int hashCode() {
- return "InnerFunction".hashCode() << 2 ^ times;
+ return "InnerNullaryFunction".hashCode() << 2 ^ times;
}
};
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
index 723721b..12ee536 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
@@ -22,8 +22,8 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.algorithm.RemoveMatching;
import org.junit.After;
import org.junit.Before;
@@ -73,7 +73,7 @@
// ------------------------------------------------------------------------
private List<Integer> list = null;
private List<Integer> evens = null;
- private UnaryPredicate<Integer> isOdd = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isOdd = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 != 0;
}
@@ -82,7 +82,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Doubler implements UnaryFunction<Integer, Integer> {
+ static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
return new Integer(2*obj);
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
index 5a5a410..25f4cb5 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
@@ -22,8 +22,8 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.algorithm.RetainMatching;
import org.junit.After;
import org.junit.Before;
@@ -73,7 +73,7 @@
// ------------------------------------------------------------------------
private List<Integer> list = null;
private List<Integer> odds = null;
- private UnaryPredicate<Integer> isOdd = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isOdd = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 != 0;
}
@@ -82,7 +82,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Doubler implements UnaryFunction<Integer, Integer> {
+ static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
return new Integer(2*obj);
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java
index 7b54f41..79c53d5 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java
@@ -21,7 +21,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Offset;
import org.junit.Test;
@@ -51,7 +51,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Counter implements Procedure, Serializable {
+ static class Counter implements NullaryProcedure, Serializable {
private static final long serialVersionUID = 1L;
public void run() {
count++;
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java
index 4db16b7..69ffdcb 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java
@@ -21,7 +21,7 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Limit;
import org.apache.commons.functor.core.Offset;
import org.junit.Test;
@@ -52,7 +52,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Counter implements Procedure, Serializable {
+ static class Counter implements NullaryProcedure, Serializable {
private static final long serialVersionUID = 1L;
public void run() {
count++;
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java
index 20fd1e7..fc0956b 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java
@@ -30,7 +30,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.IsEqual;
import org.junit.After;
@@ -48,7 +48,7 @@
private List<Integer> list = null;
private List<Integer> evens = null;
- private UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj != null && obj % 2 == 0;
}
@@ -275,6 +275,6 @@
@Test(expected=NullPointerException.class)
public void testRetainNullPredicate() {
- FilteredIterable.of(Collections.singleton("foo")).retain((UnaryPredicate<String>) null);
+ FilteredIterable.of(Collections.singleton("foo")).retain((Predicate<String>) null);
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
index 29d04bd..2df1ecc 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
@@ -28,7 +28,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.junit.After;
import org.junit.Before;
@@ -214,12 +214,12 @@
public void testEquals() {
Iterator<Integer> iter = list.iterator();
FilteredIterator<Integer> t = new FilteredIterator<Integer>(iter, isEven);
- UnaryPredicate<Integer> isOdd = new UnaryPredicate<Integer>() {
+ Predicate<Integer> isOdd = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj.intValue() % 2 != 0;
}
};
- UnaryPredicate<Float> isOddFloat = new UnaryPredicate<Float>() {
+ Predicate<Float> isOddFloat = new Predicate<Float>() {
public boolean test(Float obj) {
return obj.intValue() % 2 != 0;
}
@@ -234,7 +234,7 @@
// ------------------------------------------------------------------------
private List<Integer> list = null;
private List<Integer> evens = null;
- private UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj.intValue() % 2 == 0;
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
index 4b76dd2..675e379 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
@@ -25,7 +25,7 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
@@ -52,7 +52,7 @@
list.add(new Integer(10));
list.add(new Integer(15));
- UnaryPredicate<Integer> p = IsElementOf.instance(list);
+ Predicate<Integer> p = IsElementOf.instance(list);
assertTrue(p.test(new Integer(5)));
assertTrue(p.test(new Integer(10)));
assertTrue(p.test(new Integer(15)));
@@ -66,7 +66,7 @@
public void testTestArray() throws Exception {
int[] list = new int[] { 5, 10, 15 };
- UnaryPredicate<Integer> p = IsElementOf.instance(list);
+ Predicate<Integer> p = IsElementOf.instance(list);
assertTrue(p.test(new Integer(5)));
assertTrue(p.test(new Integer(10)));
assertTrue(p.test(new Integer(15)));
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
index ff6c810..2db23c9 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
@@ -29,7 +29,7 @@
import java.util.Set;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
@@ -106,7 +106,7 @@
@Test
public void testEquals() throws Exception {
- UnaryPredicate<String> p = new IsEmpty<String>();
+ Predicate<String> p = new IsEmpty<String>();
assertEquals(p,p);
assertObjectsAreEqual(p,new IsEmpty<Long>());
assertObjectsAreEqual(p,IsEmpty.instance());
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
index 8ca8213..297cc13 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
@@ -28,7 +28,7 @@
import java.util.Set;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
@@ -100,7 +100,7 @@
@Test
public void testEquals() throws Exception {
- UnaryFunction<Object, Integer> f = new Size<Object>();
+ Function<Object, Integer> f = new Size<Object>();
assertEquals(f,f);
assertObjectsAreEqual(f,new Size<Object>());
assertObjectsAreEqual(f,Size.instance());
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
index 13d53a3..1c61866 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
@@ -30,7 +30,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Identity;
import org.junit.After;
import org.junit.Before;
@@ -188,7 +188,7 @@
public void testEquals() {
Iterator<Integer> iter = list.iterator();
TransformedIterator<Integer, Integer> t = new TransformedIterator<Integer, Integer>(iter, negate);
- UnaryFunction<Number, Double> negateDouble = new UnaryFunction<Number, Double>() {
+ Function<Number, Double> negateDouble = new Function<Number, Double>() {
public Double evaluate(Number obj) {
return new Double(obj.intValue() * -1);
}
@@ -203,7 +203,7 @@
// ------------------------------------------------------------------------
private List<Integer> list = null;
private List<Integer> negatives = null;
- private UnaryFunction<Number, Integer> negate = new UnaryFunction<Number, Integer>() {
+ private Function<Number, Integer> negate = new Function<Number, Integer>() {
public Integer evaluate(Number obj) {
return new Integer(obj.intValue() * -1);
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
index 2d7c414..abee5ad 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
@@ -22,7 +22,7 @@
import java.util.Collections;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.junit.Test;
/**
@@ -68,8 +68,8 @@
}
@Test
- public void testUnaryFunctionMin() {
- UnaryFunction<Integer, Integer> unaryMax = Max.instance(ONE);
- assertEquals(ONE,unaryMax.evaluate(ZERO));
+ public void testFunctionMin() {
+ Function<Integer, Integer> max = Max.instance(ONE);
+ assertEquals(ONE,max.evaluate(ZERO));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
index 5cc8c1c..3e63cd2 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
@@ -22,7 +22,7 @@
import java.util.Collections;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.junit.Test;
/**
@@ -68,8 +68,8 @@
}
@Test
- public void testUnaryFunctionMin() {
- UnaryFunction<Integer, Integer> unaryMin = Min.instance(ONE);
- assertEquals(ZERO,unaryMin.evaluate(ZERO));
+ public void testFunctionMin() {
+ Function<Integer, Integer> min = Min.instance(ONE);
+ assertEquals(ZERO,min.evaluate(ZERO));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopNullaryProcedure.java
similarity index 81%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopProcedure.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopNullaryProcedure.java
index a071a4f..d70fee3 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopNullaryProcedure.java
@@ -19,16 +19,16 @@
import static org.junit.Assert.assertEquals;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestAbstractLoopProcedure extends BaseFunctorTest {
+public class TestAbstractLoopNullaryProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@@ -47,13 +47,13 @@
assertEquals(p,p);
assertObjectsAreEqual(p,new MockLoopProcedure(Constant.FALSE, NoOp.INSTANCE));
assertObjectsAreNotEqual(p,new MockLoopProcedure(Constant.TRUE, NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new MockLoopProcedure(Constant.FALSE, new Sequence()));
+ assertObjectsAreNotEqual(p,new MockLoopProcedure(Constant.FALSE, new NullarySequence()));
}
}
-class MockLoopProcedure extends AbstractLoopProcedure {
+class MockLoopProcedure extends AbstractLoopNullaryProcedure {
private static final long serialVersionUID = 1L;
- public MockLoopProcedure(Predicate condition, Procedure action) {
+ public MockLoopProcedure(NullaryPredicate condition, NullaryProcedure action) {
super(condition,action);
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestAnd.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestAnd.java
index 1fb8334..b277dca 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestAnd.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestAnd.java
@@ -17,10 +17,9 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.util.Arrays;
-
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
@@ -29,6 +28,7 @@
/**
* @version $Revision$ $Date$
*/
+@SuppressWarnings("unchecked")
public class TestAnd extends BaseFunctorTest {
// Functor Testing Framework
@@ -36,7 +36,7 @@
@Override
protected Object makeFunctor() {
- return new And(Constant.TRUE, Constant.TRUE);
+ return new And<Object>(Constant.TRUE, Constant.TRUE);
}
// Tests
@@ -44,96 +44,91 @@
@Test
public void testTrue() throws Exception {
- assertTrue((new And()).test());
- assertTrue((new And(Constant.TRUE)).test());
- assertTrue((new And(Constant.TRUE,Constant.TRUE)).test());
- assertTrue((new And(Constant.TRUE,Constant.TRUE,Constant.TRUE)).test());
+ assertTrue((new And<Object>()).test("xyzzy"));
+ assertTrue((new And<Object>(Constant.TRUE)).test("xyzzy"));
+ assertTrue((new And<Object>(Constant.TRUE,Constant.TRUE)).test("xyzzy"));
+ assertTrue((new And<Object>(Constant.TRUE,Constant.TRUE,Constant.TRUE)).test("xyzzy"));
- And p = new And(Constant.TRUE);
- assertTrue(p.test());
+ And<Object> p = new And<Object>(Constant.TRUE);
+ assertTrue(p.test("xyzzy"));
for (int i=0;i<10;i++) {
p.and(Constant.TRUE);
- assertTrue(p.test());
+ assertTrue(p.test("xyzzy"));
}
- And q = new And(Constant.TRUE);
- assertTrue(q.test());
+ And<Object> q = new And<Object>(Constant.TRUE);
+ assertTrue(q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.and(Constant.TRUE);
- assertTrue(q.test());
+ assertTrue(q.test("xyzzy"));
}
- And r = new And(p,q);
- assertTrue(r.test());
+ And<Object> r = new And<Object>(p,q);
+ assertTrue(r.test("xyzzy"));
}
@Test
public void testFalse() throws Exception {
- assertTrue(!(new And(Constant.FALSE)).test());
- assertTrue(!(new And(Constant.TRUE,Constant.FALSE)).test());
- assertTrue(!(new And(Constant.TRUE,Constant.TRUE,Constant.FALSE)).test());
+ assertFalse(new And<Object>(Constant.FALSE).test("xyzzy"));
+ assertFalse(new And<Object>(Constant.TRUE,Constant.FALSE).test("xyzzy"));
+ assertFalse(new And<Object>(Constant.TRUE,Constant.TRUE,Constant.FALSE).test("xyzzy"));
- And p = new And(Constant.FALSE);
- assertTrue(!p.test());
+ And<Object> p = new And<Object>(Constant.FALSE);
+ assertTrue(!p.test("xyzzy"));
for (int i=0;i<10;i++) {
- p.and(Constant.FALSE);
- assertTrue(!p.test());
+ p.and(Constant.TRUE);
+ assertTrue(!p.test("xyzzy"));
}
- And q = new And(Constant.TRUE);
- assertTrue(q.test());
+ And<Object> q = new And<Object>(Constant.TRUE);
+ assertTrue(q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.and(Constant.TRUE);
- assertTrue(q.test());
+ assertTrue(q.test("xyzzy"));
}
- And r = new And(p,q);
- assertTrue(!r.test());
+ And<Object> r = new And<Object>(p,q);
+ assertTrue(!r.test("xyzzy"));
}
@Test
public void testDuplicateAdd() throws Exception {
- Predicate p = Constant.TRUE;
- And q = new And(p,p);
- assertTrue(q.test());
+ Predicate<Object> p = Constant.TRUE;
+ And<Object> q = new And<Object>(p,p);
+ assertTrue(q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.and(p);
- assertTrue(q.test());
+ assertTrue(q.test("xyzzy"));
}
}
+ @SuppressWarnings("rawtypes")
@Test
public void testEquals() throws Exception {
- And p = new And();
+ And<Object> p = new And<Object>();
assertEquals(p,p);
- And q = new And();
+ And<Object> q = new And<Object>();
assertObjectsAreEqual(p,q);
for (int i=0;i<3;i++) {
- p.and(Constant.TRUE);
+ p.and(Constant.truePredicate());
assertObjectsAreNotEqual(p,q);
q.and(Constant.truePredicate());
assertObjectsAreEqual(p,q);
- p.and(new And(Constant.TRUE,Constant.FALSE));
+ p.and(new And<Object>(Constant.truePredicate(),Constant.falsePredicate()));
assertObjectsAreNotEqual(p,q);
- q.and(new And(Constant.TRUE,Constant.FALSE));
+ q.and(new And<Object>(Constant.truePredicate(),Constant.falsePredicate()));
assertObjectsAreEqual(p,q);
}
- assertObjectsAreNotEqual(p,Constant.TRUE);
- Iterable<Predicate> iterable = Arrays.<Predicate>asList(
- Constant.TRUE,
- new And(Constant.TRUE, Constant.FALSE),
- Constant.TRUE,
- new And(Constant.TRUE, Constant.FALSE),
- Constant.TRUE,
- new And(Constant.TRUE, Constant.FALSE));
- assertObjectsAreEqual(p,new And(iterable));
-
- assertObjectsAreNotEqual(p,new And((Iterable<Predicate>)null));
- assertObjectsAreNotEqual(p,new And((Predicate[])null));
- assertObjectsAreNotEqual(p,new And((Predicate)null));
-
+ assertObjectsAreNotEqual(p,Constant.truePredicate());
+ And<Object> r = new And<Object>();
+ r.and(Constant.truePredicate());
+ r.and(new And<Object>(Constant.truePredicate(),Constant.falsePredicate()));
+ assertObjectsAreEqual(r, new And<Object>(r.getPredicateList()));
+ assertObjectsAreNotEqual(p, new And((Iterable<Predicate<Object>>)null));
+ assertObjectsAreNotEqual(p, new And((Predicate<Object>[])null));
+ assertObjectsAreNotEqual(p, new And((Predicate<Object>)null));
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryFunction.java
similarity index 76%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryFunction.java
index 28f0329..0926623 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryFunction.java
@@ -29,16 +29,16 @@
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryCompositeBinaryFunction extends BaseFunctorTest {
+public class TestCompositeBinaryFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ return new CompositeBinaryFunction<Object, Object, Object>(
RightIdentity.FUNCTION,
Constant.of("left"),
Identity.instance());
@@ -49,7 +49,7 @@
@Test
public void testEvaluate() throws Exception {
- BinaryFunction<Object, Object, Object> f = new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ BinaryFunction<Object, Object, Object> f = new CompositeBinaryFunction<Object, Object, Object>(
RightIdentity.FUNCTION,
Constant.of("K"),
Identity.instance());
@@ -60,28 +60,28 @@
@Test
public void testEquals() throws Exception {
- BinaryFunction<Object, Object, Object> f = new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ BinaryFunction<Object, Object, Object> f = new CompositeBinaryFunction<Object, Object, Object>(
LeftIdentity.FUNCTION,
Constant.of("left"),
Constant.of("right"));
assertEquals(f,f);
- assertObjectsAreEqual(f,new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ assertObjectsAreEqual(f,new CompositeBinaryFunction<Object, Object, Object>(
LeftIdentity.FUNCTION,
Constant.of("left"),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryFunction<Object, Object, Object>(
RightIdentity.FUNCTION,
Constant.of("left"),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryFunction<Object, Object, Object>(
LeftIdentity.FUNCTION,
Identity.instance(),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryFunction<Object, Object, Object>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryFunction<Object, Object, Object>(
LeftIdentity.FUNCTION,
Constant.of("left"),
Identity.instance()));
- assertTrue(!((UnaryCompositeBinaryFunction<?,?,?>)f).equals(null));
+ assertTrue(!((CompositeBinaryFunction<?,?,?>)f).equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryPredicate.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryPredicate.java
similarity index 75%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryPredicate.java
index 71adf8f..4fd9d48 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryCompositeBinaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeBinaryPredicate.java
@@ -28,16 +28,16 @@
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryCompositeBinaryPredicate extends BaseFunctorTest {
+public class TestCompositeBinaryPredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ return new CompositeBinaryPredicate<Boolean, Boolean>(
RightIdentity.PREDICATE,
Constant.FALSE,
new Identity<Boolean>());
@@ -48,7 +48,7 @@
@Test
public void testEvaluate() throws Exception {
- BinaryPredicate<Boolean, Boolean> f = new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ BinaryPredicate<Boolean, Boolean> f = new CompositeBinaryPredicate<Boolean, Boolean>(
RightIdentity.PREDICATE,
Constant.FALSE,
new Identity<Boolean>());
@@ -58,32 +58,32 @@
@Test
public void testEquals() throws Exception {
- BinaryPredicate<Boolean, Boolean> f = new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ BinaryPredicate<Boolean, Boolean> f = new CompositeBinaryPredicate<Boolean, Boolean>(
LeftIdentity.PREDICATE,
Constant.TRUE,
Constant.FALSE);
assertEquals(f,f);
- assertObjectsAreEqual(f,new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ assertObjectsAreEqual(f,new CompositeBinaryPredicate<Boolean, Boolean>(
LeftIdentity.PREDICATE,
Constant.TRUE,
Constant.FALSE));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryPredicate<Boolean, Boolean>(
RightIdentity.PREDICATE,
Constant.TRUE,
Constant.FALSE));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryPredicate<Boolean, Boolean>(
LeftIdentity.PREDICATE,
Constant.FALSE,
Constant.FALSE));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryPredicate<Boolean, Boolean>(
LeftIdentity.PREDICATE,
new Identity<Boolean>(),
Constant.TRUE));
- assertObjectsAreNotEqual(f,new UnaryCompositeBinaryPredicate<Boolean, Boolean>(
+ assertObjectsAreNotEqual(f,new CompositeBinaryPredicate<Boolean, Boolean>(
LeftIdentity.PREDICATE,
Constant.TRUE,
new Identity<Boolean>()));
- assertTrue(!((UnaryCompositeBinaryPredicate<?,?>)f).equals(null));
+ assertTrue(!((CompositeBinaryPredicate<?,?>)f).equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
similarity index 72%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
index e42dbe8..42f4274 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
@@ -20,15 +20,15 @@
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestCompositeUnaryFunction extends BaseFunctorTest {
+public class TestCompositeFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@@ -44,15 +44,15 @@
@Test
public void testEvaluate() throws Exception {
- assertEquals(new Integer(4),(new CompositeUnaryFunction<Object, Integer>(Constant.of(4))).evaluate(null));
+ assertEquals(new Integer(4),(new CompositeFunction<Object, Integer>(Constant.of(4))).evaluate(null));
assertEquals(new Integer(4),(Composite.function(Constant.of(4)).of(Constant.of(3)).evaluate("xyzzy")));
- assertEquals(new Integer(3),(new CompositeUnaryFunction<Object, Integer>(Constant.of(3)).of(Constant.of(4)).evaluate("xyzzy")));
+ assertEquals(new Integer(3),(new CompositeFunction<Object, Integer>(Constant.of(3)).of(Constant.of(4)).evaluate("xyzzy")));
}
@Test
public void testOf() throws Exception {
- UnaryFunction<Object, Integer> uf = new UnaryFunction<Object, Integer>() {
+ Function<Object, Integer> uf = new Function<Object, Integer>() {
public Integer evaluate(Object obj) {
if (obj instanceof Integer) {
return (((Integer) obj).intValue()) + 1;
@@ -61,23 +61,27 @@
}
}
};
- CompositeUnaryFunction<Object, Integer> f = null;
+ CompositeFunction<Object, Integer> f = null;
for (int i = 0; i < 10; i++) {
- f = f == null ? new CompositeUnaryFunction<Object, Integer>(uf) : f.of(uf);
+ f = f == null ? new CompositeFunction<Object, Integer>(uf) : f.of(uf);
assertEquals(Integer.valueOf(i+1),f.evaluate(null));
}
}
@Test
public void testEquals() throws Exception {
- CompositeUnaryFunction<Object, String> f = new CompositeUnaryFunction<Object, String>(Constant.of("x"));
+ CompositeFunction<Object, String> f = new CompositeFunction<Object, String>(Constant.of("x"));
assertEquals(f,f);
- CompositeUnaryFunction<Object, String> g = new CompositeUnaryFunction<Object, String>(Constant.of("x"));
+ CompositeFunction<Object, String> g = new CompositeFunction<Object, String>(Constant.of("x"));
assertObjectsAreEqual(f,g);
for (int i=0;i<3;i++) {
f = f.of(Constant.of("y")).of(Constant.of("z"));
+ System.out.println(f);
+ System.out.println(f.hashCode());
+ System.out.println(g);
+ System.out.println(g.hashCode());
assertObjectsAreNotEqual(f,g);
g = g.of(Constant.of("y")).of(Constant.of("z"));
assertObjectsAreEqual(f,g);
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositePredicate.java
similarity index 86%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestCompositePredicate.java
index 4a26414..f23a97b 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositePredicate.java
@@ -25,9 +25,9 @@
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestCompositeUnaryPredicate extends BaseFunctorTest {
+public class TestCompositePredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@@ -49,7 +49,7 @@
@Test(expected = NullPointerException.class)
public void testNullNotAllowed() throws Exception {
- new CompositeUnaryPredicate<Object>(null);
+ new CompositePredicate<Object>(null);
}
@Test(expected = NullPointerException.class)
@@ -59,7 +59,7 @@
@Test
public void testOf() throws Exception {
- CompositeUnaryPredicate<Object> f = new CompositeUnaryPredicate<Object>(Constant.TRUE);
+ CompositePredicate<Object> f = new CompositePredicate<Object>(Constant.TRUE);
assertTrue(f.test(null));
for (int i=0;i<10;i++) {
f = f.of(Constant.FALSE);
@@ -69,9 +69,9 @@
@Test
public void testEquals() throws Exception {
- CompositeUnaryPredicate<Object> f = new CompositeUnaryPredicate<Object>(Constant.TRUE);
+ CompositePredicate<Object> f = new CompositePredicate<Object>(Constant.TRUE);
assertEquals(f,f);
- CompositeUnaryPredicate<Object> g = new CompositeUnaryPredicate<Object>(Constant.TRUE);
+ CompositePredicate<Object> g = new CompositePredicate<Object>(Constant.TRUE);
assertObjectsAreEqual(f,g);
for (int i=0;i<3;i++) {
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeProcedure.java
similarity index 82%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryProcedure.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeProcedure.java
index ec2aff5..a492bf8 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeUnaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeProcedure.java
@@ -26,9 +26,9 @@
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestCompositeUnaryProcedure extends BaseFunctorTest {
+public class TestCompositeProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@@ -47,13 +47,13 @@
}
@Test(expected=NullPointerException.class)
- public void testNullUnaryProcedureNotAllowed() throws Exception {
- new CompositeUnaryProcedure<Object>(null);
+ public void testNulProcedureNotAllowed() throws Exception {
+ new CompositeProcedure<Object>(null);
}
@Test(expected=NullPointerException.class)
- public void testNullUnaryProcedureNotAllowed2() throws Exception {
- new CompositeUnaryProcedure<Object>(NoOp.instance()).of(null);
+ public void testNullProcedureNotAllowed2() throws Exception {
+ new CompositeProcedure<Object>(NoOp.instance()).of(null);
}
@Test
@@ -63,9 +63,9 @@
@Test
public void testEquals() throws Exception {
- CompositeUnaryProcedure<Object> f = Composite.procedure(NoOp.instance());
+ CompositeProcedure<Object> f = Composite.procedure(NoOp.instance());
assertEquals(f,f);
- CompositeUnaryProcedure<Object> g = Composite.procedure(NoOp.instance());
+ CompositeProcedure<Object> g = Composite.procedure(NoOp.instance());
assertObjectsAreEqual(f,g);
for (int i=0;i<3;i++) {
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditional.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditional.java
index e634672..71a462a 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditional.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditional.java
@@ -18,7 +18,7 @@
import static org.junit.Assert.assertNotNull;
-import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.IsEqual;
@@ -42,16 +42,19 @@
}
@Test
+ public void testNullaryMethods() {
+ assertNotNull(Conditional.procedure(new NullaryNot(Constant.TRUE),new NullarySequence()));
+ assertNotNull(Conditional.procedure(new NullaryNot(Constant.TRUE),new NullarySequence(),new NullarySequence()));
+ assertNotNull(Conditional.function(new NullaryNot(Constant.TRUE),Constant.FALSE,Constant.FALSE));
+ assertNotNull(Conditional.predicate((NullaryPredicate)Constant.truePredicate(),Constant.truePredicate(),Constant.truePredicate()));
+ }
+
+ @Test
public void testUnaryMethods() {
- assertNotNull(Conditional.procedure(new Not(Constant.TRUE),new Sequence()));
- assertNotNull(Conditional.procedure(new Not(Constant.TRUE),new Sequence(),new Sequence()));
- assertNotNull(Conditional.procedure(IsNull.instance(),NoOp.instance()));
- assertNotNull(Conditional.procedure(IsNull.instance(),NoOp.instance(),NoOp.instance()));
- assertNotNull(Conditional.procedure(new IsEqual<Object, Object>(),NoOp.INSTANCE));
- assertNotNull(Conditional.function(IsNull.instance(),Identity.instance(),Identity.instance()));
- assertNotNull(Conditional.function(new Not(Constant.TRUE),Constant.FALSE,Constant.FALSE));
- assertNotNull(Conditional.predicate((Predicate)Constant.truePredicate(),Constant.truePredicate(),Constant.truePredicate()));
- assertNotNull(Conditional.predicate(IsNull.instance(),Constant.truePredicate(),Constant.truePredicate()));
+ assertNotNull(Conditional.procedure(IsNull.instance(),NoOp.instance()));
+ assertNotNull(Conditional.procedure(IsNull.instance(),NoOp.instance(),NoOp.instance()));
+ assertNotNull(Conditional.function(IsNull.instance(),Identity.instance(),Identity.instance()));
+ assertNotNull(Conditional.predicate(IsNull.instance(),Constant.truePredicate(),Constant.truePredicate()));
}
@Test
@@ -59,5 +62,6 @@
assertNotNull(Conditional.procedure(IsGreaterThan.instance(),NoOp.instance(),NoOp.instance()));
assertNotNull(Conditional.function(IsGreaterThan.instance(),Max.instance(),Max.instance()));
assertNotNull(Conditional.predicate(IsGreaterThan.instance(),Constant.truePredicate(),Constant.truePredicate()));
+ assertNotNull(Conditional.procedure(new IsEqual<Object, Object>(),NoOp.INSTANCE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
index 93d8fed..3695429 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalFunction.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
@@ -33,7 +34,7 @@
@Override
protected Object makeFunctor() {
- return new ConditionalFunction<Object>(
+ return new ConditionalFunction<Object, Object>(
Constant.TRUE,
Constant.of("left"),
Constant.of("right"));
@@ -44,45 +45,37 @@
@Test
public void testEvaluate() throws Exception {
- {
- ConditionalFunction<Object> f = new ConditionalFunction<Object>(
- Constant.TRUE,
- Constant.of("left"),
- Constant.of("right"));
- assertEquals("left",f.evaluate());
- }
- {
- ConditionalFunction<Object> f = new ConditionalFunction<Object>(
- Constant.FALSE,
- Constant.of("left"),
- Constant.of("right"));
- assertEquals("right",f.evaluate());
- }
+ ConditionalFunction<Object, Object> f = new ConditionalFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of("left"),
+ Constant.of("right"));
+ assertEquals("left",f.evaluate(Boolean.TRUE));
+ assertEquals("right",f.evaluate(Boolean.FALSE));
}
@Test
public void testEquals() throws Exception {
- ConditionalFunction<Object> f = new ConditionalFunction<Object>(
- Constant.TRUE,
+ ConditionalFunction<Object, Object> f = new ConditionalFunction<Object, Object>(
+ Identity.INSTANCE,
Constant.of("left"),
Constant.of("right"));
assertEquals(f,f);
- assertObjectsAreEqual(f,new ConditionalFunction<Object>(
- Constant.TRUE,
+ assertObjectsAreEqual(f,new ConditionalFunction<Object, Object>(
+ Identity.INSTANCE,
Constant.of("left"),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new ConditionalFunction<Object>(
- Constant.TRUE,
+ assertObjectsAreNotEqual(f,new ConditionalFunction<Object, Object>(
+ Identity.INSTANCE,
Constant.of(null),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new ConditionalFunction<Object>(
+ assertObjectsAreNotEqual(f,new ConditionalFunction<Object, Object>(
Constant.TRUE,
Constant.of("left"),
- Constant.of(null)));
- assertObjectsAreNotEqual(f,new ConditionalFunction<Object>(
- Constant.FALSE,
- Constant.of("left"),
Constant.of("right")));
+ assertObjectsAreNotEqual(f,new ConditionalFunction<Object, Object>(
+ Identity.INSTANCE,
+ Constant.of("left"),
+ Constant.of(null)));
assertTrue(!f.equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryFunction.java
similarity index 61%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryFunction.java
index fae2345..6a82afb 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryFunction.java
@@ -21,20 +21,19 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.core.Constant;
-import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestConditionalUnaryFunction extends BaseFunctorTest {
+public class TestConditionalNullaryFunction extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new ConditionalUnaryFunction<Object, Object>(
+ return new ConditionalNullaryFunction<Object>(
Constant.TRUE,
Constant.of("left"),
Constant.of("right"));
@@ -45,37 +44,45 @@
@Test
public void testEvaluate() throws Exception {
- ConditionalUnaryFunction<Object, Object> f = new ConditionalUnaryFunction<Object, Object>(
- Identity.INSTANCE,
- Constant.of("left"),
- Constant.of("right"));
- assertEquals("left",f.evaluate(Boolean.TRUE));
- assertEquals("right",f.evaluate(Boolean.FALSE));
+ {
+ ConditionalNullaryFunction<Object> f = new ConditionalNullaryFunction<Object>(
+ Constant.TRUE,
+ Constant.of("left"),
+ Constant.of("right"));
+ assertEquals("left",f.evaluate());
+ }
+ {
+ ConditionalNullaryFunction<Object> f = new ConditionalNullaryFunction<Object>(
+ Constant.FALSE,
+ Constant.of("left"),
+ Constant.of("right"));
+ assertEquals("right",f.evaluate());
+ }
}
@Test
public void testEquals() throws Exception {
- ConditionalUnaryFunction<Object, Object> f = new ConditionalUnaryFunction<Object, Object>(
- Identity.INSTANCE,
+ ConditionalNullaryFunction<Object> f = new ConditionalNullaryFunction<Object>(
+ Constant.TRUE,
Constant.of("left"),
Constant.of("right"));
assertEquals(f,f);
- assertObjectsAreEqual(f,new ConditionalUnaryFunction<Object, Object>(
- Identity.INSTANCE,
- Constant.of("left"),
- Constant.of("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction<Object, Object>(
- Identity.INSTANCE,
- Constant.of(null),
- Constant.of("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction<Object, Object>(
+ assertObjectsAreEqual(f,new ConditionalNullaryFunction<Object>(
Constant.TRUE,
Constant.of("left"),
Constant.of("right")));
- assertObjectsAreNotEqual(f,new ConditionalUnaryFunction<Object, Object>(
- Identity.INSTANCE,
+ assertObjectsAreNotEqual(f,new ConditionalNullaryFunction<Object>(
+ Constant.TRUE,
+ Constant.of(null),
+ Constant.of("right")));
+ assertObjectsAreNotEqual(f,new ConditionalNullaryFunction<Object>(
+ Constant.TRUE,
Constant.of("left"),
Constant.of(null)));
+ assertObjectsAreNotEqual(f,new ConditionalNullaryFunction<Object>(
+ Constant.FALSE,
+ Constant.of("left"),
+ Constant.of("right")));
assertTrue(!f.equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryPredicate.java
similarity index 63%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryPredicate.java
index 59fdca1..7dc46e3 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryPredicate.java
@@ -21,20 +21,19 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.core.Constant;
-import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestConditionalUnaryPredicate extends BaseFunctorTest {
+public class TestConditionalNullaryPredicate extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new ConditionalUnaryPredicate<Object>(
+ return new ConditionalNullaryPredicate(
Constant.TRUE,
Constant.FALSE,
Constant.TRUE);
@@ -45,35 +44,43 @@
@Test
public void testTest() throws Exception {
- ConditionalUnaryPredicate<Object> p = new ConditionalUnaryPredicate<Object>(
- Identity.INSTANCE,
- Constant.TRUE,
- Constant.FALSE);
- assertTrue(p.test(Boolean.TRUE));
- assertTrue(!p.test(Boolean.FALSE));
+ {
+ ConditionalNullaryPredicate p = new ConditionalNullaryPredicate(
+ Constant.TRUE,
+ Constant.TRUE,
+ Constant.FALSE);
+ assertTrue(p.test());
+ }
+ {
+ ConditionalNullaryPredicate p = new ConditionalNullaryPredicate(
+ Constant.FALSE,
+ Constant.TRUE,
+ Constant.FALSE);
+ assertTrue(!p.test());
+ }
}
@Test
public void testEquals() throws Exception {
- ConditionalUnaryPredicate<Object> p = new ConditionalUnaryPredicate<Object>(
- Identity.INSTANCE,
+ ConditionalNullaryPredicate p = new ConditionalNullaryPredicate(
Constant.TRUE,
- Constant.TRUE);
+ Constant.TRUE,
+ Constant.FALSE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalUnaryPredicate<Object>(
- Identity.INSTANCE,
+ assertObjectsAreEqual(p,new ConditionalNullaryPredicate(
Constant.TRUE,
- Constant.TRUE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate<Object>(
- Identity.INSTANCE,
+ Constant.TRUE,
+ Constant.FALSE));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryPredicate(
+ Constant.TRUE,
Constant.FALSE,
Constant.TRUE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate<Object>(
+ assertObjectsAreNotEqual(p,new ConditionalNullaryPredicate(
Constant.TRUE,
Constant.TRUE,
Constant.TRUE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryPredicate<Object>(
- Identity.INSTANCE,
+ assertObjectsAreNotEqual(p,new ConditionalNullaryPredicate(
+ Constant.FALSE,
Constant.TRUE,
Constant.FALSE));
assertTrue(!p.equals(null));
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryProcedure.java
new file mode 100644
index 0000000..094dead
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalNullaryProcedure.java
@@ -0,0 +1,131 @@
+/*
+ * 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.functor.core.composite;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.NoOp;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestConditionalNullaryProcedure extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new ConditionalNullaryProcedure(
+ Constant.TRUE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE);
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testRun() throws Exception {
+ {
+ RunCounter left = new RunCounter();
+ RunCounter right = new RunCounter();
+ ConditionalNullaryProcedure p = new ConditionalNullaryProcedure(
+ Constant.TRUE,
+ left,
+ right);
+ assertEquals(0,left.count);
+ assertEquals(0,right.count);
+ p.run();
+ assertEquals(1,left.count);
+ assertEquals(0,right.count);
+ p.run();
+ assertEquals(2,left.count);
+ assertEquals(0,right.count);
+ p.run();
+ assertEquals(3,left.count);
+ assertEquals(0,right.count);
+ }
+ {
+ RunCounter left = new RunCounter();
+ RunCounter right = new RunCounter();
+ ConditionalNullaryProcedure p = new ConditionalNullaryProcedure(
+ Constant.FALSE,
+ left,
+ right);
+ assertEquals(0,left.count);
+ assertEquals(0,right.count);
+ p.run();
+ assertEquals(0,left.count);
+ assertEquals(1,right.count);
+ p.run();
+ assertEquals(0,left.count);
+ assertEquals(2,right.count);
+ p.run();
+ assertEquals(0,left.count);
+ assertEquals(3,right.count);
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ ConditionalNullaryProcedure p = new ConditionalNullaryProcedure(
+ Constant.FALSE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE);
+ assertEquals(p,p);
+ assertObjectsAreEqual(p,new ConditionalNullaryProcedure(
+ Constant.FALSE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryProcedure(
+ Constant.TRUE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryProcedure(
+ Constant.TRUE,
+ NoOp.INSTANCE,
+ NoOp.INSTANCE));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryProcedure(
+ Constant.FALSE,
+ new RunCounter(),
+ NoOp.INSTANCE));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryProcedure(
+ Constant.FALSE,
+ NoOp.INSTANCE,
+ new RunCounter()));
+ assertObjectsAreNotEqual(p,new ConditionalNullaryProcedure(
+ Constant.TRUE,
+ NoOp.INSTANCE));
+ assertTrue(!p.equals(null));
+ }
+
+ // Classes
+ // ------------------------------------------------------------------------
+
+ static class RunCounter implements NullaryProcedure {
+ public void run() {
+ count++;
+ }
+ public int count = 0;
+ }
+}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
index 8c72a70..6906517 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalPredicate.java
@@ -21,6 +21,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.Identity;
import org.junit.Test;
/**
@@ -33,7 +34,7 @@
@Override
protected Object makeFunctor() {
- return new ConditionalPredicate(
+ return new ConditionalPredicate<Object>(
Constant.TRUE,
Constant.FALSE,
Constant.TRUE);
@@ -44,43 +45,35 @@
@Test
public void testTest() throws Exception {
- {
- ConditionalPredicate p = new ConditionalPredicate(
- Constant.TRUE,
- Constant.TRUE,
- Constant.FALSE);
- assertTrue(p.test());
- }
- {
- ConditionalPredicate p = new ConditionalPredicate(
- Constant.FALSE,
- Constant.TRUE,
- Constant.FALSE);
- assertTrue(!p.test());
- }
+ ConditionalPredicate<Object> p = new ConditionalPredicate<Object>(
+ Identity.INSTANCE,
+ Constant.TRUE,
+ Constant.FALSE);
+ assertTrue(p.test(Boolean.TRUE));
+ assertTrue(!p.test(Boolean.FALSE));
}
@Test
public void testEquals() throws Exception {
- ConditionalPredicate p = new ConditionalPredicate(
+ ConditionalPredicate<Object> p = new ConditionalPredicate<Object>(
+ Identity.INSTANCE,
Constant.TRUE,
- Constant.TRUE,
- Constant.FALSE);
+ Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalPredicate(
+ assertObjectsAreEqual(p,new ConditionalPredicate<Object>(
+ Identity.INSTANCE,
Constant.TRUE,
- Constant.TRUE,
- Constant.FALSE));
- assertObjectsAreNotEqual(p,new ConditionalPredicate(
- Constant.TRUE,
+ Constant.TRUE));
+ assertObjectsAreNotEqual(p,new ConditionalPredicate<Object>(
+ Identity.INSTANCE,
Constant.FALSE,
Constant.TRUE));
- assertObjectsAreNotEqual(p,new ConditionalPredicate(
+ assertObjectsAreNotEqual(p,new ConditionalPredicate<Object>(
Constant.TRUE,
Constant.TRUE,
Constant.TRUE));
- assertObjectsAreNotEqual(p,new ConditionalPredicate(
- Constant.FALSE,
+ assertObjectsAreNotEqual(p,new ConditionalPredicate<Object>(
+ Identity.INSTANCE,
Constant.TRUE,
Constant.FALSE));
assertTrue(!p.equals(null));
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
index bb7ec01..5453381 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalProcedure.java
@@ -22,6 +22,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.core.Constant;
+import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
@@ -35,7 +36,7 @@
@Override
protected Object makeFunctor() {
- return new ConditionalProcedure(
+ return new ConditionalProcedure<Object>(
Constant.TRUE,
NoOp.INSTANCE,
NoOp.INSTANCE);
@@ -46,84 +47,59 @@
@Test
public void testRun() throws Exception {
- {
- RunCounter left = new RunCounter();
- RunCounter right = new RunCounter();
- ConditionalProcedure p = new ConditionalProcedure(
- Constant.TRUE,
- left,
- right);
- assertEquals(0,left.count);
- assertEquals(0,right.count);
- p.run();
- assertEquals(1,left.count);
- assertEquals(0,right.count);
- p.run();
- assertEquals(2,left.count);
- assertEquals(0,right.count);
- p.run();
- assertEquals(3,left.count);
- assertEquals(0,right.count);
- }
- {
- RunCounter left = new RunCounter();
- RunCounter right = new RunCounter();
- ConditionalProcedure p = new ConditionalProcedure(
- Constant.FALSE,
- left,
- right);
- assertEquals(0,left.count);
- assertEquals(0,right.count);
- p.run();
- assertEquals(0,left.count);
- assertEquals(1,right.count);
- p.run();
- assertEquals(0,left.count);
- assertEquals(2,right.count);
- p.run();
- assertEquals(0,left.count);
- assertEquals(3,right.count);
- }
+ RunCounter left = new RunCounter();
+ RunCounter right = new RunCounter();
+ ConditionalProcedure<Object> p = new ConditionalProcedure<Object>(
+ Identity.INSTANCE,
+ left,
+ right);
+ assertEquals(0,left.count);
+ assertEquals(0,right.count);
+ p.run(Boolean.TRUE);
+ assertEquals(1,left.count);
+ assertEquals(0,right.count);
+ p.run(Boolean.FALSE);
+ assertEquals(1,left.count);
+ assertEquals(1,right.count);
+ p.run(Boolean.TRUE);
+ assertEquals(2,left.count);
+ assertEquals(1,right.count);
}
@Test
public void testEquals() throws Exception {
- ConditionalProcedure p = new ConditionalProcedure(
- Constant.FALSE,
+ ConditionalProcedure<Object> p = new ConditionalProcedure<Object>(
+ Identity.INSTANCE,
NoOp.INSTANCE,
NoOp.INSTANCE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalProcedure(
- Constant.FALSE,
+ assertObjectsAreEqual(p,new ConditionalProcedure<Object>(
+ Identity.INSTANCE,
NoOp.INSTANCE,
NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalProcedure(
+ assertObjectsAreNotEqual(p,new ConditionalProcedure<Object>(
Constant.TRUE,
NoOp.INSTANCE,
NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalProcedure(
- Constant.TRUE,
- NoOp.INSTANCE,
- NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalProcedure(
- Constant.FALSE,
+ assertObjectsAreNotEqual(p,new ConditionalProcedure<Object>(
+ Identity.INSTANCE,
new RunCounter(),
NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalProcedure(
- Constant.FALSE,
+ assertObjectsAreNotEqual(p,new ConditionalProcedure<Object>(
+ Identity.INSTANCE,
NoOp.INSTANCE,
new RunCounter()));
- assertObjectsAreNotEqual(p,new ConditionalProcedure(
+ assertObjectsAreNotEqual(p, new ConditionalProcedure<Object>(
Constant.TRUE,
- NoOp.INSTANCE));
+ new RunCounter()));
assertTrue(!p.equals(null));
}
// Classes
// ------------------------------------------------------------------------
- static class RunCounter implements Procedure {
- public void run() {
+ static class RunCounter implements Procedure<Object> {
+ public void run(Object obj) {
count++;
}
public int count = 0;
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java
deleted file mode 100644
index be92f6e..0000000
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestConditionalUnaryProcedure.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.functor.core.composite;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
-import org.apache.commons.functor.core.Constant;
-import org.apache.commons.functor.core.Identity;
-import org.apache.commons.functor.core.NoOp;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-public class TestConditionalUnaryProcedure extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new ConditionalUnaryProcedure<Object>(
- Constant.TRUE,
- NoOp.INSTANCE,
- NoOp.INSTANCE);
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testRun() throws Exception {
- RunCounter left = new RunCounter();
- RunCounter right = new RunCounter();
- ConditionalUnaryProcedure<Object> p = new ConditionalUnaryProcedure<Object>(
- Identity.INSTANCE,
- left,
- right);
- assertEquals(0,left.count);
- assertEquals(0,right.count);
- p.run(Boolean.TRUE);
- assertEquals(1,left.count);
- assertEquals(0,right.count);
- p.run(Boolean.FALSE);
- assertEquals(1,left.count);
- assertEquals(1,right.count);
- p.run(Boolean.TRUE);
- assertEquals(2,left.count);
- assertEquals(1,right.count);
- }
-
- @Test
- public void testEquals() throws Exception {
- ConditionalUnaryProcedure<Object> p = new ConditionalUnaryProcedure<Object>(
- Identity.INSTANCE,
- NoOp.INSTANCE,
- NoOp.INSTANCE);
- assertEquals(p,p);
- assertObjectsAreEqual(p,new ConditionalUnaryProcedure<Object>(
- Identity.INSTANCE,
- NoOp.INSTANCE,
- NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure<Object>(
- Constant.TRUE,
- NoOp.INSTANCE,
- NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure<Object>(
- Identity.INSTANCE,
- new RunCounter(),
- NoOp.INSTANCE));
- assertObjectsAreNotEqual(p,new ConditionalUnaryProcedure<Object>(
- Identity.INSTANCE,
- NoOp.INSTANCE,
- new RunCounter()));
- assertObjectsAreNotEqual(p, new ConditionalUnaryProcedure<Object>(
- Constant.TRUE,
- new RunCounter()));
- assertTrue(!p.equals(null));
- }
-
- // Classes
- // ------------------------------------------------------------------------
-
- static class RunCounter implements UnaryProcedure<Object> {
- public void run(Object obj) {
- count++;
- }
- public int count = 0;
- }
-}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileNullaryProcedure.java
similarity index 76%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileProcedure.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileNullaryProcedure.java
index 6482c50..355c0e1 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestDoWhileNullaryProcedure.java
@@ -23,30 +23,30 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.adapter.BoundPredicate;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.functor.adapter.BoundNullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
import org.apache.commons.functor.core.collection.IsEmpty;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class TestDoWhileProcedure extends BaseFunctorTest {
+public class TestDoWhileNullaryProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new DoWhileProcedure(NoOp.INSTANCE, Constant.FALSE);
+ return new DoWhileNullaryProcedure(NoOp.INSTANCE, Constant.FALSE);
}
// Tests
// ------------------------------------------------------------------------
- public class ListRemoveFirstProcedure implements Procedure {
+ public class ListRemoveFirstProcedure implements NullaryProcedure {
protected List<Object> list;
@@ -75,9 +75,9 @@
public void testLoopWithAction() throws Exception {
List<Object> list=getList();
- Procedure action=new ListRemoveFirstProcedure(list);
- Predicate condition=new Not(new BoundPredicate(new IsEmpty<List<Object>>(), list));
- Procedure procedure=new DoWhileProcedure(action, condition);
+ NullaryProcedure action=new ListRemoveFirstProcedure(list);
+ NullaryPredicate condition=new NullaryNot(new BoundNullaryPredicate(new IsEmpty<List<Object>>(), list));
+ NullaryProcedure procedure=new DoWhileNullaryProcedure(action, condition);
assertTrue("The condition should be true before running the loop", condition.test());
assertFalse("The list should not be empty then", list.isEmpty());
@@ -87,14 +87,14 @@
list=getList();
action=new ListRemoveFirstProcedure(list);
- condition=new Predicate() {
+ condition=new NullaryPredicate() {
private int count=2;
public boolean test() {
return count-- > 0;
}
};
- procedure=new DoWhileProcedure(action, condition);
+ procedure=new DoWhileNullaryProcedure(action, condition);
procedure.run();
assertFalse("The list should not contain \"a\" anymore", list.contains("a"));
assertFalse("The list should not contain \"b\" anymore", list.contains("b"));
@@ -105,8 +105,8 @@
@Test
public void testLoopForNothing() {
List<Object> list=getList();
- Procedure action=new ListRemoveFirstProcedure(list);
- Procedure procedure=new DoWhileProcedure(action, Constant.FALSE);
+ NullaryProcedure action=new ListRemoveFirstProcedure(list);
+ NullaryProcedure procedure=new DoWhileNullaryProcedure(action, Constant.FALSE);
assertTrue("The list should contain 4 elements before runnning the loop", list.size()==4);
procedure.run();
assertTrue("The list should contain 3 elements after runnning the loop", list.size()==3);
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
index 7d34b90..e83fc22 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
@@ -17,7 +17,6 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -37,7 +36,7 @@
@Override
protected Object makeFunctor() {
- return new Not(Constant.TRUE);
+ return new Not<Object>(Constant.TRUE);
}
// Tests
@@ -45,19 +44,19 @@
@Test
public void testTest() throws Exception {
- Predicate truePred = new Not(Constant.FALSE);
- assertTrue(truePred.test());
- Predicate falsePred = new Not(Constant.TRUE);
- assertFalse(falsePred.test());
+ Predicate<Object> truePred = new Not<Object>(Constant.FALSE);
+ assertTrue(truePred.test(null));
+ assertTrue(truePred.test("xyzzy"));
+ assertTrue(truePred.test(new Integer(3)));
}
@Test
public void testEquals() throws Exception {
- Not p = new Not(Constant.TRUE);
+ Not<Object> p = new Not<Object>(Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new Not(Constant.TRUE));
+ assertObjectsAreEqual(p,new Not<Object>(Constant.TRUE));
assertObjectsAreEqual(p,Not.not(Constant.TRUE));
- assertObjectsAreNotEqual(p,new Not(Constant.FALSE));
+ assertObjectsAreNotEqual(p,new Not<Object>(Constant.FALSE));
assertObjectsAreNotEqual(p,Constant.TRUE);
assertTrue(!p.equals(null));
}
@@ -69,6 +68,6 @@
@Test
public void testNotNotNull() throws Exception {
- assertNotNull(Not.not(Constant.TRUE));
+ assertNotNull(Not.not(Constant.truePredicate()));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryAnd.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryAnd.java
new file mode 100644
index 0000000..3b614c6
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryAnd.java
@@ -0,0 +1,140 @@
+/*
+ * 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.functor.core.composite;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.core.Constant;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestNullaryAnd extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new NullaryAnd(Constant.TRUE, Constant.TRUE);
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testTrue() throws Exception {
+ assertTrue((new NullaryAnd()).test());
+ assertTrue((new NullaryAnd(Constant.TRUE)).test());
+ assertTrue((new NullaryAnd(Constant.TRUE,Constant.TRUE)).test());
+ assertTrue((new NullaryAnd(Constant.TRUE,Constant.TRUE,Constant.TRUE)).test());
+
+ NullaryAnd p = new NullaryAnd(Constant.TRUE);
+ assertTrue(p.test());
+ for (int i=0;i<10;i++) {
+ p.and(Constant.TRUE);
+ assertTrue(p.test());
+ }
+
+ NullaryAnd q = new NullaryAnd(Constant.TRUE);
+ assertTrue(q.test());
+ for (int i=0;i<10;i++) {
+ q.and(Constant.TRUE);
+ assertTrue(q.test());
+ }
+
+ NullaryAnd r = new NullaryAnd(p,q);
+ assertTrue(r.test());
+ }
+
+ @Test
+ public void testFalse() throws Exception {
+ assertTrue(!(new NullaryAnd(Constant.FALSE)).test());
+ assertTrue(!(new NullaryAnd(Constant.TRUE,Constant.FALSE)).test());
+ assertTrue(!(new NullaryAnd(Constant.TRUE,Constant.TRUE,Constant.FALSE)).test());
+
+ NullaryAnd p = new NullaryAnd(Constant.FALSE);
+ assertTrue(!p.test());
+ for (int i=0;i<10;i++) {
+ p.and(Constant.FALSE);
+ assertTrue(!p.test());
+ }
+
+ NullaryAnd q = new NullaryAnd(Constant.TRUE);
+ assertTrue(q.test());
+ for (int i=0;i<10;i++) {
+ q.and(Constant.TRUE);
+ assertTrue(q.test());
+ }
+
+ NullaryAnd r = new NullaryAnd(p,q);
+ assertTrue(!r.test());
+ }
+
+ @Test
+ public void testDuplicateAdd() throws Exception {
+ NullaryPredicate p = Constant.TRUE;
+ NullaryAnd q = new NullaryAnd(p,p);
+ assertTrue(q.test());
+ for (int i=0;i<10;i++) {
+ q.and(p);
+ assertTrue(q.test());
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ NullaryAnd p = new NullaryAnd();
+ assertEquals(p,p);
+ NullaryAnd q = new NullaryAnd();
+ assertObjectsAreEqual(p,q);
+
+ for (int i=0;i<3;i++) {
+ p.and(Constant.TRUE);
+ assertObjectsAreNotEqual(p,q);
+ q.and(Constant.truePredicate());
+ assertObjectsAreEqual(p,q);
+ p.and(new NullaryAnd(Constant.TRUE,Constant.FALSE));
+ assertObjectsAreNotEqual(p,q);
+ q.and(new NullaryAnd(Constant.TRUE,Constant.FALSE));
+ assertObjectsAreEqual(p,q);
+ }
+
+ assertObjectsAreNotEqual(p,Constant.TRUE);
+ Iterable<NullaryPredicate> iterable = Arrays.<NullaryPredicate>asList(
+ Constant.TRUE,
+ new NullaryAnd(Constant.TRUE, Constant.FALSE),
+ Constant.TRUE,
+ new NullaryAnd(Constant.TRUE, Constant.FALSE),
+ Constant.TRUE,
+ new NullaryAnd(Constant.TRUE, Constant.FALSE));
+ assertObjectsAreEqual(p,new NullaryAnd(iterable));
+
+ assertObjectsAreNotEqual(p,new NullaryAnd((Iterable<NullaryPredicate>)null));
+ assertObjectsAreNotEqual(p,new NullaryAnd((NullaryPredicate[])null));
+ assertObjectsAreNotEqual(p,new NullaryAnd((NullaryPredicate)null));
+
+ assertTrue(!p.equals(null));
+ }
+
+}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryNot.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryNot.java
similarity index 68%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryNot.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryNot.java
index e673b1b..dfda85c 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryNot.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryNot.java
@@ -17,26 +17,27 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.NullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-public class TestUnaryNot extends BaseFunctorTest {
+public class TestNullaryNot extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnaryNot<Object>(Constant.TRUE);
+ return new NullaryNot(Constant.TRUE);
}
// Tests
@@ -44,30 +45,30 @@
@Test
public void testTest() throws Exception {
- UnaryPredicate<Object> truePred = new UnaryNot<Object>(Constant.FALSE);
- assertTrue(truePred.test(null));
- assertTrue(truePred.test("xyzzy"));
- assertTrue(truePred.test(new Integer(3)));
+ NullaryPredicate truePred = new NullaryNot(Constant.FALSE);
+ assertTrue(truePred.test());
+ NullaryPredicate falsePred = new NullaryNot(Constant.TRUE);
+ assertFalse(falsePred.test());
}
@Test
public void testEquals() throws Exception {
- UnaryNot<Object> p = new UnaryNot<Object>(Constant.TRUE);
+ NullaryNot p = new NullaryNot(Constant.TRUE);
assertEquals(p,p);
- assertObjectsAreEqual(p,new UnaryNot<Object>(Constant.TRUE));
- assertObjectsAreEqual(p,UnaryNot.not(Constant.TRUE));
- assertObjectsAreNotEqual(p,new UnaryNot<Object>(Constant.FALSE));
+ assertObjectsAreEqual(p,new NullaryNot(Constant.TRUE));
+ assertObjectsAreEqual(p,NullaryNot.not(Constant.TRUE));
+ assertObjectsAreNotEqual(p,new NullaryNot(Constant.FALSE));
assertObjectsAreNotEqual(p,Constant.TRUE);
assertTrue(!p.equals(null));
}
@Test
public void testNotNull() throws Exception {
- assertNull(UnaryNot.not(null));
+ assertNull(NullaryNot.not(null));
}
@Test
public void testNotNotNull() throws Exception {
- assertNotNull(UnaryNot.not(Constant.truePredicate()));
+ assertNotNull(NullaryNot.not(Constant.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryOr.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryOr.java
new file mode 100644
index 0000000..4149d8a
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullaryOr.java
@@ -0,0 +1,154 @@
+/*
+ * 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.functor.core.composite;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.core.Constant;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public class TestNullaryOr extends BaseFunctorTest {
+
+ // Functor Testing Framework
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected Object makeFunctor() {
+ return new NullaryOr(Constant.FALSE, Constant.TRUE);
+ }
+
+ // Tests
+ // ------------------------------------------------------------------------
+
+ @Test
+ public void testConstructors() {
+ NullaryOr or = new NullaryOr(Constant.FALSE);
+ assertEquals(Boolean.FALSE, or.test());
+ NullaryOr or2 = new NullaryOr((Iterable<NullaryPredicate>)Arrays.asList((NullaryPredicate)Constant.truePredicate()));
+ assertEquals(Boolean.TRUE, or2.test());
+ NullaryOr or3 = new NullaryOr((NullaryPredicate)null);
+ assertEquals(Boolean.FALSE, or3.test());
+ NullaryOr or4 = new NullaryOr((Iterable<NullaryPredicate>)null);
+ assertEquals(Boolean.FALSE, or4.test());
+ }
+
+ @Test
+ public void testTrue() throws Exception {
+ assertTrue((new NullaryOr(Constant.TRUE)).test());
+ assertTrue((new NullaryOr(Constant.FALSE, Constant.TRUE)).test());
+ assertTrue((new NullaryOr(Constant.FALSE, Constant.FALSE, Constant.TRUE)).test());
+
+ NullaryOr p = new NullaryOr(Constant.TRUE);
+ assertTrue(p.test());
+ for (int i=0;i<10;i++) {
+ p.or(Constant.of(i%2==0));
+ assertTrue(p.test());
+ }
+
+ NullaryOr q = new NullaryOr(Constant.TRUE);
+ assertTrue(q.test());
+ for (int i=0;i<10;i++) {
+ q.or(Constant.of(i%2==0));
+ assertTrue(q.test());
+ }
+
+ NullaryOr r = new NullaryOr(p,q);
+ assertTrue(r.test());
+ }
+
+ @Test
+ public void testFalse() throws Exception {
+ assertFalse(new NullaryOr().test());
+ assertFalse(new NullaryOr(Constant.FALSE).test());
+ assertFalse(new NullaryOr(Constant.FALSE,Constant.FALSE).test());
+ assertFalse(new NullaryOr(Constant.FALSE,Constant.FALSE,Constant.FALSE).test());
+
+ NullaryOr p = new NullaryOr(Constant.FALSE);
+ assertFalse(p.test());
+ for (int i=0;i<10;i++) {
+ p.or(Constant.FALSE);
+ assertFalse(p.test());
+ }
+
+ NullaryOr q = new NullaryOr(Constant.FALSE);
+ assertFalse(q.test());
+ for (int i=0;i<10;i++) {
+ q.or(Constant.FALSE);
+ assertFalse(q.test());
+ }
+
+ NullaryOr r = new NullaryOr(p,q);
+ assertTrue(!r.test());
+ }
+
+ @Test
+ public void testDuplicateAdd() throws Exception {
+ NullaryPredicate p = Constant.TRUE;
+ NullaryOr q = new NullaryOr(p,p);
+ assertTrue(q.test());
+ for (int i=0;i<10;i++) {
+ q.or(p);
+ assertTrue(q.test());
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ NullaryOr p = new NullaryOr();
+ assertEquals(p,p);
+
+ NullaryOr q = new NullaryOr();
+ assertObjectsAreEqual(p,q);
+
+ NullaryAnd r = new NullaryAnd();
+ assertObjectsAreNotEqual(p,r);
+
+ for (int i=0;i<3;i++) {
+ p.or(Constant.TRUE);
+ assertObjectsAreNotEqual(p,q);
+ q.or(Constant.TRUE);
+ assertObjectsAreEqual(p,q);
+ r.and(Constant.TRUE);
+ assertObjectsAreNotEqual(p,r);
+
+ p.or(new NullaryOr(Constant.TRUE,Constant.FALSE));
+ assertObjectsAreNotEqual(p,q);
+ q.or(new NullaryOr(Constant.TRUE,Constant.FALSE));
+ assertObjectsAreEqual(p,q);
+ r.and(new NullaryOr(Constant.TRUE,Constant.FALSE));
+ assertObjectsAreNotEqual(p,r);
+ }
+
+ assertObjectsAreNotEqual(p,Constant.TRUE);
+
+ assertObjectsAreNotEqual(p,new NullaryOr((Iterable<NullaryPredicate>)null));
+ assertObjectsAreNotEqual(p,new NullaryOr((NullaryPredicate[])null));
+ assertObjectsAreNotEqual(p,new NullaryOr((NullaryPredicate)null));
+
+ assertTrue(!p.equals(null));
+ }
+
+}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullarySequence.java
similarity index 61%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestNullarySequence.java
index d3f6323..1e8594a 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNullarySequence.java
@@ -17,28 +17,27 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.NoOp;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1365329 $ $Date: 2012-07-24 19:34:23 -0300 (Tue, 24 Jul 2012) $
*/
-@SuppressWarnings("unchecked")
-public class TestUnarySequence extends BaseFunctorTest {
+public class TestNullarySequence extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new UnarySequence<Object>(new NoOp(),new NoOp());
+ return new NullarySequence(new NoOp(),new NoOp());
}
// Tests
@@ -46,77 +45,71 @@
@Test
public void testConstructors() throws Exception {
- UnarySequence<Object> seq1 = new UnarySequence<Object>((UnaryProcedure<? super Object>)null);
- UnarySequence<Object> seq2 = new UnarySequence<Object>();
+ NullarySequence seq1 = new NullarySequence((NullaryProcedure)null);
+ NullarySequence seq2 = new NullarySequence();
assertObjectsAreEqual(seq1, seq2);
RunCounter p1 = new RunCounter();
RunCounter p2 = new RunCounter();
- List<UnaryProcedure<? super Object>> iterable = new ArrayList<UnaryProcedure<? super Object>>();
+ List<NullaryProcedure> iterable = new ArrayList<NullaryProcedure>();
iterable.add(p1);
iterable.add(p2);
- UnarySequence<Object> seq3 = new UnarySequence<Object>(iterable);
- UnarySequence<Object> seq4 = new UnarySequence<Object>(p1, p2);
+ NullarySequence seq3 = new NullarySequence(iterable);
+ NullarySequence seq4 = new NullarySequence(p1, p2);
assertObjectsAreEqual(seq3, seq4);
- UnarySequence<Object> seq5 = new UnarySequence<Object>((Iterable<UnaryProcedure<? super Object>>)null);
- UnarySequence<Object> seq6 = new UnarySequence<Object>((UnaryProcedure<? super Object>[])null);
+ NullarySequence seq5 = new NullarySequence((Iterable<NullaryProcedure>)null);
+ NullarySequence seq6 = new NullarySequence((NullaryProcedure[])null);
assertObjectsAreEqual(seq5, seq6);
}
-
+
@Test
public void testRunZero() throws Exception {
- UnarySequence<String> seq = new UnarySequence<String>();
- seq.run(null);
- seq.run("xyzzy");
+ NullarySequence seq = new NullarySequence();
+ seq.run();
}
@Test
public void testRunOne() throws Exception {
RunCounter counter = new RunCounter();
- UnarySequence<String> seq = new UnarySequence<String>(counter);
+ NullarySequence seq = new NullarySequence(counter);
assertEquals(0,counter.count);
- seq.run(null);
+ seq.run();
assertEquals(1,counter.count);
- seq.run("xyzzy");
- assertEquals(2,counter.count);
}
@Test
public void testRunTwo() throws Exception {
RunCounter[] counter = { new RunCounter(), new RunCounter() };
- UnarySequence<String> seq = new UnarySequence<String>(counter[0],counter[1]);
+ NullarySequence seq = new NullarySequence(counter[0],counter[1]);
assertEquals(0,counter[0].count);
assertEquals(0,counter[1].count);
- seq.run(null);
+ seq.run();
assertEquals(1,counter[0].count);
assertEquals(1,counter[1].count);
- seq.run("xyzzy");
- assertEquals(2,counter[0].count);
- assertEquals(2,counter[1].count);
}
@Test
public void testThen() throws Exception {
List<RunCounter> list = new ArrayList<RunCounter>();
- UnarySequence<String> seq = new UnarySequence<String>();
- seq.run(null);
+ NullarySequence seq = new NullarySequence();
+ seq.run();
for (int i=0;i<10;i++) {
RunCounter counter = new RunCounter();
seq.then(counter);
list.add(counter);
- seq.run("xyzzy");
+ seq.run();
for (int j=0;j<list.size();j++) {
- assertEquals(list.size()-j,((list.get(j)).count));
+ assertEquals(list.size()-j,(((RunCounter)(list.get(j))).count));
}
}
}
@Test
public void testEquals() throws Exception {
- UnarySequence<?> p = new UnarySequence<Object>();
+ NullarySequence p = new NullarySequence();
assertEquals(p,p);
- UnarySequence<?> q = new UnarySequence<Object>();
+ NullarySequence q = new NullarySequence();
assertObjectsAreEqual(p,q);
for (int i=0;i<3;i++) {
@@ -124,21 +117,21 @@
assertObjectsAreNotEqual(p,q);
q.then(new NoOp());
assertObjectsAreEqual(p,q);
- p.then(new UnarySequence<Object>(new NoOp(),new NoOp()));
+ p.then(new NullarySequence(new NoOp(),new NoOp()));
assertObjectsAreNotEqual(p,q);
- q.then(new UnarySequence<Object>(new NoOp(),new NoOp()));
+ q.then(new NullarySequence(new NoOp(),new NoOp()));
assertObjectsAreEqual(p,q);
}
assertObjectsAreNotEqual(p,new NoOp());
- assertFalse(p.equals(null));
+ assertTrue(!p.equals(null));
}
// Classes
// ------------------------------------------------------------------------
- static class RunCounter implements UnaryProcedure<Object> {
- public void run(Object that) {
+ static class RunCounter implements NullaryProcedure {
+ public void run() {
count++;
}
public int count = 0;
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestOr.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestOr.java
index 4653aeb..6935ae9 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestOr.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestOr.java
@@ -17,11 +17,8 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.util.Arrays;
-
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.core.Constant;
@@ -30,6 +27,7 @@
/**
* @version $Revision$ $Date$
*/
+@SuppressWarnings("unchecked")
public class TestOr extends BaseFunctorTest {
// Functor Testing Framework
@@ -37,118 +35,104 @@
@Override
protected Object makeFunctor() {
- return new Or(Constant.FALSE, Constant.TRUE);
+ return new Or<Object>(Constant.FALSE,Constant.TRUE);
}
// Tests
// ------------------------------------------------------------------------
@Test
- public void testConstructors() {
- Or or = new Or(Constant.FALSE);
- assertEquals(Boolean.FALSE, or.test());
- Or or2 = new Or((Iterable<Predicate>)Arrays.asList((Predicate)Constant.truePredicate()));
- assertEquals(Boolean.TRUE, or2.test());
- Or or3 = new Or((Predicate)null);
- assertEquals(Boolean.FALSE, or3.test());
- Or or4 = new Or((Iterable<Predicate>)null);
- assertEquals(Boolean.FALSE, or4.test());
- }
-
- @Test
public void testTrue() throws Exception {
- assertTrue((new Or(Constant.TRUE)).test());
- assertTrue((new Or(Constant.FALSE, Constant.TRUE)).test());
- assertTrue((new Or(Constant.FALSE, Constant.FALSE, Constant.TRUE)).test());
+ assertTrue((new Or<Object>(Constant.TRUE)).test("xyzzy"));
+ assertTrue((new Or<Object>(Constant.FALSE,Constant.TRUE)).test("xyzzy"));
+ assertTrue((new Or<Object>(Constant.FALSE,Constant.FALSE,Constant.TRUE)).test("xyzzy"));
- Or p = new Or(Constant.TRUE);
- assertTrue(p.test());
+ Or<Object> p = new Or<Object>(Constant.TRUE);
+ assertTrue(p.test("xyzzy"));
for (int i=0;i<10;i++) {
p.or(Constant.of(i%2==0));
- assertTrue(p.test());
+ assertTrue(p.test("xyzzy"));
}
- Or q = new Or(Constant.TRUE);
- assertTrue(q.test());
+ Or<Object> q = new Or<Object>(Constant.TRUE);
+ assertTrue(q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.or(Constant.of(i%2==0));
- assertTrue(q.test());
+ assertTrue(q.test("xyzzy"));
}
- Or r = new Or(p,q);
- assertTrue(r.test());
+ Or<Object> r = new Or<Object>(p,q);
+ assertTrue(r.test("xyzzy"));
}
@Test
public void testFalse() throws Exception {
- assertFalse(new Or().test());
- assertFalse(new Or(Constant.FALSE).test());
- assertFalse(new Or(Constant.FALSE,Constant.FALSE).test());
- assertFalse(new Or(Constant.FALSE,Constant.FALSE,Constant.FALSE).test());
+ assertTrue(!(new Or<Object>()).test("xyzzy"));
+ assertTrue(!(new Or<Object>(Constant.FALSE)).test("xyzzy"));
+ assertTrue(!(new Or<Object>(Constant.FALSE,Constant.FALSE)).test("xyzzy"));
+ assertTrue(!(new Or<Object>(Constant.FALSE,Constant.FALSE,Constant.FALSE)).test("xyzzy"));
- Or p = new Or(Constant.FALSE);
- assertFalse(p.test());
+ Or<Object> p = new Or<Object>(Constant.FALSE);
+ assertTrue(!p.test("xyzzy"));
for (int i=0;i<10;i++) {
p.or(Constant.FALSE);
- assertFalse(p.test());
+ assertTrue(!p.test("xyzzy"));
}
- Or q = new Or(Constant.FALSE);
- assertFalse(q.test());
+ Or<Object> q = new Or<Object>(Constant.FALSE);
+ assertTrue(!q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.or(Constant.FALSE);
- assertFalse(q.test());
+ assertTrue(!q.test("xyzzy"));
}
- Or r = new Or(p,q);
- assertTrue(!r.test());
+ Or<Object> r = new Or<Object>(p,q);
+ assertTrue(!r.test("xyzzy"));
}
@Test
public void testDuplicateAdd() throws Exception {
- Predicate p = Constant.TRUE;
- Or q = new Or(p,p);
- assertTrue(q.test());
+ Predicate<Object> p = Constant.TRUE;
+ Or<Object> q = new Or<Object>(p,p);
+ assertTrue(q.test("xyzzy"));
for (int i=0;i<10;i++) {
q.or(p);
- assertTrue(q.test());
+ assertTrue(q.test("xyzzy"));
}
}
@Test
public void testEquals() throws Exception {
- Or p = new Or();
+ Or<Object> p = new Or<Object>();
assertEquals(p,p);
- Or q = new Or();
+ Or<Object> q = new Or<Object>();
assertObjectsAreEqual(p,q);
- And r = new And();
+ And<Object> r = new And<Object>();
assertObjectsAreNotEqual(p,r);
for (int i=0;i<3;i++) {
- p.or(Constant.TRUE);
+ p.or(Constant.truePredicate());
assertObjectsAreNotEqual(p,q);
- q.or(Constant.TRUE);
+ q.or(Constant.truePredicate());
assertObjectsAreEqual(p,q);
- r.and(Constant.TRUE);
+ r.and(Constant.truePredicate());
assertObjectsAreNotEqual(p,r);
- p.or(new Or(Constant.TRUE,Constant.FALSE));
+ p.or(new Or<Object>(Constant.truePredicate(),Constant.falsePredicate()));
assertObjectsAreNotEqual(p,q);
- q.or(new Or(Constant.TRUE,Constant.FALSE));
+ q.or(new Or<Object>(Constant.truePredicate(),Constant.falsePredicate()));
assertObjectsAreEqual(p,q);
- r.and(new Or(Constant.TRUE,Constant.FALSE));
+ r.and(new Or<Object>(Constant.truePredicate(),Constant.falsePredicate()));
assertObjectsAreNotEqual(p,r);
}
- assertObjectsAreNotEqual(p,Constant.TRUE);
-
- assertObjectsAreNotEqual(p,new Or((Iterable<Predicate>)null));
- assertObjectsAreNotEqual(p,new Or((Predicate[])null));
- assertObjectsAreNotEqual(p,new Or((Predicate)null));
-
- assertTrue(!p.equals(null));
+ assertObjectsAreNotEqual(p,Constant.truePredicate());
+ Or<Object> s = new Or<Object>();
+ s.or(Constant.truePredicate());
+ s.or(new Or<Object>(Constant.truePredicate(),Constant.falsePredicate()));
+ assertObjectsAreEqual(s, new Or<Object>(s.getPredicateList()));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestSequence.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestSequence.java
index 5ec8f9a..ccd6ba4 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestSequence.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestSequence.java
@@ -17,7 +17,7 @@
package org.apache.commons.functor.core.composite;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +30,7 @@
/**
* @version $Revision$ $Date$
*/
+@SuppressWarnings("unchecked")
public class TestSequence extends BaseFunctorTest {
// Functor Testing Framework
@@ -37,7 +38,7 @@
@Override
protected Object makeFunctor() {
- return new Sequence(new NoOp(),new NoOp());
+ return new Sequence<Object>(new NoOp(),new NoOp());
}
// Tests
@@ -45,71 +46,77 @@
@Test
public void testConstructors() throws Exception {
- Sequence seq1 = new Sequence((Procedure)null);
- Sequence seq2 = new Sequence();
+ Sequence<Object> seq1 = new Sequence<Object>((Procedure<? super Object>)null);
+ Sequence<Object> seq2 = new Sequence<Object>();
assertObjectsAreEqual(seq1, seq2);
RunCounter p1 = new RunCounter();
RunCounter p2 = new RunCounter();
- List<Procedure> iterable = new ArrayList<Procedure>();
+ List<Procedure<? super Object>> iterable = new ArrayList<Procedure<? super Object>>();
iterable.add(p1);
iterable.add(p2);
- Sequence seq3 = new Sequence(iterable);
- Sequence seq4 = new Sequence(p1, p2);
+ Sequence<Object> seq3 = new Sequence<Object>(iterable);
+ Sequence<Object> seq4 = new Sequence<Object>(p1, p2);
assertObjectsAreEqual(seq3, seq4);
- Sequence seq5 = new Sequence((Iterable<Procedure>)null);
- Sequence seq6 = new Sequence((Procedure[])null);
+ Sequence<Object> seq5 = new Sequence<Object>((Iterable<Procedure<? super Object>>)null);
+ Sequence<Object> seq6 = new Sequence<Object>((Procedure<? super Object>[])null);
assertObjectsAreEqual(seq5, seq6);
}
-
+
@Test
public void testRunZero() throws Exception {
- Sequence seq = new Sequence();
- seq.run();
+ Sequence<String> seq = new Sequence<String>();
+ seq.run(null);
+ seq.run("xyzzy");
}
@Test
public void testRunOne() throws Exception {
RunCounter counter = new RunCounter();
- Sequence seq = new Sequence(counter);
+ Sequence<String> seq = new Sequence<String>(counter);
assertEquals(0,counter.count);
- seq.run();
+ seq.run(null);
assertEquals(1,counter.count);
+ seq.run("xyzzy");
+ assertEquals(2,counter.count);
}
@Test
public void testRunTwo() throws Exception {
RunCounter[] counter = { new RunCounter(), new RunCounter() };
- Sequence seq = new Sequence(counter[0],counter[1]);
+ Sequence<String> seq = new Sequence<String>(counter[0],counter[1]);
assertEquals(0,counter[0].count);
assertEquals(0,counter[1].count);
- seq.run();
+ seq.run(null);
assertEquals(1,counter[0].count);
assertEquals(1,counter[1].count);
+ seq.run("xyzzy");
+ assertEquals(2,counter[0].count);
+ assertEquals(2,counter[1].count);
}
@Test
public void testThen() throws Exception {
List<RunCounter> list = new ArrayList<RunCounter>();
- Sequence seq = new Sequence();
- seq.run();
+ Sequence<String> seq = new Sequence<String>();
+ seq.run(null);
for (int i=0;i<10;i++) {
RunCounter counter = new RunCounter();
seq.then(counter);
list.add(counter);
- seq.run();
+ seq.run("xyzzy");
for (int j=0;j<list.size();j++) {
- assertEquals(list.size()-j,(((RunCounter)(list.get(j))).count));
+ assertEquals(list.size()-j,((list.get(j)).count));
}
}
}
@Test
public void testEquals() throws Exception {
- Sequence p = new Sequence();
+ Sequence<?> p = new Sequence<Object>();
assertEquals(p,p);
- Sequence q = new Sequence();
+ Sequence<?> q = new Sequence<Object>();
assertObjectsAreEqual(p,q);
for (int i=0;i<3;i++) {
@@ -117,21 +124,21 @@
assertObjectsAreNotEqual(p,q);
q.then(new NoOp());
assertObjectsAreEqual(p,q);
- p.then(new Sequence(new NoOp(),new NoOp()));
+ p.then(new Sequence<Object>(new NoOp(),new NoOp()));
assertObjectsAreNotEqual(p,q);
- q.then(new Sequence(new NoOp(),new NoOp()));
+ q.then(new Sequence<Object>(new NoOp(),new NoOp()));
assertObjectsAreEqual(p,q);
}
assertObjectsAreNotEqual(p,new NoOp());
- assertTrue(!p.equals(null));
+ assertFalse(p.equals(null));
}
// Classes
// ------------------------------------------------------------------------
- static class RunCounter implements Procedure {
- public void run() {
+ static class RunCounter implements Procedure<Object> {
+ public void run(Object that) {
count++;
}
public int count = 0;
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java
index 8034e04..44fb8a7 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java
@@ -23,7 +23,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.junit.Test;
@@ -48,7 +48,7 @@
}
}
- private static class AddOne implements UnaryFunction<Integer, Integer>, Serializable {
+ private static class AddOne implements Function<Integer, Integer>, Serializable {
private static final long serialVersionUID = 8759620198239402369L;
public Integer evaluate(Integer obj) {
return obj + 1;
@@ -82,7 +82,7 @@
return left-right;
}
};
- UnaryFunction<Integer, Integer> p = new UnaryFunction<Integer, Integer>() {
+ Function<Integer, Integer> p = new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return obj-1;
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java
index 8e2e85d..c662c6c 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java
@@ -23,7 +23,7 @@
import org.apache.commons.functor.BaseFunctorTest;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.junit.Test;
@@ -48,7 +48,7 @@
}
}
- private static class Total implements UnaryProcedure<Integer>, Serializable {
+ private static class Total implements Procedure<Integer>, Serializable {
private static final long serialVersionUID = 8532164308852418241L;
private int total = 0;
public void run(Integer obj) {
@@ -88,7 +88,7 @@
return left-right;
}
};
- UnaryProcedure<Integer> p = new UnaryProcedure<Integer>() {
+ Procedure<Integer> p = new Procedure<Integer>() {
public void run(Integer obj) {
// Do nothing
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
similarity index 71%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedFunction.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
index c39b002..92dcf1a 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
@@ -22,17 +22,17 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.NullaryFunction;
import org.apache.commons.functor.Function;
-import org.apache.commons.functor.UnaryFunction;
import org.junit.Test;
/**
- * Tests for TransformedFunction.
+ * Tests for TransformedNullaryFunction.
* @version $Revision: $ $Date: $
*/
-public class TestTransformedFunction extends BaseFunctorTest {
+public class TestTransformedNullaryFunction extends BaseFunctorTest {
- private static class One implements Function<Integer>, Serializable {
+ private static class One implements NullaryFunction<Integer>, Serializable {
private static final long serialVersionUID = 8160546546365936087L;
public Integer evaluate() {
return new Integer(1);
@@ -47,7 +47,7 @@
}
};
- private static class AddOne implements UnaryFunction<Integer, Integer>, Serializable {
+ private static class AddOne implements Function<Integer, Integer>, Serializable {
private static final long serialVersionUID = 2005155787293129721L;
public Integer evaluate(Integer obj) {
return obj + 1;
@@ -67,32 +67,32 @@
@Override
protected Object makeFunctor() throws Exception {
- return new TransformedFunction<Integer>(one, addOne);
+ return new TransformedNullaryFunction<Integer>(one, addOne);
}
@Test
public void testRun() {
- TransformedFunction<Integer> p = new TransformedFunction<Integer>(one, addOne);
+ TransformedNullaryFunction<Integer> p = new TransformedNullaryFunction<Integer>(one, addOne);
assertEquals(Integer.valueOf(2),p.evaluate());
}
@Test
public void testEquals() {
- TransformedFunction<Integer> t = new TransformedFunction<Integer>(one, addOne);
- Function<Integer> f = new Function<Integer>() {
+ TransformedNullaryFunction<Integer> t = new TransformedNullaryFunction<Integer>(one, addOne);
+ NullaryFunction<Integer> f = new NullaryFunction<Integer>() {
public Integer evaluate() {
return new Integer(2);
}
};
- UnaryFunction<Integer, Integer> p = new UnaryFunction<Integer, Integer>() {
+ Function<Integer, Integer> p = new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return obj + 2;
}
};
assertEquals(t,t);
- assertObjectsAreEqual(t,new TransformedFunction<Integer>(one, addOne));
- assertObjectsAreNotEqual(t,new TransformedFunction<Integer>(f, addOne));
- assertObjectsAreNotEqual(t,new TransformedFunction<Integer>(one, p));
+ assertObjectsAreEqual(t,new TransformedNullaryFunction<Integer>(one, addOne));
+ assertObjectsAreNotEqual(t,new TransformedNullaryFunction<Integer>(f, addOne));
+ assertObjectsAreNotEqual(t,new TransformedNullaryFunction<Integer>(one, p));
assertTrue(!t.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
similarity index 72%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedProcedure.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
index e88e870..8e5a58e 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
@@ -22,17 +22,17 @@
import java.io.Serializable;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Function;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.Procedure;
import org.junit.Test;
/**
- * Tests for TransformedProcedure.
+ * Tests for TransformedNullaryProcedure.
* @version $Revision: $ $Date: $
*/
-public class TestTransformedProcedure extends BaseFunctorTest{
+public class TestTransformedNullaryProcedure extends BaseFunctorTest{
- private static class One implements Function<Integer>, Serializable {
+ private static class One implements NullaryFunction<Integer>, Serializable {
private static final long serialVersionUID = 7385852113529459456L;
public Integer evaluate() {
return new Integer(1);
@@ -47,7 +47,7 @@
}
};
- private static class AggregatorProcedure implements UnaryProcedure<Integer>, Serializable {
+ private static class AggregatorProcedure implements Procedure<Integer>, Serializable {
private static final long serialVersionUID = -2744193737701268327L;
private int total = 0;
public void run(Integer obj) {
@@ -71,33 +71,33 @@
@Override
protected Object makeFunctor() throws Exception {
- return new TransformedProcedure(one, aggregator);
+ return new TransformedNullaryProcedure(one, aggregator);
}
@Test
public void testRun() {
- TransformedProcedure p = new TransformedProcedure(one, aggregator);
+ TransformedNullaryProcedure p = new TransformedNullaryProcedure(one, aggregator);
p.run();
assertEquals(1,aggregator.getTotal());
}
@Test
public void testEquals() {
- TransformedProcedure t = new TransformedProcedure(one, aggregator);
- Function<Integer> f = new Function<Integer>() {
+ TransformedNullaryProcedure t = new TransformedNullaryProcedure(one, aggregator);
+ NullaryFunction<Integer> f = new NullaryFunction<Integer>() {
public Integer evaluate() {
return new Integer(2);
}
};
- UnaryProcedure<Integer> p = new UnaryProcedure<Integer>() {
+ Procedure<Integer> p = new Procedure<Integer>() {
public void run(Integer obj) {
// Do nothing
}
};
assertEquals(t,t);
- assertObjectsAreEqual(t,new TransformedProcedure(one, aggregator));
- assertObjectsAreNotEqual(t,new TransformedProcedure(f, aggregator));
- assertObjectsAreNotEqual(t,new TransformedProcedure(one, p));
+ assertObjectsAreEqual(t,new TransformedNullaryProcedure(one, aggregator));
+ assertObjectsAreNotEqual(t,new TransformedNullaryProcedure(f, aggregator));
+ assertObjectsAreNotEqual(t,new TransformedNullaryProcedure(one, p));
assertTrue(!t.equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryAnd.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryAnd.java
deleted file mode 100644
index 542e665..0000000
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryAnd.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.functor.core.composite;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.core.Constant;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-@SuppressWarnings("unchecked")
-public class TestUnaryAnd extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new UnaryAnd<Object>(Constant.TRUE, Constant.TRUE);
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testTrue() throws Exception {
- assertTrue((new UnaryAnd<Object>()).test("xyzzy"));
- assertTrue((new UnaryAnd<Object>(Constant.TRUE)).test("xyzzy"));
- assertTrue((new UnaryAnd<Object>(Constant.TRUE,Constant.TRUE)).test("xyzzy"));
- assertTrue((new UnaryAnd<Object>(Constant.TRUE,Constant.TRUE,Constant.TRUE)).test("xyzzy"));
-
- UnaryAnd<Object> p = new UnaryAnd<Object>(Constant.TRUE);
- assertTrue(p.test("xyzzy"));
- for (int i=0;i<10;i++) {
- p.and(Constant.TRUE);
- assertTrue(p.test("xyzzy"));
- }
-
- UnaryAnd<Object> q = new UnaryAnd<Object>(Constant.TRUE);
- assertTrue(q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.and(Constant.TRUE);
- assertTrue(q.test("xyzzy"));
- }
-
- UnaryAnd<Object> r = new UnaryAnd<Object>(p,q);
- assertTrue(r.test("xyzzy"));
- }
-
- @Test
- public void testFalse() throws Exception {
- assertFalse(new UnaryAnd<Object>(Constant.FALSE).test("xyzzy"));
- assertFalse(new UnaryAnd<Object>(Constant.TRUE,Constant.FALSE).test("xyzzy"));
- assertFalse(new UnaryAnd<Object>(Constant.TRUE,Constant.TRUE,Constant.FALSE).test("xyzzy"));
-
- UnaryAnd<Object> p = new UnaryAnd<Object>(Constant.FALSE);
- assertTrue(!p.test("xyzzy"));
- for (int i=0;i<10;i++) {
- p.and(Constant.TRUE);
- assertTrue(!p.test("xyzzy"));
- }
-
- UnaryAnd<Object> q = new UnaryAnd<Object>(Constant.TRUE);
- assertTrue(q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.and(Constant.TRUE);
- assertTrue(q.test("xyzzy"));
- }
-
- UnaryAnd<Object> r = new UnaryAnd<Object>(p,q);
- assertTrue(!r.test("xyzzy"));
- }
-
- @Test
- public void testDuplicateAdd() throws Exception {
- UnaryPredicate<Object> p = Constant.TRUE;
- UnaryAnd<Object> q = new UnaryAnd<Object>(p,p);
- assertTrue(q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.and(p);
- assertTrue(q.test("xyzzy"));
- }
- }
-
- @SuppressWarnings("rawtypes")
- @Test
- public void testEquals() throws Exception {
- UnaryAnd<Object> p = new UnaryAnd<Object>();
- assertEquals(p,p);
- UnaryAnd<Object> q = new UnaryAnd<Object>();
- assertObjectsAreEqual(p,q);
-
- for (int i=0;i<3;i++) {
- p.and(Constant.truePredicate());
- assertObjectsAreNotEqual(p,q);
- q.and(Constant.truePredicate());
- assertObjectsAreEqual(p,q);
- p.and(new UnaryAnd<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreNotEqual(p,q);
- q.and(new UnaryAnd<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreEqual(p,q);
- }
-
- assertObjectsAreNotEqual(p,Constant.truePredicate());
- UnaryAnd<Object> r = new UnaryAnd<Object>();
- r.and(Constant.truePredicate());
- r.and(new UnaryAnd<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreEqual(r, new UnaryAnd<Object>(r.getUnaryPredicateList()));
- assertObjectsAreNotEqual(p, new UnaryAnd((Iterable<UnaryPredicate<Object>>)null));
- assertObjectsAreNotEqual(p, new UnaryAnd((UnaryPredicate<Object>[])null));
- assertObjectsAreNotEqual(p, new UnaryAnd((UnaryPredicate<Object>)null));
- assertTrue(!p.equals(null));
- }
-
-}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryOr.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryOr.java
deleted file mode 100644
index 4662025..0000000
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestUnaryOr.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.functor.core.composite;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.core.Constant;
-import org.junit.Test;
-
-/**
- * @version $Revision$ $Date$
- */
-@SuppressWarnings("unchecked")
-public class TestUnaryOr extends BaseFunctorTest {
-
- // Functor Testing Framework
- // ------------------------------------------------------------------------
-
- @Override
- protected Object makeFunctor() {
- return new UnaryOr<Object>(Constant.FALSE,Constant.TRUE);
- }
-
- // Tests
- // ------------------------------------------------------------------------
-
- @Test
- public void testTrue() throws Exception {
- assertTrue((new UnaryOr<Object>(Constant.TRUE)).test("xyzzy"));
- assertTrue((new UnaryOr<Object>(Constant.FALSE,Constant.TRUE)).test("xyzzy"));
- assertTrue((new UnaryOr<Object>(Constant.FALSE,Constant.FALSE,Constant.TRUE)).test("xyzzy"));
-
- UnaryOr<Object> p = new UnaryOr<Object>(Constant.TRUE);
- assertTrue(p.test("xyzzy"));
- for (int i=0;i<10;i++) {
- p.or(Constant.of(i%2==0));
- assertTrue(p.test("xyzzy"));
- }
-
- UnaryOr<Object> q = new UnaryOr<Object>(Constant.TRUE);
- assertTrue(q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.or(Constant.of(i%2==0));
- assertTrue(q.test("xyzzy"));
- }
-
- UnaryOr<Object> r = new UnaryOr<Object>(p,q);
- assertTrue(r.test("xyzzy"));
- }
-
- @Test
- public void testFalse() throws Exception {
- assertTrue(!(new UnaryOr<Object>()).test("xyzzy"));
- assertTrue(!(new UnaryOr<Object>(Constant.FALSE)).test("xyzzy"));
- assertTrue(!(new UnaryOr<Object>(Constant.FALSE,Constant.FALSE)).test("xyzzy"));
- assertTrue(!(new UnaryOr<Object>(Constant.FALSE,Constant.FALSE,Constant.FALSE)).test("xyzzy"));
-
- UnaryOr<Object> p = new UnaryOr<Object>(Constant.FALSE);
- assertTrue(!p.test("xyzzy"));
- for (int i=0;i<10;i++) {
- p.or(Constant.FALSE);
- assertTrue(!p.test("xyzzy"));
- }
-
- UnaryOr<Object> q = new UnaryOr<Object>(Constant.FALSE);
- assertTrue(!q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.or(Constant.FALSE);
- assertTrue(!q.test("xyzzy"));
- }
-
- UnaryOr<Object> r = new UnaryOr<Object>(p,q);
- assertTrue(!r.test("xyzzy"));
- }
-
- @Test
- public void testDuplicateAdd() throws Exception {
- UnaryPredicate<Object> p = Constant.TRUE;
- UnaryOr<Object> q = new UnaryOr<Object>(p,p);
- assertTrue(q.test("xyzzy"));
- for (int i=0;i<10;i++) {
- q.or(p);
- assertTrue(q.test("xyzzy"));
- }
- }
-
- @Test
- public void testEquals() throws Exception {
- UnaryOr<Object> p = new UnaryOr<Object>();
- assertEquals(p,p);
-
- UnaryOr<Object> q = new UnaryOr<Object>();
- assertObjectsAreEqual(p,q);
-
- UnaryAnd<Object> r = new UnaryAnd<Object>();
- assertObjectsAreNotEqual(p,r);
-
- for (int i=0;i<3;i++) {
- p.or(Constant.truePredicate());
- assertObjectsAreNotEqual(p,q);
- q.or(Constant.truePredicate());
- assertObjectsAreEqual(p,q);
- r.and(Constant.truePredicate());
- assertObjectsAreNotEqual(p,r);
-
- p.or(new UnaryOr<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreNotEqual(p,q);
- q.or(new UnaryOr<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreEqual(p,q);
- r.and(new UnaryOr<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreNotEqual(p,r);
- }
-
- assertObjectsAreNotEqual(p,Constant.truePredicate());
- UnaryOr<Object> s = new UnaryOr<Object>();
- s.or(Constant.truePredicate());
- s.or(new UnaryOr<Object>(Constant.truePredicate(),Constant.falsePredicate()));
- assertObjectsAreEqual(s, new UnaryOr<Object>(s.getUnaryPredicateList()));
- }
-
-}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoNullaryProcedure.java
similarity index 76%
rename from core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoProcedure.java
rename to core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoNullaryProcedure.java
index 373711a..8607d14 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestWhileDoNullaryProcedure.java
@@ -23,30 +23,30 @@
import java.util.List;
import org.apache.commons.functor.BaseFunctorTest;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.adapter.BoundPredicate;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.functor.adapter.BoundNullaryPredicate;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
import org.apache.commons.functor.core.collection.IsEmpty;
import org.junit.Test;
/**
- * @version $Revision$ $Date$
+ * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $
*/
-public class TestWhileDoProcedure extends BaseFunctorTest {
+public class TestWhileDoNullaryProcedure extends BaseFunctorTest {
// Functor Testing Framework
// ------------------------------------------------------------------------
@Override
protected Object makeFunctor() {
- return new WhileDoProcedure(Constant.FALSE, NoOp.INSTANCE);
+ return new WhileDoNullaryProcedure(Constant.FALSE, NoOp.INSTANCE);
}
// Tests
// ------------------------------------------------------------------------
- public class ListRemoveFirstProcedure implements Procedure {
+ public class ListRemoveFirstProcedure implements NullaryProcedure {
protected List<Object> list;
@@ -75,9 +75,9 @@
public void testLoopWithAction() throws Exception {
List<Object> list=getList();
- Procedure action=new ListRemoveFirstProcedure(list);
- Predicate condition=new Not(new BoundPredicate(new IsEmpty<List<Object>>(), list));
- Procedure procedure=new WhileDoProcedure(condition, action);
+ NullaryProcedure action=new ListRemoveFirstProcedure(list);
+ NullaryPredicate condition=new NullaryNot(new BoundNullaryPredicate(new IsEmpty<List<Object>>(), list));
+ NullaryProcedure procedure=new WhileDoNullaryProcedure(condition, action);
assertTrue("The condition should be true before running the loop", condition.test());
assertFalse("The list should not be empty then", list.isEmpty());
@@ -87,14 +87,14 @@
list=getList();
action=new ListRemoveFirstProcedure(list);
- condition=new Predicate() {
+ condition=new NullaryPredicate() {
private int count=2;
public boolean test() {
return count-- > 0;
}
};
- procedure=new WhileDoProcedure(condition, action);
+ procedure=new WhileDoNullaryProcedure(condition, action);
procedure.run();
assertFalse("The list should not contain \"a\" anymore", list.contains("a"));
assertFalse("The list should not contain \"b\" anymore", list.contains("b"));
@@ -105,8 +105,8 @@
@Test
public void testLoopForNothing() {
List<Object> list=getList();
- Procedure action=new ListRemoveFirstProcedure(list);
- Procedure procedure=new WhileDoProcedure(Constant.FALSE, action);
+ NullaryProcedure action=new ListRemoveFirstProcedure(list);
+ NullaryProcedure procedure=new WhileDoNullaryProcedure(Constant.FALSE, action);
assertTrue("The list should contain 4 elements before runnning the loop", list.size()==4);
procedure.run();
assertTrue("The list should contain 4 elements after runnning the loop", list.size()==4);
diff --git a/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java b/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
index 7cb64d3..6e67e78 100644
--- a/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
@@ -30,10 +30,10 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.Function;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
import org.apache.commons.functor.adapter.IgnoreLeftFunction;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.Identity;
@@ -550,8 +550,8 @@
*/
private abstract class UniversalFunctor implements
- Procedure, UnaryProcedure<Object>, BinaryProcedure<Object, Object>,
- Function<Object>, UnaryFunction<Object, Object>, BinaryFunction<Object, Object, Object> {
+ NullaryProcedure, Procedure<Object>, BinaryProcedure<Object, Object>,
+ NullaryFunction<Object>, Function<Object, Object>, BinaryFunction<Object, Object, Object> {
public abstract void run();
public void run(Object obj) {
diff --git a/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java b/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
index fa26afb..acb75d3 100644
--- a/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
@@ -26,12 +26,12 @@
import java.util.Random;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.collection.IsEmpty;
import org.apache.commons.functor.core.comparator.IsGreaterThanOrEqual;
import org.apache.commons.functor.core.comparator.IsLessThan;
-import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
+import org.apache.commons.functor.core.composite.ConditionalFunction;
import org.apache.commons.functor.generator.FilteredGenerator;
import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
import org.junit.Test;
@@ -306,7 +306,7 @@
*/
/*
- * Our quicksort method will invoke a UnaryFunction named
+ * Our quicksort method will invoke a Function named
* quicksort:
*/
@@ -337,7 +337,7 @@
* to transalate this description directly into code:
*/
- private UnaryFunction<Object, Object> quicksort = new ConditionalUnaryFunction<Object, Object>(
+ private Function<Object, Object> quicksort = new ConditionalFunction<Object, Object>(
/* if the list is empty... */
IsEmpty.instance(),
/* ...then return an empty list... */
@@ -386,10 +386,10 @@
* First, let's save ourselves some casting and error handling by
* definining some functor sub-types.
*
- * Let ListFunction be a UnaryFunction that operates on Lists:
+ * Let ListFunction be a Function that operates on Lists:
*/
- public abstract class ListFunction implements UnaryFunction<Object, Object> {
+ public abstract class ListFunction implements Function<Object, Object> {
public abstract Object evaluate(List<?> list);
public Object evaluate(Object obj) {
@@ -434,7 +434,7 @@
* Given a List, we need to be able to break it into its head:
*/
- private UnaryFunction<Object, Object> head = new ListFunction() {
+ private Function<Object, Object> head = new ListFunction() {
@Override
public Object evaluate(List<?> list) {
return list.get(0);
@@ -444,7 +444,7 @@
/*
* and its tail:
*/
- private UnaryFunction<Object, Object> tail = new ListFunction() {
+ private Function<Object, Object> tail = new ListFunction() {
@Override
public Object evaluate(List<?> list) {
return list.size() < 2 ?
diff --git a/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnFunctionImplementationSample.java b/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnFunctionImplementationSample.java
index 648747e..086d760 100644
--- a/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnFunctionImplementationSample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnFunctionImplementationSample.java
@@ -18,7 +18,7 @@
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.aggregator.ArrayListBackedAggregator;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -63,7 +63,7 @@
* This function returns the index of the first occurrence in the list of
* the given value.
*/
- static class OwnFunction implements UnaryFunction<List<Integer>, Integer> {
+ static class OwnFunction implements Function<List<Integer>, Integer> {
/** Value to find in the list. */
private int valueToFind;
diff --git a/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnListImplementationSample.java b/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnListImplementationSample.java
index 4166a17..d48fecf 100644
--- a/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnListImplementationSample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/aggregator/list/OwnListImplementationSample.java
@@ -22,7 +22,7 @@
import java.util.LinkedList;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.aggregator.AbstractListBackedAggregator;
import org.apache.commons.functor.aggregator.functions.IntegerSumAggregatorFunction;
import org.junit.Test;
@@ -51,15 +51,15 @@
* type of parameter stored.
*/
static class CustomListAggregator<T> extends AbstractListBackedAggregator<T> {
- public CustomListAggregator(UnaryFunction<List<T>, T> aggregationFunction) {
+ public CustomListAggregator(Function<List<T>, T> aggregationFunction) {
super(aggregationFunction);
}
- public CustomListAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval) {
+ public CustomListAggregator(Function<List<T>, T> aggregationFunction, long interval) {
super(aggregationFunction, interval);
}
- public CustomListAggregator(UnaryFunction<List<T>, T> aggregationFunction, long interval,
+ public CustomListAggregator(Function<List<T>, T> aggregationFunction, long interval,
boolean useSharedTimer) {
super(aggregationFunction, interval, useSharedTimer);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
index efa29ed..e941c8e 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.four;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Evaluates to the absolute Integer value of the Number-valued
@@ -24,7 +24,7 @@
*
* @version $Revision$ $Date$
*/
-public final class Abs implements UnaryFunction<Number, Integer> {
+public final class Abs implements Function<Number, Integer> {
public Integer evaluate(Number num) {
return new Integer(Math.abs(num.intValue()));
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/DataMunger.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/DataMunger.java
index b4ff63a..f2e0666 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/DataMunger.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/DataMunger.java
@@ -21,8 +21,8 @@
import java.io.Reader;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.adapter.BinaryFunctionUnaryFunction;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.adapter.BinaryFunctionFunction;
import org.apache.commons.functor.core.IsNull;
import org.apache.commons.functor.core.LeftIdentity;
import org.apache.commons.functor.core.RightIdentity;
@@ -81,14 +81,14 @@
}
/**
- * A UnaryFunction that returns the absolute value of the difference
+ * A Function that returns the absolute value of the difference
* between the Integers stored in the <i>col1</i> and <i>col2</i>th
* whitespace delimited columns of the input line (a String).
*/
- private static UnaryFunction<String, Integer> absSpread(final int col1, final int col2) {
+ private static Function<String, Integer> absSpread(final int col1, final int col2) {
return Composite.function(
Abs.instance(),
- new BinaryFunctionUnaryFunction<String, Number>(
+ new BinaryFunctionFunction<String, Number>(
Composite.function(
Subtract.instance(),
Composite.function(ToInteger.instance(),NthColumn.instance(col1)),
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/IsInteger.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/IsInteger.java
index 630f40d..feba0b1 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/IsInteger.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/IsInteger.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.four;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
/**
* Tests to true iff the input object can be converted to
@@ -24,7 +24,7 @@
*
* @version $Revision$ $Date$
*/
-public final class IsInteger implements UnaryPredicate<String> {
+public final class IsInteger implements Predicate<String> {
public boolean test(String obj) {
try {
ToInteger.instance().evaluate(obj);
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/NthColumn.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/NthColumn.java
index 96cd04a..598c6ec 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/NthColumn.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/NthColumn.java
@@ -18,7 +18,7 @@
import java.util.StringTokenizer;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Evaluates the input String to extrace the nth whitespace
@@ -26,7 +26,7 @@
*
* @version $Revision$ $Date$
*/
-public final class NthColumn implements UnaryFunction<String, String> {
+public final class NthColumn implements Function<String, String> {
public NthColumn(int n) {
this.n = n;
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
index 2e6ee7a..d840fff 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.four;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* Converts a String value to an Integer, throwing
@@ -27,7 +27,7 @@
*
* @version $Revision$ $Date$
*/
-public final class ToInteger implements UnaryFunction<String, Integer> {
+public final class ToInteger implements Function<String, Integer> {
public Integer evaluate(String str) {
StringBuffer buf = new StringBuffer();
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
index db6842f..06f9c73 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.LeftBoundFunction;
/**
@@ -31,7 +31,7 @@
return INSTANCE;
}
- public static UnaryFunction<Number, Number> to(int factor) {
+ public static Function<Number, Number> to(int factor) {
return LeftBoundFunction.bind(INSTANCE, factor);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
index 898c353..e0320a8 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.RightBoundFunction;
/**
@@ -32,7 +32,7 @@
return INSTANCE;
}
- public static UnaryFunction<Number, Number> by(int factor) {
+ public static Function<Number, Number> by(int factor) {
return RightBoundFunction.bind(INSTANCE, factor);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
index 0e17541..9e7858b 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.RightBoundFunction;
/**
@@ -31,7 +31,7 @@
return INSTANCE;
}
- public static UnaryFunction<Number, Number> by(int factor) {
+ public static Function<Number, Number> by(int factor) {
return RightBoundFunction.bind(instance(),factor);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
index b442427..8ccd6cd 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.LeftBoundFunction;
/**
@@ -32,7 +32,7 @@
return INSTANCE;
}
- public static UnaryFunction<Number, Number> by(int factor) {
+ public static Function<Number, Number> by(int factor) {
return LeftBoundFunction.bind(INSTANCE, factor);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Product.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Product.java
index 90f99b5..7064397 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Product.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Product.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
@@ -27,7 +27,7 @@
this(name,sku,ToMoney.from(Multiply.by(cost)));
}
- public Product(String name, String sku, UnaryFunction<? super Integer, Money> price) {
+ public Product(String name, String sku, Function<? super Integer, Money> price) {
this.name = name;
this.sku = sku;
this.priceFunction = price;
@@ -37,7 +37,7 @@
return name;
}
- public UnaryFunction<? super Integer, Money> getPriceFunction() {
+ public Function<? super Integer, Money> getPriceFunction() {
return priceFunction;
}
@@ -49,7 +49,7 @@
name = string;
}
- public void setPriceFunction(UnaryFunction<? super Integer, Money> function) {
+ public void setPriceFunction(Function<? super Integer, Money> function) {
priceFunction = function;
}
@@ -63,5 +63,5 @@
private String name;
private String sku;
- private UnaryFunction<? super Integer, Money> priceFunction;
+ private Function<? super Integer, Money> priceFunction;
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
index dceb717..865b22f 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
@@ -16,7 +16,7 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.adapter.LeftBoundFunction;
/**
@@ -31,7 +31,7 @@
return INSTANCE;
}
- public static UnaryFunction<Number, Number> from(int factor) {
+ public static Function<Number, Number> from(int factor) {
return LeftBoundFunction.bind(INSTANCE, factor);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
index 10e25b2..b56fa1e 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
@@ -18,13 +18,13 @@
import static org.junit.Assert.assertEquals;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.adapter.BinaryFunctionUnaryFunction;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.adapter.BinaryFunctionFunction;
import org.apache.commons.functor.core.Identity;
import org.apache.commons.functor.core.comparator.IsGreaterThan;
import org.apache.commons.functor.core.composite.Composite;
-import org.apache.commons.functor.core.composite.ConditionalUnaryFunction;
-import org.apache.commons.functor.core.composite.UnaryCompositeBinaryFunction;
+import org.apache.commons.functor.core.composite.ConditionalFunction;
+import org.apache.commons.functor.core.composite.CompositeBinaryFunction;
import org.junit.Test;
/**
@@ -121,7 +121,7 @@
"Banana",
"SKU-0002",
ToMoney.from(
- new ConditionalUnaryFunction<Integer, Number>(
+ new ConditionalFunction<Integer, Number>(
IsGreaterThan.instance(new Integer(3)),
Multiply.by(25),
Multiply.by(33))));
@@ -144,8 +144,8 @@
"Banana",
"SKU-0002",
ToMoney.from(
- new BinaryFunctionUnaryFunction<Integer, Number>(
- new UnaryCompositeBinaryFunction<Integer, Integer, Number>(
+ new BinaryFunctionFunction<Integer, Number>(
+ new CompositeBinaryFunction<Integer, Integer, Number>(
Add.instance(),
Composite.function(
Multiply.by(100),
@@ -182,7 +182,7 @@
"SKU-0003",
ToMoney.from(
Composite.function(Multiply.by(40),
- BinaryFunctionUnaryFunction.adapt(new UnaryCompositeBinaryFunction<Number, Number, Number>(Subtract.instance(),
+ BinaryFunctionFunction.adapt(new CompositeBinaryFunction<Number, Number, Number>(Subtract.instance(),
new Identity<Number>(),
Divide.by(3))))));
@@ -204,11 +204,11 @@
* and we haven't even considered things
* something like "buy 3, get 2 free", etc.
*
- * Perhaps a special UnaryFunction instance is in
+ * Perhaps a special Function instance is in
* order:
*/
- class BuyNGetMFree implements UnaryFunction<Number, Number> {
+ class BuyNGetMFree implements Function<Number, Number> {
public BuyNGetMFree(int n, int m, int costPerUnit) {
this.n = n;
this.m = m;
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/ToMoney.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/ToMoney.java
index cbd6aff..353b5bb 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/ToMoney.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/ToMoney.java
@@ -16,13 +16,13 @@
*/
package org.apache.commons.functor.example.kata.one;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
import org.apache.commons.functor.core.composite.Composite;
/**
* @version $Revision$ $Date$
*/
-public class ToMoney implements UnaryFunction<Number, Money> {
+public class ToMoney implements Function<Number, Money> {
public Money evaluate(Number cents) {
return new Money(cents.intValue());
@@ -32,7 +32,7 @@
return INSTANCE;
}
- public static <X> UnaryFunction<X, Money> from(UnaryFunction<? super X, ? extends Number> fn) {
+ public static <X> Function<X, Money> from(Function<? super X, ? extends Number> fn) {
return Composite.function(INSTANCE, fn);
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/two/EiffelStyleLoop.java b/core/src/test/java/org/apache/commons/functor/example/kata/two/EiffelStyleLoop.java
index 531d197..b42339c 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/two/EiffelStyleLoop.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/two/EiffelStyleLoop.java
@@ -16,9 +16,9 @@
*/
package org.apache.commons.functor.example.kata.two;
-import org.apache.commons.functor.Function;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.Constant;
import org.apache.commons.functor.core.NoOp;
@@ -26,13 +26,13 @@
* Supports an Eiffel style loop construct.
* <pre>
* new EiffelStyleLoop()
- * .from(new Procedure() { public void run() {} }) // init code
- * .invariant(new Predicate() { public boolean test() {} }) // invariants
- * .variant(new Procedure() { public Object evaluate() {} }) // diminishing comparable value
+ * .from(new NullaryProcedure() { public void run() {} }) // init code
+ * .invariant(new NullaryPredicate() { public boolean test() {} }) // invariants
+ * .variant(new NullaryProcedure() { public Object evaluate() {} }) // diminishing comparable value
* // or
- * // .variant(new Predicate() { public boolean test() {} }) // more invariants
- * .until(new Predicate() { public boolean test() {} }) // terminating condition
- * .loop(new Procedure() { public void run() {} }) // the acutal loop
+ * // .variant(new NullaryPredicate() { public boolean test() {} }) // more invariants
+ * .until(new NullaryPredicate() { public boolean test() {} }) // terminating condition
+ * .loop(new NullaryProcedure() { public void run() {} }) // the acutal loop
* .run();
* </pre>
*
@@ -41,25 +41,25 @@
*
* @version $Revision$ $Date$
*/
-public class EiffelStyleLoop implements Procedure {
- public EiffelStyleLoop from(Procedure procedure) {
+public class EiffelStyleLoop implements NullaryProcedure {
+ public EiffelStyleLoop from(NullaryProcedure procedure) {
from = procedure;
return this;
}
- public EiffelStyleLoop invariant(Predicate predicate) {
+ public EiffelStyleLoop invariant(NullaryPredicate predicate) {
invariant = predicate;
return this;
}
- public EiffelStyleLoop variant(Predicate predicate) {
+ public EiffelStyleLoop variant(NullaryPredicate predicate) {
variant = predicate;
return this;
}
@SuppressWarnings("unchecked")
- public EiffelStyleLoop variant(final Function<Object> function) {
- return variant(new Predicate() {
+ public EiffelStyleLoop variant(final NullaryFunction<Object> function) {
+ return variant(new NullaryPredicate() {
public boolean test() {
boolean result = true;
Comparable<Object> next = (Comparable<Object>)(function.evaluate());
@@ -73,12 +73,12 @@
});
}
- public EiffelStyleLoop until(Predicate predicate) {
+ public EiffelStyleLoop until(NullaryPredicate predicate) {
until = predicate;
return this;
}
- public EiffelStyleLoop loop(Procedure procedure) {
+ public EiffelStyleLoop loop(NullaryProcedure procedure) {
loop = procedure;
return this;
}
@@ -109,10 +109,10 @@
}
}
- private Procedure from = NoOp.instance();
- private Predicate invariant = Constant.truePredicate();
- private Predicate variant = Constant.truePredicate();
- private Predicate until = Constant.falsePredicate();
- private Procedure loop = NoOp.instance();
+ private NullaryProcedure from = NoOp.instance();
+ private NullaryPredicate invariant = Constant.truePredicate();
+ private NullaryPredicate variant = Constant.truePredicate();
+ private NullaryPredicate until = Constant.falsePredicate();
+ private NullaryProcedure loop = NoOp.instance();
}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java b/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
index 0a37d80..9e9f305 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
@@ -21,9 +21,9 @@
import java.util.Collections;
import java.util.List;
-import org.apache.commons.functor.Function;
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryFunction;
+import org.apache.commons.functor.NullaryPredicate;
+import org.apache.commons.functor.NullaryProcedure;
import org.apache.commons.functor.core.algorithm.RecursiveEvaluation;
import org.apache.commons.functor.core.algorithm.UntilDo;
import org.apache.commons.functor.generator.util.IntegerRange;
@@ -209,7 +209,7 @@
* // the result index is between
* // low (inclusive) and high (exclusive),
* // or high is 0 (the list is empty)
- * Predicate INV = new Predicate() {
+ * NullaryPredicate INV = new NullaryPredicate() {
* public boolean test() {
* return high == 0 ||
* (low <= result && result < high);
@@ -218,7 +218,7 @@
*
* is a valid invariant in our binary search, and that:
*
- * Predicate TERM = new Predicate() {
+ * NullaryPredicate TERM = new NullaryPredicate() {
* public boolean test() {
* return (high - low) <= 1;
* }
@@ -230,7 +230,7 @@
* closer together, without violating
* our invariant:
*
- * Procedure BODY = new Procedure() {
+ * NullaryProcedure BODY = new NullaryProcedure() {
* public void run() {
* int mid = (high + low) / 2;
* if (greaterThan(list,mid,seeking)) {
@@ -252,12 +252,12 @@
* Algorithms.untildo(BODY,TERM);
*
* Since we'll want to share state among the TERM and BODY,
- * let's declare a single interface for the TERM Predicate and
- * the BODY Procedure. We'll be calculating a result within
- * the loop, so let's add a Function implementation as well,
+ * let's declare a single interface for the TERM NullaryPredicate and
+ * the BODY NullaryProcedure. We'll be calculating a result within
+ * the loop, so let's add a NullaryFunction implementation as well,
* as a way of retrieving that result:
*/
- interface Loop extends Predicate, Procedure, Function<Object> {
+ interface Loop extends NullaryPredicate, NullaryProcedure, NullaryFunction<Object> {
/** The terminating condition. */
boolean test();
/** The loop body. */
@@ -341,32 +341,32 @@
seeking = aSeeking;
list = aList;
- from(new Procedure() {
+ from(new NullaryProcedure() {
public void run() {
low = 0;
high = list.size();
}
});
- invariant(new Predicate() {
+ invariant(new NullaryPredicate() {
public boolean test() {
return high == 0 || low < high;
}
});
- variant(new Function<Object>() {
+ variant(new NullaryFunction<Object>() {
public Object evaluate() {
return new Integer(high - low);
}
});
- until(new Predicate() {
+ until(new NullaryPredicate() {
public boolean test() {
return high - low <= 1;
}
});
- loop(new Procedure() {
+ loop(new NullaryProcedure() {
public void run() {
int mid = (high + low) / 2;
if (BaseBinaryChop.greaterThan(list,mid,seeking)) {
@@ -429,7 +429,7 @@
* We can use the Algorithms.recuse method
* to implement that as tail recursion.
*
- * Here the anonymous Function implemenation
+ * Here the anonymous NullaryFunction implemenation
* holds this itermediate state, rather than
* the VM's call stack.
*
@@ -441,7 +441,7 @@
public void testTailRecursive() {
chopTest(new BaseBinaryChop() {
public int find(final Integer seeking, final List<Integer> list) {
- return ((Number) new RecursiveEvaluation(new Function<Object>() {
+ return ((Number) new RecursiveEvaluation(new NullaryFunction<Object>() {
public Object evaluate() {
if (high - low > 1) {
int mid = (high + low) / 2;
@@ -510,14 +510,14 @@
/**
* We can do that using tail recursion as well.
*
- * Again, the anonymous Function implemenation
+ * Again, the anonymous NullaryFunction implemenation
* holds the "continuation" state.
*/
@Test
public void testTailRecursive2() {
chopTest(new BaseBinaryChop() {
public int find(final Integer seeking, final List<Integer> list) {
- return ((Number) new RecursiveEvaluation(new Function<Object>() {
+ return ((Number) new RecursiveEvaluation(new NullaryFunction<Object>() {
public Object evaluate() {
if (sublist.isEmpty()) {
return BaseBinaryChop.NEGATIVE_ONE;
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/Contains.java b/core/src/test/java/org/apache/commons/functor/example/lines/Contains.java
index ef6dc1d..a357485 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/Contains.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/Contains.java
@@ -16,13 +16,13 @@
*/
package org.apache.commons.functor.example.lines;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
/**
* @version $Revision$ $Date$
*/
-public class Contains<T> implements UnaryPredicate<T> {
+public class Contains<T> implements Predicate<T> {
public Contains(String str) {
this.str = str;
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/Count.java b/core/src/test/java/org/apache/commons/functor/example/lines/Count.java
index 0a25a19..a42a15a 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/Count.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/Count.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.functor.example.lines;
-import org.apache.commons.functor.Procedure;
+import org.apache.commons.functor.NullaryProcedure;
/**
* @version $Revision$ $Date$
*/
-public class Count implements Procedure {
+public class Count implements NullaryProcedure {
public void run() {
count++;
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java b/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java
index 008148e..1095e9d 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java
@@ -22,7 +22,7 @@
import java.io.FileReader;
import java.io.Reader;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.BaseGenerator;
/**
@@ -45,7 +45,7 @@
}
}
- public void run(UnaryProcedure<? super String> proc) {
+ public void run(Procedure<? super String> proc) {
try {
for (String line = in.readLine(); line != null; line = in.readLine()) {
proc.run(line);
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/StartsWith.java b/core/src/test/java/org/apache/commons/functor/example/lines/StartsWith.java
index a59d63c..d7e597b 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/StartsWith.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/StartsWith.java
@@ -16,13 +16,13 @@
*/
package org.apache.commons.functor.example.lines;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
/**
* @version $Revision$ $Date$
*/
-public class StartsWith<T> implements UnaryPredicate<T> {
+public class StartsWith<T> implements Predicate<T> {
public StartsWith(String prefix) {
this.prefix = prefix;
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java b/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
index 92062c5..6a4d09a 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
@@ -24,12 +24,12 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.apache.commons.functor.adapter.ProcedureUnaryProcedure;
+import org.apache.commons.functor.adapter.NullaryProcedureProcedure;
import org.apache.commons.functor.core.Offset;
import org.apache.commons.functor.core.algorithm.FoldLeft;
import org.apache.commons.functor.core.collection.Size;
-import org.apache.commons.functor.core.composite.UnaryAnd;
-import org.apache.commons.functor.core.composite.UnaryNot;
+import org.apache.commons.functor.core.composite.And;
+import org.apache.commons.functor.core.composite.Not;
import org.apache.commons.functor.generator.FilteredGenerator;
import org.apache.commons.functor.generator.TransformedGenerator;
@@ -78,14 +78,14 @@
Count count = new Count();
Lines
.from(reader)
- .run(ProcedureUnaryProcedure.adapt(count));
+ .run(NullaryProcedureProcedure.adapt(count));
assertEquals("Expected 16 lines",16,count.getCount());
}
public void testCountWordsExcludingComments() throws Exception {
Object result = new FoldLeft<Integer>(Sum.instance()).evaluate(new TransformedGenerator<String, Integer>(
- new FilteredGenerator<String>(Lines.from(reader), UnaryNot.not(new StartsWith<String>("#"))), WordCount
+ new FilteredGenerator<String>(Lines.from(reader), Not.not(new StartsWith<String>("#"))), WordCount
.instance()));
assertEquals("Expected 90 words",new Integer(90),result);
@@ -94,7 +94,7 @@
public void testCountCommentLines() throws Exception {
Count count = new Count();
new FilteredGenerator<String>(Lines.from(reader), new StartsWith<String>("#"))
- .run(ProcedureUnaryProcedure.<String>adapt(count));
+ .run(NullaryProcedureProcedure.<String>adapt(count));
assertEquals("Expected 6 lines",6,count.getCount());
}
@@ -107,7 +107,7 @@
@SuppressWarnings("unchecked")
public void testFindMatchingFromTail() throws Exception {
- Collection<String> matches = new FilteredGenerator<String>(Lines.from(reader), new UnaryAnd<String>(new Offset(
+ Collection<String> matches = new FilteredGenerator<String>(Lines.from(reader), new And<String>(new Offset(
8), new Contains<String>("lo"))).toCollection();
assertEquals("Expected 2 lines",2,matches.size());
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/WordCount.java b/core/src/test/java/org/apache/commons/functor/example/lines/WordCount.java
index 51938c7..bcd681b 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/WordCount.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/WordCount.java
@@ -18,12 +18,12 @@
import java.util.StringTokenizer;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* @version $Revision$ $Date$
*/
-public class WordCount implements UnaryFunction<String, Integer> {
+public class WordCount implements Function<String, Integer> {
public Integer evaluate(String obj) {
return new StringTokenizer(obj).countTokens();
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java b/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
index a1c7d18..088ec81 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
@@ -23,7 +23,7 @@
import org.apache.commons.functor.BinaryProcedure;
import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction;
import org.apache.commons.functor.core.algorithm.GeneratorContains;
-import org.apache.commons.functor.core.composite.UnaryNot;
+import org.apache.commons.functor.core.composite.Not;
import org.apache.commons.functor.generator.IteratorToGeneratorAdapter;
/**
@@ -50,7 +50,7 @@
Map<K,V> dest = a;
Map<K,V> src = b;
- if (GeneratorContains.instance().test(IteratorToGeneratorAdapter.adapt(src.keySet().iterator()),UnaryNot.not(new ContainsKey(dest)))) {
+ if (GeneratorContains.instance().test(IteratorToGeneratorAdapter.adapt(src.keySet().iterator()),Not.not(new ContainsKey(dest)))) {
throw new IllegalArgumentException();
} else {
dest.putAll(src);
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java b/core/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
index c338a78..50cfd53 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java
@@ -23,9 +23,9 @@
import org.apache.commons.functor.BinaryFunction;
import org.apache.commons.functor.BinaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.Procedure;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
/**
* @version $Revision$ $Date$
@@ -101,7 +101,7 @@
// protected
- protected void setOnClear(UnaryProcedure<Map<K, V>> procedure) {
+ protected void setOnClear(Procedure<Map<K, V>> procedure) {
onclear = procedure;
}
@@ -161,19 +161,19 @@
private BinaryFunction<Map<K, V>, K, V> onremove = DEFAULT_ON_REMOVE;
- protected UnaryProcedure<Map<K, V>> DEFAULT_ON_CLEAR = new UnaryProcedure<Map<K, V>>() {
+ protected Procedure<Map<K, V>> DEFAULT_ON_CLEAR = new Procedure<Map<K, V>>() {
public void run(Map<K, V> map) {
map.clear();
}
};
- private UnaryProcedure<Map<K, V>> onclear = DEFAULT_ON_CLEAR;
+ private Procedure<Map<K, V>> onclear = DEFAULT_ON_CLEAR;
private Map<K, V> map = null;
// inner classes
- protected static class ContainsKey implements UnaryPredicate<Object> {
+ protected static class ContainsKey implements Predicate<Object> {
ContainsKey(Map<?, ?> map) {
this.map = map;
}
@@ -185,7 +185,7 @@
private Map<?, ?> map = null;
}
- protected static class Throw<K, V> implements Procedure, UnaryProcedure<Map<K, V>>, BinaryProcedure<K, V> {
+ protected static class Throw<K, V> implements NullaryProcedure, Procedure<Map<K, V>>, BinaryProcedure<K, V> {
Throw(RuntimeException e) {
this.klass = e.getClass();
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/LazyMap.java b/core/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
index 3f80020..7fd147c 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/LazyMap.java
@@ -19,13 +19,13 @@
import java.util.Map;
import org.apache.commons.functor.BinaryFunction;
-import org.apache.commons.functor.UnaryFunction;
+import org.apache.commons.functor.Function;
/**
* @version $Revision$ $Date$
*/
public class LazyMap<K, V> extends FunctoredMap<K, V> {
- public LazyMap(Map<K, V> map, final UnaryFunction<K, V> factory) {
+ public LazyMap(Map<K, V> map, final Function<K, V> factory) {
super(map);
setOnGet(new BinaryFunction<Map<K,V>, K, V>() {
public V evaluate(Map<K, V> map, K key) {
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java b/core/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
index 4179623..c794c72 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/PredicatedMap.java
@@ -22,7 +22,7 @@
import org.apache.commons.functor.BinaryPredicate;
import org.apache.commons.functor.BinaryProcedure;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.adapter.BinaryProcedureBinaryFunction;
import org.apache.commons.functor.core.composite.ConditionalBinaryFunction;
@@ -30,7 +30,7 @@
* @version $Revision$ $Date$
*/
public class PredicatedMap<K, V> extends FunctoredMap<K, V> {
- public PredicatedMap(Map<K, V> map, final UnaryPredicate<K> keyPredicate, final UnaryPredicate<V> valuePredicate) {
+ public PredicatedMap(Map<K, V> map, final Predicate<K> keyPredicate, final Predicate<V> valuePredicate) {
super(map);
setOnPut(new ConditionalBinaryFunction<Map<K,V>, Object[], V>(
new BinaryPredicate<Map<K, V>, Object[]>() {
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
index e7cc2d6..732d3d1 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
@@ -24,7 +24,7 @@
import java.util.LinkedList;
import java.util.List;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.util.CollectionTransformer;
import org.junit.After;
import org.junit.Before;
@@ -44,7 +44,7 @@
@Before
public void setUp() throws Exception {
simpleGenerator = new BaseGenerator<Integer>() {
- public void run(UnaryProcedure<? super Integer> proc) {
+ public void run(Procedure<? super Integer> proc) {
for (int i=0;i<5;i++) {
proc.run(new Integer(i));
if (isStopped()) {
@@ -86,7 +86,7 @@
@Test
public void testSimpleGenerator() {
final StringBuffer result = new StringBuffer();
- simpleGenerator.run(new UnaryProcedure<Integer>() {
+ simpleGenerator.run(new Procedure<Integer>() {
public void run(Integer obj) {
result.append(obj);
}
@@ -98,7 +98,7 @@
@Test
public void testStop() {
final StringBuffer result = new StringBuffer();
- simpleGenerator.run(new UnaryProcedure<Integer>() {
+ simpleGenerator.run(new Procedure<Integer>() {
int i=0;
public void run(Integer obj) {
result.append(obj);
@@ -115,10 +115,10 @@
public void testWrappingGenerator() {
final StringBuffer result = new StringBuffer();
final Generator<Integer> gen = new BaseGenerator<Integer>(simpleGenerator) {
- public void run(final UnaryProcedure<? super Integer> proc) {
+ public void run(final Procedure<? super Integer> proc) {
Generator<Integer> wrapped = (Generator<Integer>)getWrappedGenerator();
assertSame(simpleGenerator, wrapped);
- wrapped.run(new UnaryProcedure<Integer>() {
+ wrapped.run(new Procedure<Integer>() {
public void run(Integer obj) {
proc.run(new Integer(obj.intValue() + 1));
}
@@ -126,7 +126,7 @@
}
};
- gen.run(new UnaryProcedure<Integer>() {
+ gen.run(new Procedure<Integer>() {
public void run(Integer obj) {
result.append(obj);
}
@@ -136,7 +136,7 @@
// try to stop the wrapped generator
final StringBuffer result2 = new StringBuffer();
- gen.run(new UnaryProcedure<Integer>() {
+ gen.run(new Procedure<Integer>() {
int i=0;
public void run(Integer obj) {
result2.append(obj);
@@ -180,14 +180,14 @@
private List<Integer> listWithDuplicates = null;
@SuppressWarnings("unused")
private int sum = 0;
-// private UnaryPredicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
-// private UnaryPredicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
-// private UnaryPredicate isEven = new UnaryPredicate() {
+// private Predicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
+// private Predicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
+// private Predicate isEven = new Predicate() {
// public boolean test(Object obj) {
// return ((Number) obj).intValue() % 2 == 0;
// }
// };
-// private UnaryPredicate isOdd = new UnaryPredicate() {
+// private Predicate isOdd = new Predicate() {
// public boolean test(Object obj) {
// return ((Number) obj).intValue() % 2 != 0;
// }
@@ -196,7 +196,7 @@
// Classes
// ------------------------------------------------------------------------
- static class Summer implements UnaryProcedure<Number> {
+ static class Summer implements Procedure<Number> {
public void run(Number that) {
sum += (that).intValue();
}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
index a049e01..4ba2d14 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
@@ -23,8 +23,8 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -54,7 +54,7 @@
// ------------------------------------------------------------------------
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicate() {
+ public void testConstructorProhibitsNullPredicate() {
new FilteredGenerator<Integer>(filteredGenerator, null);
}
@@ -64,7 +64,7 @@
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicateOrNullWrappedGenerator() {
+ public void testConstructorProhibitsNullPredicateOrNullWrappedGenerator() {
new FilteredGenerator<Integer>(null, null);
}
@@ -76,7 +76,7 @@
assertTrue(!filteredGenerator.equals((FilteredGenerator<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new FilteredGenerator<Integer>(
- new IntegerRange(1, 10), new UnaryPredicate<Integer>() {
+ new IntegerRange(1, 10), new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 == 0;
}
@@ -97,7 +97,7 @@
@Test
public void testGenerate() {
final List<Integer> evenNumbers = new ArrayList<Integer>();
- filteredGenerator.run(new UnaryProcedure<Integer>() {
+ filteredGenerator.run(new Procedure<Integer>() {
public void run(Integer obj) {
evenNumbers.add(obj);
}
@@ -111,7 +111,7 @@
// Attributes
// ------------------------------------------------------------------------
private Generator<Integer> wrappedGenerator = null;
- private UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>()
+ private Predicate<Integer> isEven = new Predicate<Integer>()
{
public boolean test( Integer obj ) {
return obj % 2 == 0;
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java b/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
index ce6141c..8576343 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
@@ -19,7 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -72,7 +72,7 @@
Generator<Integer> aGenerateWithADifferentPredicate = new GenerateUntil<Integer>(
new IntegerRange(1, 10),
- new UnaryPredicate<Integer>() {
+ new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj > FIVE;
}
@@ -94,7 +94,7 @@
private static final Integer FIVE = new Integer(5);
private Generator<Integer> wrappedGenerator = null;
- private UnaryPredicate<Integer> isMoreThanFive = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isMoreThanFive = new Predicate<Integer>() {
public boolean test( Integer obj ) {
return obj > FIVE;
}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java b/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
index 14c3651..b1e14fb 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
@@ -19,7 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.apache.commons.functor.UnaryPredicate;
+import org.apache.commons.functor.Predicate;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -49,7 +49,7 @@
// ------------------------------------------------------------------------
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicate() {
+ public void testConstructorProhibitsNullPredicate() {
new GenerateWhile<Integer>(generateWhile, null);
}
@@ -59,7 +59,7 @@
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicateOrNullWrappedGenerator() {
+ public void testConstructorProhibitsNullPredicateOrNullWrappedGenerator() {
new GenerateWhile<Integer>(null, null);
}
@@ -71,7 +71,7 @@
assertTrue(!generateWhile.equals((GenerateWhile<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new GenerateWhile<Integer>(
- new IntegerRange(1, 10), new UnaryPredicate<Integer>() {
+ new IntegerRange(1, 10), new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj < FIVE;
}
@@ -94,7 +94,7 @@
private static final Integer FIVE = new Integer(5);
private Generator<Integer> wrappedGenerator = null;
- private UnaryPredicate<Integer> isLessThanFive = new UnaryPredicate<Integer>()
+ private Predicate<Integer> isLessThanFive = new Predicate<Integer>()
{
public boolean test( Integer obj ) {
return obj < FIVE;
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
index 9ff36f6..6887617 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
@@ -20,8 +20,8 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.functor.UnaryFunction;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Function;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -56,12 +56,12 @@
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryFunction() {
+ public void testConstructorProhibitsNullFunction() {
new TransformedGenerator<Integer, Integer>(wrappedGenerator, null);
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullWrappedGeneratorOrNullUnaryFunction() {
+ public void testConstructorProhibitsNullWrappedGeneratorOrNullFunction() {
new TransformedGenerator<Integer, Integer>(null, null);
}
@@ -74,7 +74,7 @@
assertTrue(!sumsTwoGenerator.equals((TransformedGenerator<Integer, Integer>)null));
TransformedGenerator<Integer, Integer> aGenerateWithADifferentFunction =
- new TransformedGenerator<Integer, Integer>(wrappedGenerator, new UnaryFunction<Integer, Integer>() {
+ new TransformedGenerator<Integer, Integer>(wrappedGenerator, new Function<Integer, Integer>() {
public Integer evaluate( Integer obj ) {
return obj;
}
@@ -95,7 +95,7 @@
@Test
public void testGenerate() {
final List<Integer> doubledValues = new ArrayList<Integer>();
- sumsTwoGenerator.run(new UnaryProcedure<Integer>() {
+ sumsTwoGenerator.run(new Procedure<Integer>() {
public void run( Integer obj ) {
doubledValues.add(obj);
}
@@ -112,7 +112,7 @@
private static final Integer TWO = new Integer(2);
private Generator<Integer> wrappedGenerator = null;
- private UnaryFunction<Integer, Integer> sumsTwo = new UnaryFunction<Integer, Integer>() {
+ private Function<Integer, Integer> sumsTwo = new Function<Integer, Integer>() {
public Integer evaluate( Integer obj ) {
return obj += TWO;
}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java b/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
index fca00de..bc0bb57 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
@@ -23,8 +23,8 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -54,7 +54,7 @@
// ------------------------------------------------------------------------
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicate() {
+ public void testConstructorProhibitsNullPredicate() {
new UntilGenerate<Integer>(null, untilGenerate);
}
@@ -64,7 +64,7 @@
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicateOrNullWrappedGenerator() {
+ public void testConstructorProhibitsNullPredicateOrNullWrappedGenerator() {
new UntilGenerate<Integer>(null, null);
}
@@ -76,7 +76,7 @@
assertTrue(!untilGenerate.equals((UntilGenerate<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new UntilGenerate<Integer>(
- new UnaryPredicate<Integer>() {
+ new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj < FIVE;
}
@@ -96,7 +96,7 @@
@Test
public void testGenerate() {
final List<Integer> numbersGreaterThanFive = new ArrayList<Integer>();
- untilGenerate.run(new UnaryProcedure<Integer>() {
+ untilGenerate.run(new Procedure<Integer>() {
public void run( Integer obj ) {
numbersGreaterThanFive.add(obj);
}
@@ -112,7 +112,7 @@
private static final Integer FIVE = new Integer(5);
private Generator<Integer> wrappedGenerator = null;
- private UnaryPredicate<Integer> isLessThanFive = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isLessThanFive = new Predicate<Integer>() {
public boolean test( Integer obj ) {
return obj < FIVE;
}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java b/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
index 5db5884..d83267b 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
@@ -23,8 +23,8 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.functor.UnaryPredicate;
-import org.apache.commons.functor.UnaryProcedure;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
import org.apache.commons.functor.generator.util.IntegerRange;
import org.junit.After;
import org.junit.Before;
@@ -53,7 +53,7 @@
// ------------------------------------------------------------------------
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicate() {
+ public void testConstructorProhibitsNullPredicate() {
new WhileGenerate<Integer>(null, whileGenerate);
}
@@ -63,7 +63,7 @@
}
@Test(expected=NullPointerException.class)
- public void testConstructorProhibitsNullUnaryPredicateOrNullWrappedGenerator() {
+ public void testConstructorProhibitsNullPredicateOrNullWrappedGenerator() {
new WhileGenerate<Integer>(null, null);
}
@@ -75,7 +75,7 @@
assertTrue(!whileGenerate.equals((WhileGenerate<Integer>)null));
Generator<Integer> aGenerateWithADifferentPredicate = new WhileGenerate<Integer>(
- new UnaryPredicate<Integer>() {
+ new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj < FIVE;
}
@@ -95,7 +95,7 @@
@Test
public void testGenerate() {
final List<Integer> numbersMinorThanFive = new ArrayList<Integer>();
- whileGenerate.run(new UnaryProcedure<Integer>() {
+ whileGenerate.run(new Procedure<Integer>() {
public void run( Integer obj ) {
numbersMinorThanFive.add(obj);
}
@@ -111,7 +111,7 @@
private static final Integer FIVE = new Integer(5);
private Generator<Integer> wrappedGenerator = null;
- private UnaryPredicate<Integer> isLessThanFive = new UnaryPredicate<Integer>() {
+ private Predicate<Integer> isLessThanFive = new Predicate<Integer>() {
public boolean test( Integer obj ) {
return obj < FIVE;
}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bf041bd..c654291 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -23,6 +23,9 @@
</properties>
<body>
<release version="1.0" date="2012-??-??" description="First release.">
+ <action issue="FUNCTOR-24" dev="kinow">
+ Change default arity of Function, Procedure and Predicate
+ </action>
<action issue="FUNCTOR-27" dev="kinow">
Add static Limit#of method to create new Limit's.
</action>
diff --git a/src/site/xdoc/aggregator.xml b/src/site/xdoc/aggregator.xml
index e1102e9..9bf05d3 100644
--- a/src/site/xdoc/aggregator.xml
+++ b/src/site/xdoc/aggregator.xml
@@ -175,8 +175,7 @@
this.agg = aggregator;
}
- @Override
- public void onTimer(AbstractTimedAggregator<Double> aggregator) {
+ public void onTimer(AbstractTimedAggregator<Double> aggregator, Double evaluation) {
double aggregated = aggregator.evaluate();
/* log the value etc. */
}
@@ -242,8 +241,7 @@
this.agg = aggregator;
}
- @Override
- public void onTimer(AbstractTimedAggregator<Double> aggregator) {
+ public void onTimer(AbstractTimedAggregator<Double> aggregator, Double evaluation) {
double aggregated = aggregator.evaluate();
/* log the value etc. */
}
@@ -291,7 +289,7 @@
<p>
For the list-based aggregators, use an instance of
<a href="apidocs/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.html">AbstractListBackedAggregator</a>
- and pass in an instance of <a href="apidocs/org/apache/commons/functor/UnaryFunction.html">UnaryFunction</a>
+ and pass in an instance of <a href="apidocs/org/apache/commons/functor/Function.html">Function</a>
which accepts a <code>List</code> and returns a single object.
</p>
<p>
@@ -308,13 +306,13 @@
The naming convention is that if the function takes 2
parameters (i.e. it is an instance of <a href="apidocs/org/apache/commons/functor/BinaryFunction.html">BinaryFunction</a> then the
name of the class in this package will contain <code>BinaryFunction</code>, otherwise, if it is an instance
- of <a href="apidocs/org/apache/commons/functor/UnaryFunction.html">UnaryFunction</a> then the
+ of <a href="apidocs/org/apache/commons/functor/Function.html">Function</a> then the
name will only contain <code>Function</code>.
</p>
<p>
The reason behind it is that instances of <code>BinaryFunction</code> can be used with
<a href="apidocs/org/apache/commons/functor/aggregator/AbstractNoStoreAggregator.html">AbstractNoStoreAggregator</a>
- whereas the instances of <code>UnaryFunction</code> can be used
+ whereas the instances of <code>Function</code> can be used
with <a href="apidocs/org/apache/commons/functor/aggregator/AbstractTimedAggregator.html">AbstractTimedAggregator</a>.
</p>
</section>
diff --git a/src/site/xdoc/examples.xml b/src/site/xdoc/examples.xml
index 436e41f..f73a7c6 100644
--- a/src/site/xdoc/examples.xml
+++ b/src/site/xdoc/examples.xml
@@ -44,7 +44,7 @@
<source>
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
-UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 == 0;
}
@@ -67,7 +67,7 @@
<source>
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
-UnaryFunction<Integer, Integer> doubler = new UnaryFunction<Integer, Integer>() {
+Function<Integer, Integer> doubler = new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return obj * 2;
}
@@ -90,7 +90,7 @@
<source>
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
-UnaryProcedure<Integer> print = new UnaryProcedure<Integer>() {
+Procedure<Integer> print = new Procedure<Integer>() {
public void run(Integer obj) {
System.out.print(obj + " ");
}
@@ -140,19 +140,19 @@
<source>
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
-UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 == 0;
}
};
-UnaryFunction<Integer, Integer> doubler = new UnaryFunction<Integer, Integer>() {
+Function<Integer, Integer> doubler = new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return obj * 2;
}
};
-UnaryProcedure<Integer> print = new UnaryProcedure<Integer>() {
+Procedure<Integer> print = new Procedure<Integer>() {
public void run(Integer obj) {
System.out.print(obj + " ");
}
@@ -187,13 +187,13 @@
integers from 1 to 4 (the right argument is non-inclusive). The
generator is wrapped within a <em>Filtered Generator</em> that applies
the isEven predicate to each integer generated by the former generator.
- Finally, we execute a <em>Composite Unary Procedure</em> that uses
+ Finally, we execute a <em>Composite Procedure</em> that uses
a function to double the value of the integer before printing it.
</p>
<source>
Generator<Integer> integerGenerator = new IntegerRange(1, 5); // inclusive, exclusive
-UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
+Predicate<Integer> isEven = new Predicate<Integer>() {
public boolean test(Integer obj) {
return obj % 2 == 0;
}
@@ -202,20 +202,20 @@
FilteredGenerator<Integer> filteredGenerator =
new FilteredGenerator<Integer>(integerGenerator, isEven);
-UnaryFunction<Integer, Integer> doubler = new UnaryFunction<Integer, Integer>() {
+Function<Integer, Integer> doubler = new Function<Integer, Integer>() {
public Integer evaluate(Integer obj) {
return obj * 2;
}
};
-UnaryProcedure<Integer> print = new UnaryProcedure<Integer>() {
+Procedure<Integer> print = new Procedure<Integer>() {
public void run(Integer obj) {
System.out.print(obj + " ");
}
};
-CompositeUnaryProcedure<Integer> compositeProcedure =
- new CompositeUnaryProcedure<Integer>(print);
+CompositeProcedure<Integer> compositeProcedure =
+ new CompositeProcedure<Integer>(print);
filteredGenerator.run(compositeProcedure.of(doubler));
</source>