You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/05/05 17:06:55 UTC
svn commit: r1479336 - in
/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors:
ChainedClosure.java ChainedTransformer.java
Author: tn
Date: Sun May 5 15:06:50 2013
New Revision: 1479336
URL: http://svn.apache.org/r1479336
Log:
[COLLECTIONS-453] Change ChainedTransformer and ChainedClosure constructors to copy input arguments, add private constructor for factory methods to not copy twice.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java?rev=1479336&r1=1479335&r2=1479336&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java Sun May 5 15:06:50 2013
@@ -49,7 +49,7 @@ public class ChainedClosure<E> implement
if (closures.length == 0) {
return NOPClosure.<E>nopClosure();
}
- return new ChainedClosure<E>(FunctorUtils.copy(closures));
+ return new ChainedClosure<E>(closures);
}
/**
@@ -78,18 +78,28 @@ public class ChainedClosure<E> implement
cmds[i++] = closure;
}
FunctorUtils.validate(cmds);
- return new ChainedClosure<E>(cmds);
+ return new ChainedClosure<E>(false, cmds);
+ }
+
+ /**
+ * Hidden constructor for the use by the static factory methods.
+ *
+ * @param clone if {@code true} the input argument will be cloned
+ * @param closures the closures to chain, no nulls
+ */
+ private ChainedClosure(final boolean clone, final Closure<? super E>... closures) {
+ super();
+ iClosures = clone ? FunctorUtils.copy(closures) : closures;
}
/**
* Constructor that performs no validation.
* Use <code>chainedClosure</code> if you want that.
*
- * @param closures the closures to chain, not copied, no nulls
+ * @param closures the closures to chain, copied, no nulls
*/
- public ChainedClosure(final Closure<? super E>[] closures) {
- super();
- iClosures = closures;
+ public ChainedClosure(final Closure<? super E>... closures) {
+ this(true, closures);
}
/**
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java?rev=1479336&r1=1479335&r2=1479336&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java Sun May 5 15:06:50 2013
@@ -52,7 +52,7 @@ public class ChainedTransformer<T> imple
if (transformers.length == 0) {
return NOPTransformer.<T>nopTransformer();
}
- return new ChainedTransformer<T>(FunctorUtils.copy(transformers));
+ return new ChainedTransformer<T>(transformers);
}
/**
@@ -77,18 +77,28 @@ public class ChainedTransformer<T> imple
// convert to array like this to guarantee iterator() ordering
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
FunctorUtils.validate(cmds);
- return new ChainedTransformer<T>(cmds);
+ return new ChainedTransformer<T>(false, cmds);
}
/**
- * Constructor that performs no validation.
- * Use <code>chainedTransformer</code> if you want that.
+ * Hidden constructor for the use by the static factory methods.
*
+ * @param clone if {@code true} the input argument will be cloned
* @param transformers the transformers to chain, not copied, no nulls
*/
- public ChainedTransformer(final Transformer<? super T, ? extends T>[] transformers) {
+ private ChainedTransformer(final boolean clone, final Transformer<? super T, ? extends T>[] transformers) {
super();
- iTransformers = transformers;
+ iTransformers = clone ? FunctorUtils.copy(transformers) : transformers;
+ }
+
+ /**
+ * Constructor that performs no validation.
+ * Use <code>chainedTransformer</code> if you want that.
+ *
+ * @param transformers the transformers to chain, copied, no nulls
+ */
+ public ChainedTransformer(final Transformer<? super T, ? extends T>... transformers) {
+ this(true, transformers);
}
/**