/** * Create a new Transformer that calls one of the transformers depending * on the predicates. * <p> * The Map consists of Predicate keys and Transformer values. A transformer * is called if its matching predicate returns true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, the default * transformer is called. The default transformer is set in the map with a * null key. If no default transformer is set, null will be returned in a default * case. The ordering is that of the iterator() method on the entryset collection * of the map. * * @see org.apache.commons.collections.functors.SwitchTransformer * * @param predicatesAndTransformers a map of predicates to transformers * @return the transformer * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if the map is empty * @throws IllegalArgumentException if any transformer in the map is null * @throws ClassCastException if the map elements are of the wrong type */ public static Transformer switchTransformer(java.util.Map <Object, Object> predicatesAndTransformers) { return(SwitchTransformer.getInstance(predicatesAndTransformers)); }
/** * Create a new Transformer that calls one of the transformers depending * on the predicates. The transformer at array location 0 is called if the * predicate at array location 0 returned true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, null is returned. * * @see org.apache.commons.collections.functors.SwitchTransformer * * @param predicates an array of predicates to check * @param transformers an array of transformers to call * @return the transformer * @throws IllegalArgumentException if the either array is null * @throws IllegalArgumentException if the either array has 0 elements * @throws IllegalArgumentException if any element in the arrays is null * @throws IllegalArgumentException if the arrays are different sizes */ public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers) { return(SwitchTransformer.getInstance(predicates, transformers, null)); }
/** * Create a new Transformer that calls one of the transformers depending * on the predicates. The transformer at array location 0 is called if the * predicate at array location 0 returned true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, the default * transformer is called. If the default transformer is null, null is returned. * * @see org.apache.commons.collections.functors.SwitchTransformer * * @param predicates an array of predicates to check * @param transformers an array of transformers to call * @param defaultTransformer the default to call if no predicate matches, null means return null * @return the transformer * @throws IllegalArgumentException if the either array is null * @throws IllegalArgumentException if the either array has 0 elements * @throws IllegalArgumentException if any element in the arrays is null * @throws IllegalArgumentException if the arrays are different sizes */ public static Transformer switchTransformer(Predicate[] predicates, Transformer[] transformers, Transformer defaultTransformer) { return(SwitchTransformer.getInstance(predicates, transformers, defaultTransformer)); }
/** * Create a new Transformer that calls one of two transformers depending * on the specified predicate. * * @see org.apache.commons.collections.functors.SwitchTransformer * * @param predicate the predicate to switch on * @param trueTransformer the transformer called if the predicate is true * @param falseTransformer the transformer called if the predicate is false * @return the transformer * @throws IllegalArgumentException if the predicate is null * @throws IllegalArgumentException if either transformer is null */ public static Transformer switchTransformer(Predicate predicate, Transformer trueTransformer, Transformer falseTransformer) { return(SwitchTransformer.getInstance(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer)); }