/**
  * 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(java.util.Collection <Object> predicates)
 {
     Predicate[] preds = FunctorUtils.validate((java.util.Collection <Predicate>)predicates);
     if (preds.Length == 0)
     {
         return(TruePredicate.INSTANCE);
     }
     return(new NonePredicate(preds));
 }
 /**
  * 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));
 }
Example #3
0
 /**
  * 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));
 }
Example #5
0
 /**
  * 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)));
 }
Example #6
0
 /**
  * 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 java.lang.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 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 java.lang.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));
 }
        /**
         * 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(java.util.Collection <Object> transformers)
        {
            if (transformers == null)
            {
                throw new java.lang.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 (java.util.Iterator <Object> it = transformers.iterator(); it.hasNext();)
            {
                cmds[i++] = (Transformer)it.next();
            }
            FunctorUtils.validate(cmds);
            return(new ChainedTransformer(cmds));
        }
Example #9
0
        /**
         * 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(java.util.Collection <Object> closures)
        {
            if (closures == null)
            {
                throw new java.lang.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 (java.util.Iterator <Object> it = closures.iterator(); it.hasNext();)
            {
                cmds[i++] = (Closure)it.next();
            }
            FunctorUtils.validate(cmds);
            return(new ChainedClosure(cmds));
        }
Example #10
0
 /**
  * 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(java.util.Collection <Object> predicates)
 {
     Predicate[] preds = FunctorUtils.validate((java.util.Collection <Predicate>)predicates);
     return(new OnePredicate(preds));
 }