[COLLECTIONS-453] Change ChainedTransformer and ChainedClosure constructors to copy input arguments, add private constructor for factory methods to not copy twice.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1479336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
afcbced8ef
commit
8283d966f4
|
@ -49,7 +49,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
|
||||||
if (closures.length == 0) {
|
if (closures.length == 0) {
|
||||||
return NOPClosure.<E>nopClosure();
|
return NOPClosure.<E>nopClosure();
|
||||||
}
|
}
|
||||||
return new ChainedClosure<E>(FunctorUtils.copy(closures));
|
return new ChainedClosure<E>(closures);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,18 +78,28 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
|
||||||
cmds[i++] = closure;
|
cmds[i++] = closure;
|
||||||
}
|
}
|
||||||
FunctorUtils.validate(cmds);
|
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.
|
* Constructor that performs no validation.
|
||||||
* Use <code>chainedClosure</code> if you want that.
|
* 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) {
|
public ChainedClosure(final Closure<? super E>... closures) {
|
||||||
super();
|
this(true, closures);
|
||||||
iClosures = closures;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
if (transformers.length == 0) {
|
if (transformers.length == 0) {
|
||||||
return NOPTransformer.<T>nopTransformer();
|
return NOPTransformer.<T>nopTransformer();
|
||||||
}
|
}
|
||||||
return new ChainedTransformer<T>(FunctorUtils.copy(transformers));
|
return new ChainedTransformer<T>(transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,18 +77,28 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
|
||||||
// convert to array like this to guarantee iterator() ordering
|
// convert to array like this to guarantee iterator() ordering
|
||||||
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
|
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
|
||||||
FunctorUtils.validate(cmds);
|
FunctorUtils.validate(cmds);
|
||||||
return new ChainedTransformer<T>(cmds);
|
return new ChainedTransformer<T>(false, cmds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
private ChainedTransformer(final boolean clone, final Transformer<? super T, ? extends T>[] transformers) {
|
||||||
|
super();
|
||||||
|
iTransformers = clone ? FunctorUtils.copy(transformers) : transformers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that performs no validation.
|
* Constructor that performs no validation.
|
||||||
* Use <code>chainedTransformer</code> if you want that.
|
* Use <code>chainedTransformer</code> if you want that.
|
||||||
*
|
*
|
||||||
* @param transformers the transformers to chain, not copied, no nulls
|
* @param transformers the transformers to chain, copied, no nulls
|
||||||
*/
|
*/
|
||||||
public ChainedTransformer(final Transformer<? super T, ? extends T>[] transformers) {
|
public ChainedTransformer(final Transformer<? super T, ? extends T>... transformers) {
|
||||||
super();
|
this(true, transformers);
|
||||||
iTransformers = transformers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue