/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);
public void testDoWhileClosure() { MockClosure cmd = new MockClosure(); ClosureUtils.doWhileClosure(cmd, PredicateUtils.falsePredicate()).execute(null); assertEquals(1, cmd.count); cmd = new MockClosure(); ClosureUtils.doWhileClosure(cmd, PredicateUtils.uniquePredicate()).execute(null); assertEquals(2, cmd.count); try { ClosureUtils.doWhileClosure(null, null); fail(); } catch (IllegalArgumentException ex) {} }
public void testTransformerClosure() { MockTransformer mock = new MockTransformer(); Closure closure = ClosureUtils.asClosure(mock); closure.execute(null); assertEquals(1, mock.count); closure.execute(null); assertEquals(2, mock.count); assertSame(ClosureUtils.nopClosure(), ClosureUtils.asClosure(null)); }
public void testExceptionClosure() { assertNotNull(ClosureUtils.exceptionClosure()); assertSame(ClosureUtils.exceptionClosure(), ClosureUtils.exceptionClosure()); try { ClosureUtils.exceptionClosure().execute(null); } catch (FunctorException ex) { try { ClosureUtils.exceptionClosure().execute(cString); } catch (FunctorException ex2) { return; } } fail(); }
public void testChainedClosure() { MockClosure a = new MockClosure(); MockClosure b = new MockClosure(); ClosureUtils.chainedClosure(a, b).execute(null); assertEquals(1, a.count); assertEquals(1, b.count); ClosureUtils.chainedClosure(new Closure[] {a, b, a}).execute(null); assertEquals(2, a.count); assertEquals(1, b.count); coll.add(a); coll.add(b); ClosureUtils.chainedClosure(coll).execute(null); assertEquals(1, a.count); assertEquals(2, b.count); assertSame(NOPClosure.INSTANCE, ClosureUtils.chainedClosure(new Closure[0])); assertSame(NOPClosure.INSTANCE, ClosureUtils.chainedClosure(Collections.EMPTY_LIST)); ClosureUtils.chainedClosure(null, null); fail(); } catch (IllegalArgumentException ex) {} try { ClosureUtils.chainedClosure((Closure[]) null); fail(); } catch (IllegalArgumentException ex) {} try { ClosureUtils.chainedClosure((Collection) null); fail();
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @param paramTypes the parameter types * @param args the arguments * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null * @throws IllegalArgumentException if the paramTypes and args don't match */ public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName, paramTypes, args)); }
i++; return switchClosure(preds, trs, def);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @param paramTypes the parameter types * @param args the arguments * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null * @throws IllegalArgumentException if the paramTypes and args don't match */ public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName, paramTypes, args)); }
public void testSwitchClosure() { MockClosure a = new MockClosure(); MockClosure b = new MockClosure(); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}).execute("WELL"); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}).execute("HELLO"); b = new MockClosure(); MockClosure c = new MockClosure(); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}, c).execute("WELL"); map.put(PredicateUtils.equalPredicate("HELLO"), a); map.put(PredicateUtils.equalPredicate("THERE"), b); ClosureUtils.switchClosure(map).execute(null); assertEquals(0, a.count); assertEquals(0, b.count); map.put(PredicateUtils.equalPredicate("HELLO"), a); map.put(PredicateUtils.equalPredicate("THERE"), b); ClosureUtils.switchClosure(map).execute("THERE"); assertEquals(0, a.count); assertEquals(1, b.count); map.put(PredicateUtils.equalPredicate("THERE"), b);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);
/** * Creates a Closure that will invoke a specific method on the closure's * input object by reflection. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerClosure * * @param methodName the name of the method * @return the <code>invoker</code> closure * @throws IllegalArgumentException if the method name is null */ public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asClosure(InvokerTransformer.getInstance(methodName)); }
i++; return switchClosure(preds, trs, def);