@Test @SuppressWarnings("unchecked") public void testSwitchClosure() { final MockClosure<String> a = new MockClosure<String>(); final MockClosure<String> b = new MockClosure<String>(); ClosureUtils.<String>switchClosure( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Closure[] { a, b }).execute("WELL"); assertEquals(0, a.count); assertEquals(0, b.count); a.reset(); b.reset(); ClosureUtils.<String>switchClosure( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Closure[] { a, b }).execute("HELLO"); assertEquals(1, a.count); assertEquals(0, b.count); a.reset(); b.reset(); final MockClosure<String> c = new MockClosure<String>(); ClosureUtils.<String>switchClosure( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Closure[] { a, b }, c).execute("WELL"); assertEquals(0, a.count); assertEquals(0, b.count); assertEquals(1, c.count); a.reset(); b.reset(); final Map<Predicate<String>, Closure<String>> map = new HashMap<Predicate<String>, Closure<String>>(); map.put(EqualPredicate.equalPredicate("HELLO"), a); map.put(EqualPredicate.equalPredicate("THERE"), b); ClosureUtils.<String>switchClosure(map).execute(null); assertEquals(0, a.count); assertEquals(0, b.count); a.reset(); b.reset(); map.clear(); map.put(EqualPredicate.equalPredicate("HELLO"), a); map.put(EqualPredicate.equalPredicate("THERE"), b); ClosureUtils.switchClosure(map).execute("THERE"); assertEquals(0, a.count); assertEquals(1, b.count); a.reset(); b.reset(); c.reset(); map.clear(); map.put(EqualPredicate.equalPredicate("HELLO"), a); map.put(EqualPredicate.equalPredicate("THERE"), b); map.put(null, c); ClosureUtils.switchClosure(map).execute("WELL"); assertEquals(0, a.count); assertEquals(0, b.count); assertEquals(1, c.count); assertEquals(NOPClosure.INSTANCE, ClosureUtils.<String>switchClosure(new Predicate[0], new Closure[0])); assertEquals(NOPClosure.INSTANCE, ClosureUtils.<String>switchClosure(new HashMap<Predicate<String>, Closure<String>>())); map.clear(); map.put(null, null); assertEquals(NOPClosure.INSTANCE, ClosureUtils.switchClosure(map)); try { ClosureUtils.switchClosure(null, null); fail(); } catch (final NullPointerException ex) {} try { ClosureUtils.<String>switchClosure((Predicate<String>[]) null, (Closure<String>[]) null); fail(); } catch (final NullPointerException ex) {} try { ClosureUtils.<String>switchClosure((Map<Predicate<String>, Closure<String>>) null); fail(); } catch (final NullPointerException ex) {} try { ClosureUtils.<String>switchClosure(new Predicate[2], new Closure[2]); fail(); } catch (final NullPointerException ex) {} try { ClosureUtils.<String>switchClosure( new Predicate[] { TruePredicate.<String>truePredicate() }, new Closure[] { a, b }); fail(); } catch (final IllegalArgumentException ex) {} }
public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) { return SwitchClosure.<E>switchClosure(predicates, closures, null); }
ClosureUtils { public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) { return SwitchClosure.<E>switchClosure(predicates, closures, null); } }
ClosureUtils { public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) { return SwitchClosure.<E>switchClosure(predicates, closures, null); } private  ClosureUtils(); }
ClosureUtils { public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) { return SwitchClosure.<E>switchClosure(predicates, closures, null); } private  ClosureUtils(); static Closure<E> exceptionClosure(); static Closure<E> nopClosure(); static Closure<E> asClosure(final Transformer<? super E, ?> transformer); static Closure<E> forClosure(final int count, final Closure<? super E> closure); static Closure<E> whileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure); static Closure<E> doWhileClosure(final Closure<? super E> closure,
                                                final Predicate<? super E> predicate); static Closure<E> invokerClosure(final String methodName); static Closure<E> invokerClosure(final String methodName, final Class<?>[] paramTypes,
                                                final Object[] args); static Closure<E> chainedClosure(final Closure<? super E>... closures); static Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures); static Closure<E> ifClosure(final Predicate<? super E> predicate,
                                           final Closure<? super E> trueClosure); static Closure<E> ifClosure(final Predicate<? super E> predicate,
                                           final Closure<? super E> trueClosure,
                                           final Closure<? super E> falseClosure); static Closure<E> switchClosure(final Predicate<? super E>[] predicates,
                                               final Closure<? super E>[] closures); static Closure<E> switchClosure(final Predicate<? super E>[] predicates,
                                               final Closure<? super E>[] closures,
                                               final Closure<? super E> defaultClosure); static Closure<E> switchClosure(final Map<Predicate<E>, Closure<E>> predicatesAndClosures); @SuppressWarnings("unchecked") static Closure<E> switchMapClosure(final Map<? extends E, Closure<E>> objectsAndClosures); }
ClosureUtils { public static <E> Closure<E> switchClosure(final Predicate<? super E>[] predicates, final Closure<? super E>[] closures) { return SwitchClosure.<E>switchClosure(predicates, closures, null); } private  ClosureUtils(); static Closure<E> exceptionClosure(); static Closure<E> nopClosure(); static Closure<E> asClosure(final Transformer<? super E, ?> transformer); static Closure<E> forClosure(final int count, final Closure<? super E> closure); static Closure<E> whileClosure(final Predicate<? super E> predicate, final Closure<? super E> closure); static Closure<E> doWhileClosure(final Closure<? super E> closure,
                                                final Predicate<? super E> predicate); static Closure<E> invokerClosure(final String methodName); static Closure<E> invokerClosure(final String methodName, final Class<?>[] paramTypes,
                                                final Object[] args); static Closure<E> chainedClosure(final Closure<? super E>... closures); static Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures); static Closure<E> ifClosure(final Predicate<? super E> predicate,
                                           final Closure<? super E> trueClosure); static Closure<E> ifClosure(final Predicate<? super E> predicate,
                                           final Closure<? super E> trueClosure,
                                           final Closure<? super E> falseClosure); static Closure<E> switchClosure(final Predicate<? super E>[] predicates,
                                               final Closure<? super E>[] closures); static Closure<E> switchClosure(final Predicate<? super E>[] predicates,
                                               final Closure<? super E>[] closures,
                                               final Closure<? super E> defaultClosure); static Closure<E> switchClosure(final Map<Predicate<E>, Closure<E>> predicatesAndClosures); @SuppressWarnings("unchecked") static Closure<E> switchMapClosure(final Map<? extends E, Closure<E>> objectsAndClosures);  }