/**
  * 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));
 }
コード例 #2
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));
 }
コード例 #4
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)));
 }
コード例 #5
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));
 }