/** * Factory to create the predicate. * * @param predicates the predicates to check, cloned, not null * @return the <code>one</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); return new OnePredicate(preds); }
/** * Factory to create the predicate. * * @param predicates the predicates to check, cloned, not null * @return the <code>one</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); return new OnePredicate(preds); }
/** * Factory to create the predicate. * <p> * If the collection is size zero, the predicate always returns true. * * @param predicates the predicates to check, cloned, not null * @return the <code>one</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return TruePredicate.INSTANCE; } return new NonePredicate(preds); }
/** * Factory to create the predicate. * <p> * If the collection is size zero, the predicate always returns false. * If the collection is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>all</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return FalsePredicate.INSTANCE; } if (preds.length == 1) { return preds[0]; } return new AnyPredicate(preds); }
/** * Factory to create the predicate. * <p> * If the collection is size zero, the predicate always returns true. * If the collection is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>all</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return TruePredicate.INSTANCE; } if (preds.length == 1) { return preds[0]; } return new AllPredicate(preds); }
/** * Factory to create the predicate. * <p> * If the collection is size zero, the predicate always returns true. * * @param predicates the predicates to check, cloned, not null * @return the <code>one</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Collection predicates) { Predicate[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return TruePredicate.INSTANCE; } return new NonePredicate(preds); }
/** * 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 closures a collection of closures to chain * @return the <code>chained</code> closure * @throws IllegalArgumentException if the closures collection is null * @throws IllegalArgumentException if any closure in the collection is null */ public static Closure getInstance(Collection closures) { if (closures == null) { throw new IllegalArgumentException("Closure collection must not be null"); } if (closures.size() == 0) { return NOPClosure.INSTANCE; } // convert to array like this to guarantee iterator() ordering Closure[] cmds = new Closure[closures.size()]; int i = 0; for (Iterator it = closures.iterator(); it.hasNext();) { cmds[i++] = (Closure) it.next(); } FunctorUtils.validate(cmds); return new ChainedClosure(cmds); }
/** * Create a new Transformer that calls each transformer in turn, passing the * result into the next transformer. The ordering is that of the iterator() * method on the collection. * * @param transformers a collection of transformers to chain * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers collection is null * @throws IllegalArgumentException if any transformer in the collection is null */ public static Transformer getInstance(Collection transformers) { if (transformers == null) { throw new IllegalArgumentException("Transformer collection must not be null"); } if (transformers.size() == 0) { return NOPTransformer.INSTANCE; } // convert to array like this to guarantee iterator() ordering Transformer[] cmds = new Transformer[transformers.size()]; int i = 0; for (Iterator it = transformers.iterator(); it.hasNext();) { cmds[i++] = (Transformer) it.next(); } FunctorUtils.validate(cmds); return new ChainedTransformer(cmds); }
/** * Factory method that performs validation and copies the parameter arrays. * * @param predicates array of predicates, cloned, no nulls * @param closures matching array of closures, cloned, no nulls * @param defaultClosure the closure to use if no match, null means nop * @return the <code>chained</code> closure * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if any element in the array is null */ public static Closure getInstance(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { FunctorUtils.validate(predicates); FunctorUtils.validate(closures); if (predicates.length != closures.length) { throw new IllegalArgumentException("The predicate and closure arrays must be the same size"); } if (predicates.length == 0) { return (defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure); } predicates = FunctorUtils.copy(predicates); closures = FunctorUtils.copy(closures); return new SwitchClosure(predicates, closures, defaultClosure); }
/** * Factory method that performs validation and copies the parameter arrays. * * @param predicates array of predicates, cloned, no nulls * @param transformers matching array of transformers, cloned, no nulls * @param defaultTransformer the transformer to use if no match, null means return null * @return the <code>chained</code> transformer * @throws IllegalArgumentException if array is null * @throws IllegalArgumentException if any element in the array is null */ public static Transformer getInstance(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) { FunctorUtils.validate(predicates); FunctorUtils.validate(transformers); if (predicates.length != transformers.length) { throw new IllegalArgumentException("The predicate and transformer arrays must be the same size"); } if (predicates.length == 0) { return (defaultTransformer == null ? ConstantTransformer.NULL_INSTANCE : defaultTransformer); } predicates = FunctorUtils.copy(predicates); transformers = FunctorUtils.copy(transformers); return new SwitchTransformer(predicates, transformers, defaultTransformer); }
/** * Factory method that performs validation and copies the parameter array. * * @param transformers the transformers to chain, copied, no nulls * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer getInstance(Transformer[] transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.INSTANCE; } transformers = FunctorUtils.copy(transformers); return new ChainedTransformer(transformers); }
/** * Factory method that performs validation and copies the parameter array. * * @param closures the closures to chain, copied, no nulls * @return the <code>chained</code> closure * @throws IllegalArgumentException if the closures array is null * @throws IllegalArgumentException if any closure in the array is null */ public static Closure getInstance(Closure[] closures) { FunctorUtils.validate(closures); if (closures.length == 0) { return NOPClosure.INSTANCE; } closures = FunctorUtils.copy(closures); return new ChainedClosure(closures); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns true. * * @param predicates the predicates to check, cloned, not null * @return the <code>any</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return TruePredicate.INSTANCE; } predicates = FunctorUtils.copy(predicates); return new NonePredicate(predicates); }
/** * Factory method that performs validation and copies the parameter array. * * @param closures the closures to chain, copied, no nulls * @return the <code>chained</code> closure * @throws IllegalArgumentException if the closures array is null * @throws IllegalArgumentException if any closure in the array is null */ public static Closure getInstance(Closure[] closures) { FunctorUtils.validate(closures); if (closures.length == 0) { return NOPClosure.INSTANCE; } closures = FunctorUtils.copy(closures); return new ChainedClosure(closures); }
/** * Factory method that performs validation and copies the parameter array. * * @param transformers the transformers to chain, copied, no nulls * @return the <code>chained</code> transformer * @throws IllegalArgumentException if the transformers array is null * @throws IllegalArgumentException if any transformer in the array is null */ public static Transformer getInstance(Transformer[] transformers) { FunctorUtils.validate(transformers); if (transformers.length == 0) { return NOPTransformer.INSTANCE; } transformers = FunctorUtils.copy(transformers); return new ChainedTransformer(transformers); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns false. * If the array is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>any</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return FalsePredicate.INSTANCE; } if (predicates.length == 1) { return predicates[0]; } return new AnyPredicate(FunctorUtils.copy(predicates)); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns false. * If the array is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>any</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return FalsePredicate.INSTANCE; } if (predicates.length == 1) { return predicates[0]; } predicates = FunctorUtils.copy(predicates); return new OnePredicate(predicates); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns true. * If the array is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>all</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return TruePredicate.INSTANCE; } if (predicates.length == 1) { return predicates[0]; } predicates = FunctorUtils.copy(predicates); return new AllPredicate(predicates); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns true. * * @param predicates the predicates to check, cloned, not null * @return the <code>any</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return TruePredicate.INSTANCE; } predicates = FunctorUtils.copy(predicates); return new NonePredicate(predicates); }
/** * Factory to create the predicate. * <p> * If the array is size zero, the predicate always returns false. * If the array is size one, then that predicate is returned. * * @param predicates the predicates to check, cloned, not null * @return the <code>any</code> predicate * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ public static Predicate getInstance(Predicate[] predicates) { FunctorUtils.validate(predicates); if (predicates.length == 0) { return FalsePredicate.INSTANCE; } if (predicates.length == 1) { return predicates[0]; } return new AnyPredicate(FunctorUtils.copy(predicates)); }