git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-05-16 11:36:31 +00:00
parent d7321ef14d
commit 9522bd7085
13 changed files with 92 additions and 38 deletions

View File

@ -22,10 +22,13 @@ import java.util.Iterator;
import org.apache.commons.collections.Transformer;
/**
* Transformer implementation that chains the specified closures together.
* Transformer implementation that chains the specified transformers together.
* <p>
* The input object is passed to the first transformer. The transformed result
* is passed to the second transformer and so on.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.7 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -109,9 +112,10 @@ public class ChainedTransformer implements Transformer, Serializable {
}
/**
* Execute a list of transformers.
* Transforms the input to result via each decorated transformer
*
* @param object the input object passed to each transformer
* @param object the input object passed to the first transformer
* @return the transformed result
*/
public Object transform(Object object) {
for (int i = 0; i < iTransformers.length; i++) {

View File

@ -25,7 +25,7 @@ import org.apache.commons.collections.Transformer;
* Clone is performed using <code>PrototypeFactory.getInstance(input).create()</code>.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/03/31 23:13:04 $
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -55,7 +55,10 @@ public class CloneTransformer implements Transformer, Serializable {
}
/**
* Do nothing
* Transforms the input to result by cloning it.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
if (input == null) {
@ -63,5 +66,5 @@ public class CloneTransformer implements Transformer, Serializable {
}
return PrototypeFactory.getInstance(input).create();
}
}

View File

@ -25,7 +25,7 @@ import org.apache.commons.collections.Transformer;
* and then returns the input.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -63,7 +63,10 @@ public class ClosureTransformer implements Transformer, Serializable {
}
/**
* Call the closure.
* Transforms the input to result by executing a closure.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
iClosure.execute(input);
@ -72,6 +75,7 @@ public class ClosureTransformer implements Transformer, Serializable {
/**
* Gets the closure.
*
* @return the closure
* @since Commons Collections 3.1
*/

View File

@ -27,7 +27,7 @@ import org.apache.commons.collections.Transformer;
* use the prototype factory.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -67,7 +67,10 @@ public class ConstantTransformer implements Transformer, Serializable {
}
/**
* Always return constant.
* Transforms the input by ignoring it and returning the stored constant instead.
*
* @param input the input object which is ignored
* @return the stored constant
*/
public Object transform(Object input) {
return iConstant;
@ -75,6 +78,7 @@ public class ConstantTransformer implements Transformer, Serializable {
/**
* Gets the constant.
*
* @return the constant
* @since Commons Collections 3.1
*/

View File

@ -24,7 +24,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that always throws an exception.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/03/31 23:13:04 $
* @version $Revision: 1.7 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -55,10 +55,14 @@ public final class ExceptionTransformer implements Transformer, Serializable {
}
/**
* Always throw an exception.
* Transforms the input to result by cloning it.
*
* @param input the input object to transform
* @return never
* @throws FunctorException always
*/
public Object transform(Object object) {
public Object transform(Object input) {
throw new FunctorException("ExceptionTransformer invoked");
}
}

View File

@ -24,7 +24,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that calls a Factory and returns the result.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/05/03 12:03:11 $
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -62,7 +62,11 @@ public class FactoryTransformer implements Transformer, Serializable {
}
/**
* Call the factory.
* Transforms the input by ignoring the input and returning the result of
* calling the decorated factory.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
return iFactory.create();
@ -70,6 +74,7 @@ public class FactoryTransformer implements Transformer, Serializable {
/**
* Gets the factory.
*
* @return the factory
* @since Commons Collections 3.1
*/

View File

@ -26,7 +26,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that creates a new object instance by reflection.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/02/18 00:59:20 $
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -48,6 +48,7 @@ public class InstantiateTransformer implements Transformer, Serializable {
*
* @param paramTypes the constructor parameter types
* @param args the constructor arguments
* @return an instantiate transformer
*/
public static Transformer getInstance(Class[] paramTypes, Object[] args) {
if (((paramTypes == null) && (args != null))
@ -88,7 +89,10 @@ public class InstantiateTransformer implements Transformer, Serializable {
}
/**
* Return the result of instantiating the input Class object.
* Transforms the input Class object to a result by instantiation.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
try {
@ -110,5 +114,5 @@ public class InstantiateTransformer implements Transformer, Serializable {
throw new FunctorException("InstantiateTransformer: Constructor threw an exception", ex);
}
}
}

View File

@ -26,7 +26,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that creates a new object instance by reflection.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/02/18 00:59:20 $
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -43,10 +43,12 @@ public class InvokerTransformer implements Transformer, Serializable {
private final Object[] iArgs;
/**
* Transformer method that performs validation.
* Gets an instanceof this transformer calling a specific method with specific values.
*
* @param paramTypes the constructor parameter types
* @param args the constructor arguments
* @param methodName the method name to call
* @param paramTypes the parameter types of the method
* @param args the arguments to pass to the method
* @return an invoker transformer
*/
public static Transformer getInstance(String methodName, Class[] paramTypes, Object[] args) {
if (methodName == null) {
@ -94,7 +96,10 @@ public class InvokerTransformer implements Transformer, Serializable {
}
/**
* Return the result of instantiating the input Class object.
* Transforms the input to result by invoking a method on the input.
*
* @param input the input object to transform
* @return the transformed result, null if null input
*/
public Object transform(Object input) {
if (input == null) {
@ -113,5 +118,5 @@ public class InvokerTransformer implements Transformer, Serializable {
throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' threw an exception", ex);
}
}
}

View File

@ -25,7 +25,7 @@ import org.apache.commons.collections.Transformer;
* using the input parameter as a key.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.7 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -64,7 +64,10 @@ public final class MapTransformer implements Transformer, Serializable {
}
/**
* Returns the result by looking up in the map.
* Transforms the input to result by looking it up in a <code>Map</code>.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
return iMap.get(input);
@ -72,6 +75,7 @@ public final class MapTransformer implements Transformer, Serializable {
/**
* Gets the map to lookup in.
*
* @return the map
* @since Commons Collections 3.1
*/

View File

@ -23,7 +23,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that does nothing.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/03/31 23:13:04 $
* @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -53,10 +53,13 @@ public class NOPTransformer implements Transformer, Serializable {
}
/**
* Do nothing
* Transforms the input to result by doing nothing.
*
* @param input the input object to transform
* @return the transformed result which is the input
*/
public Object transform(Object input) {
return input;
}
}

View File

@ -25,7 +25,7 @@ import org.apache.commons.collections.Transformer;
* and then returns the input.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -63,7 +63,10 @@ public class PredicateTransformer implements Transformer, Serializable {
}
/**
* Call the predicate.
* Transforms the input to result by calling a predicate.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
return (iPredicate.evaluate(input) ? Boolean.TRUE : Boolean.FALSE);
@ -71,6 +74,7 @@ public class PredicateTransformer implements Transformer, Serializable {
/**
* Gets the predicate.
*
* @return the predicate
* @since Commons Collections 3.1
*/

View File

@ -23,7 +23,7 @@ import org.apache.commons.collections.Transformer;
* Transformer implementation that returns the <code>String.valueOf</code>.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2004/03/31 23:13:04 $
* @version $Revision: 1.7 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -53,10 +53,13 @@ public final class StringValueTransformer implements Transformer, Serializable {
}
/**
* Return the String.valueOf for the object.
* Transforms the input to result by calling <code>String.valueOf</code>.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
return String.valueOf(input);
}
}

View File

@ -27,7 +27,7 @@ import org.apache.commons.collections.Transformer;
* like a switch statement.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2004/03/13 17:17:03 $
* @version $Revision: 1.5 $ $Date: 2004/05/16 11:36:31 $
*
* @author Stephen Colebourne
*/
@ -127,7 +127,11 @@ public class SwitchTransformer implements Transformer, Serializable {
}
/**
* Execute the transformer whose predicate returns true.
* Transforms the input to result by calling the transformer whose matching
* predicate returns true.
*
* @param input the input object to transform
* @return the transformed result
*/
public Object transform(Object input) {
for (int i = 0; i < iPredicates.length; i++) {
@ -140,6 +144,7 @@ public class SwitchTransformer implements Transformer, Serializable {
/**
* Gets the predicates, do not modify the array.
*
* @return the predicates
* @since Commons Collections 3.1
*/
@ -149,6 +154,7 @@ public class SwitchTransformer implements Transformer, Serializable {
/**
* Gets the transformers, do not modify the array.
*
* @return the transformers
* @since Commons Collections 3.1
*/
@ -158,6 +164,7 @@ public class SwitchTransformer implements Transformer, Serializable {
/**
* Gets the default transformer.
*
* @return the default transformer
* @since Commons Collections 3.1
*/