/** * Create a new Closure that calls each closure in turn, passing the * result into the next closure. * * @see org.apache.commons.collections4.functors.ChainedClosure * * @param <E> the type that the closure acts on * @param closures an array of closures to chain * @return the <code>chained</code> closure * @throws NullPointerException if the closures array is null * @throws NullPointerException if any closure in the array is null */ public static <E> Closure<E> chainedClosure(final Closure<? super E>... closures) { return ChainedClosure.chainedClosure(closures); }
/** * Factory method that performs validation and copies the parameter array. * * @param <E> the type that the closure acts on * @param closures the closures to chain, copied, no nulls * @return the <code>chained</code> closure * @throws NullPointerException if the closures array is null * @throws NullPointerException if any closure in the array is null */ public static <E> Closure<E> chainedClosure(final Closure<? super E>... closures) { FunctorUtils.validate(closures); if (closures.length == 0) { return NOPClosure.<E>nopClosure(); } return new ChainedClosure<>(closures); }
/** * Create a new Closure that calls each closure in turn, passing the * result into the next closure. The ordering is that of the iterator() * method on the collection. * * @param <E> the type that the closure acts on * @param closures a collection of closures to chain * @return the <code>chained</code> closure * @throws NullPointerException if the closures collection is null * @throws NullPointerException if any closure in the collection is null */ @SuppressWarnings("unchecked") public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) { if (closures == null) { throw new NullPointerException("Closure collection must not be null"); } if (closures.size() == 0) { return NOPClosure.<E>nopClosure(); } // convert to array like this to guarantee iterator() ordering final Closure<? super E>[] cmds = new Closure[closures.size()]; int i = 0; for (final Closure<? super E> closure : closures) { cmds[i++] = closure; } FunctorUtils.validate(cmds); return new ChainedClosure<>(false, cmds); }
/** * Create a new Closure that calls each closure in turn, passing the * result into the next closure. The ordering is that of the iterator() * method on the collection. * * @see org.apache.commons.collections4.functors.ChainedClosure * * @param <E> the type that the closure acts on * @param closures a collection of closures to chain * @return the <code>chained</code> closure * @throws NullPointerException if the closures collection is null * @throws NullPointerException if any closure in the collection is null * @throws IllegalArgumentException if the closures collection is empty */ public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) { return ChainedClosure.chainedClosure(closures); }