You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2013/07/31 00:48:08 UTC
svn commit: r1508677 [2/9] - in /commons/proper/functor/trunk:
api/src/main/java/org/apache/commons/functor/
core/src/main/java/org/apache/commons/functor/adapter/
core/src/main/java/org/apache/commons/functor/aggregator/
core/src/main/java/org/apache/...
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java Tue Jul 30 22:48:02 2013
@@ -0,0 +1,138 @@
+/*
+ * 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.BinaryProcedure;
+import org.apache.commons.functor.NullaryProcedure;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link BinaryNullaryProcedure BinaryNullaryProcedure}
+ * to the
+ * {@link NullaryProcedure NullaryProcedure} interface
+ * using a constant left-side argument.
+ * <p/>
+ * Note that although this class implements
+ * {@link Serializable}, a given instance will
+ * only be truly <code>Serializable</code> if the
+ * underlying objects are. Attempts to serialize
+ * an instance whose delegates are 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 FullyBoundNullaryProcedure implements NullaryProcedure, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = -904891610081737737L;
+ /** 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;
+ /** The right parameter to pass to {@code procedure}. */
+ private final Object right;
+
+ /**
+ * Create a new FullyBoundNullaryProcedure instance.
+ * @param <L> left type
+ * @param <R> right type
+ * @param procedure the procedure to adapt
+ * @param left the left argument to use
+ * @param right the right argument to use
+ */
+ @SuppressWarnings("unchecked")
+ 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");
+ this.left = left;
+ this.right = right;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run() {
+ procedure.run(left, right);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof FullyBoundNullaryProcedure
+ && equals((FullyBoundNullaryProcedure) that));
+ }
+
+ /**
+ * Learn whether another FullyBoundNullaryProcedure is equal to this.
+ * @param that FullyBoundNullaryProcedure to test
+ * @return boolean
+ */
+ 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "FullyBoundNullaryProcedure".hashCode();
+ hash <<= 2;
+ hash ^= procedure.hashCode();
+ hash <<= 2;
+ if (null != left) {
+ hash ^= left.hashCode();
+ }
+ hash <<= 2;
+ if (null != right) {
+ hash ^= right.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "FullyBoundNullaryProcedure<" + procedure + "(" + left + ", " + right + ")>";
+ }
+
+ /**
+ * 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 FullyBoundNullaryProcedure
+ */
+ 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);
+ }
+
+}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionPredicate.java Tue Jul 30 22:48:02 2013
@@ -24,43 +24,45 @@ import org.apache.commons.lang3.Validate
/**
* 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 @@ public final class FunctionPredicate imp
*/
@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 @@ public final class FunctionPredicate imp
* @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 @@ public final class FunctionPredicate imp
}
/**
- * 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);
}
+
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java Tue Jul 30 22:48:02 2013
@@ -35,32 +35,34 @@ import org.apache.commons.lang3.Validate
* 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 @@ public final class FunctionProcedure imp
*/
@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 @@ public final class FunctionProcedure imp
* 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);
}
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftFunction.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreLeftFunction<L,
* 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 @@ public final class IgnoreLeftFunction<L,
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftPredicate.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreLeftPredicate<L
* 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 @@ public final class IgnoreLeftPredicate<L
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreLeftProcedure.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreLeftProcedure<L
* 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 @@ public final class IgnoreLeftProcedure<L
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightFunction.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreRightFunction<L
* 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 @@ public final class IgnoreRightFunction<L
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightPredicate.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreRightPredicate<
* 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 @@ public final class IgnoreRightPredicate<
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/IgnoreRightProcedure.java Tue Jul 30 22:48:02 2013
@@ -19,12 +19,12 @@ package org.apache.commons.functor.adapt
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 @@ public final class IgnoreRightProcedure<
* 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 @@ public final class IgnoreRightProcedure<
}
/**
- * 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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundFunction.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class LeftBoundFunction<A,
}
/**
- * Adapt a BinaryFunction as a UnaryFunction.
+ * Adapt a BinaryFunction as a Function.
* @param <L> left type
* @param <R> right type
* @param <T> result type
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundPredicate.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class LeftBoundPredicate<A>
}
/**
- * 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
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/LeftBoundProcedure.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class LeftBoundProcedure<A>
}
/**
- * 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
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionFunction.java Tue Jul 30 22:48:02 2013
@@ -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.Function;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link NullaryFunction NullaryFunction}
+ * to the
+ * {@link Function Function} interface
+ * by ignoring the unary argument.
+ * <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.
+ *
+ * @param <A> the argument type.
+ * @param <T> the returned value type.
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryFunctionFunction<A, T> implements Function<A, T>, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = 1993899041200996524L;
+ /** The {@link NullaryFunction NullaryFunction} I'm wrapping. */
+ private final NullaryFunction<? extends T> function;
+
+ /**
+ * Create a new NullaryFunctionFunction.
+ * @param function to adapt
+ */
+ public NullaryFunctionFunction(NullaryFunction<? extends T> function) {
+ this.function = Validate.notNull(function, "NullaryFunction argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T evaluate(A obj) {
+ return function.evaluate();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryFunctionFunction<?, ?>
+ && equals((NullaryFunctionFunction<?, ?>) that));
+ }
+
+ /**
+ * Learn whether another NullaryFunctionFunction is equal to this.
+ * @param that NullaryFunctionFunction to test
+ * @return boolean
+ */
+ public boolean equals(NullaryFunctionFunction<?, ?> that) {
+ return null != that && function.equals(that.function);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryFunctionFunction".hashCode();
+ hash ^= function.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryFunctionFunction<" + function + ">";
+ }
+
+ /**
+ * Adapt a NullaryFunction to the Function interface.
+ * @param <A> arg type
+ * @param <T> result type
+ * @param function to adapt
+ * @return NullaryFunctionFunction
+ */
+ public static <A, T> NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function) {
+ return null == function ? null : new NullaryFunctionFunction<A, T>(function);
+ }
+
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryPredicate.java Tue Jul 30 22:48:02 2013
@@ -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);
+ }
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryFunctionNullaryProcedure.java Tue Jul 30 22:48:02 2013
@@ -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);
+ }
+
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicateNullaryFunction.java Tue Jul 30 22:48:02 2013
@@ -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);
+ }
+
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryPredicatePredicate.java Tue Jul 30 22:48:02 2013
@@ -0,0 +1,111 @@
+/*
+ * 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.NullaryPredicate;
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link NullaryPredicate NullaryPredicate}
+ * to the
+ * {@link Predicate Predicate} interface
+ * by ignoring the given argument.
+ * <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.
+ *
+ * @param <A> the argument type.
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryPredicatePredicate<A> implements Predicate<A>, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = -5168896606842881702L;
+ /** The {@link NullaryPredicate NullaryPredicate} I'm wrapping. */
+ private final NullaryPredicate predicate;
+
+ /**
+ * Create a new NullaryPredicatePredicate.
+ * @param predicate to adapt
+ */
+ public NullaryPredicatePredicate(NullaryPredicate predicate) {
+ this.predicate = Validate.notNull(predicate, "NullaryPredicate argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean test(Object obj) {
+ return predicate.test();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryPredicatePredicate<?>
+ && equals((NullaryPredicatePredicate<?>) that));
+ }
+
+ /**
+ * Learn whether a given NullaryPredicatePredicate is equal to this.
+ * @param that NullaryPredicatePredicate to test
+ * @return boolean
+ */
+ public boolean equals(NullaryPredicatePredicate<?> that) {
+ return null != that && predicate.equals(that.predicate);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryPredicatePredicate".hashCode();
+ hash ^= predicate.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryPredicatePredicate<" + predicate + ">";
+ }
+
+ /**
+ * Adapt a NullaryPredicate to the Predicate interface.
+ * @param <A> the argument type.
+ * @param predicate to adapt
+ * @return NullaryPredicatePredicate<A>
+ */
+ public static <A> NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate) {
+ return null == predicate ? null : new NullaryPredicatePredicate<A>(predicate);
+ }
+
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureNullaryFunction.java Tue Jul 30 22:48:02 2013
@@ -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);
+ }
+
+}
Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java?rev=1508677&view=auto
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java (added)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/NullaryProcedureProcedure.java Tue Jul 30 22:48:02 2013
@@ -0,0 +1,111 @@
+/*
+ * 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.NullaryProcedure;
+import org.apache.commons.functor.Procedure;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * Adapts a
+ * {@link NullaryProcedure Procedure}
+ * to the
+ * {@link Procedure Procedure} interface
+ * by ignoring the arguments.
+ * <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.
+ *
+ * @param <A> the argument type.
+ * @version $Revision: 1365377 $ $Date: 2012-07-24 21:59:23 -0300 (Tue, 24 Jul 2012) $
+ */
+public final class NullaryProcedureProcedure<A> implements Procedure<A>, Serializable {
+ /**
+ * serialVersionUID declaration.
+ */
+ private static final long serialVersionUID = 501530698794315412L;
+ /** The {@link NullaryProcedure Procedure} I'm wrapping. */
+ private final NullaryProcedure procedure;
+
+ /**
+ * Create a new NullaryProcedureProcedure.
+ * @param procedure to adapt
+ */
+ public NullaryProcedureProcedure(NullaryProcedure procedure) {
+ this.procedure = Validate.notNull(procedure, "NullaryProcedure argument was null");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run(A obj) {
+ procedure.run();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object that) {
+ return that == this || (that instanceof NullaryProcedureProcedure<?>
+ && equals((NullaryProcedureProcedure<?>) that));
+ }
+
+ /**
+ * Learn whether another NullaryProcedureProcedure is equal to this.
+ * @param that NullaryProcedureProcedure to test
+ * @return boolean
+ */
+ public boolean equals(NullaryProcedureProcedure<?> that) {
+ return null != that && procedure.equals(that.procedure);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hash = "NullaryProcedureProcedure".hashCode();
+ hash ^= procedure.hashCode();
+ return hash;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "NullaryProcedureProcedure<" + procedure + ">";
+ }
+
+ /**
+ * Adapt a NullaryProcedure to the Procedure interface.
+ * @param <A> the argument type.
+ * @param procedure to adapt
+ * @return NullaryProcedureProcedure<A>
+ */
+ public static <A> NullaryProcedureProcedure<A> adapt(NullaryProcedure procedure) {
+ return null == procedure ? null : new NullaryProcedureProcedure<A>(procedure);
+ }
+
+}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/PredicateFunction.java Tue Jul 30 22:48:02 2013
@@ -35,21 +35,22 @@ import org.apache.commons.lang3.Validate
* 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 @@ public final class PredicateFunction imp
*
* @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 @@ public final class PredicateFunction imp
*/
@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 @@ public final class PredicateFunction imp
* @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 @@ public final class PredicateFunction imp
/**
* 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);
}
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/ProcedureFunction.java Tue Jul 30 22:48:02 2013
@@ -36,30 +36,31 @@ import org.apache.commons.lang3.Validate
* 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 @@ public final class ProcedureFunction<T>
*/
@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 @@ public final class ProcedureFunction<T>
}
/**
- * 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);
}
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundFunction.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class RightBoundFunction<A,
}
/**
- * 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.
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundPredicate.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class RightBoundPredicate<A
}
/**
- * 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
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/RightBoundProcedure.java Tue Jul 30 22:48:02 2013
@@ -19,14 +19,14 @@ package org.apache.commons.functor.adapt
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 @@ import org.apache.commons.lang3.Validate
* @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 @@ public final class RightBoundProcedure<A
}
/**
- * 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
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java Tue Jul 30 22:48:02 2013
@@ -18,7 +18,7 @@ package org.apache.commons.functor.aggre
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 @@ import org.apache.commons.lang3.Validate
* 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 @@ public abstract class AbstractListBacked
* 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 @@ public abstract class AbstractListBacked
* @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 @@ public abstract class AbstractListBacked
* ; 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 @@ public abstract class AbstractListBacked
*
* @return Current value of {@link #aggregationFunction}
*/
- final UnaryFunction<List<T>, T> getAggregationFunction() {
+ final Function<List<T>, T> getAggregationFunction() {
return aggregationFunction;
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/Aggregator.java Tue Jul 30 22:48:02 2013
@@ -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 @@ import org.apache.commons.functor.Functi
* @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
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.java Tue Jul 30 22:48:02 2013
@@ -19,7 +19,7 @@ package org.apache.commons.functor.aggre
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 @@ import org.apache.commons.functor.UnaryF
*/
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 @@ public class ArrayListBackedAggregator<T
* @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 @@ public class ArrayListBackedAggregator<T
* {@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);
}
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java?rev=1508677&r1=1508676&r2=1508677&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java (original)
+++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/aggregator/functions/DoubleMaxAggregatorFunction.java Tue Jul 30 22:48:02 2013
@@ -18,7 +18,7 @@ package org.apache.commons.functor.aggre
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 @@ import org.apache.commons.functor.UnaryF
* 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