@Test public void testIfTransformer() { final Transformer<Object, String> a = TransformerUtils.constantTransformer("A"); final Transformer<Object, String> b = TransformerUtils.constantTransformer("B"); final Transformer<Object, String> c = TransformerUtils.constantTransformer("C"); assertEquals("A", TransformerUtils.ifTransformer(TruePredicate.truePredicate(), a, b).transform(null)); assertEquals("B", TransformerUtils.ifTransformer(FalsePredicate.falsePredicate(), a, b).transform(null)); Predicate<Integer> lessThanFivePredicate = new Predicate<Integer>() { @Override public boolean evaluate(Integer value) { return value < 5; } }; assertEquals("A", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(1)); assertEquals("B", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(5)); Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A"); assertEquals("C", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("A")); assertEquals("B", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("B")); try { TransformerUtils.ifTransformer(null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(TruePredicate.truePredicate(), null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(null, ConstantTransformer.constantTransformer("A")); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.ifTransformer(null, null, null); fail(); } catch (final NullPointerException ex) {} }
public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private  TransformerUtils(); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private  TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
            final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
            final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
                                                      final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
                                                         final Transformer<? super I, ? extends O> trueTransformer,
                                                         final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
            final Transformer<? super I, ? extends O> trueTransformer,
            final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
            final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
            final Transformer<? super I, ? extends O>[] transformers,
            final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
            final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
            final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
            final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
                                                              final Object[] args); static Transformer<T, String> stringValueTransformer(); }
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private  TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
            final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
            final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
                                                      final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
                                                         final Transformer<? super I, ? extends O> trueTransformer,
                                                         final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
            final Transformer<? super I, ? extends O> trueTransformer,
            final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
            final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
            final Transformer<? super I, ? extends O>[] transformers,
            final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
            final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
            final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
            final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
                                                              final Object[] args); static Transformer<T, String> stringValueTransformer();  }