/** * Execute a list of closures. * * @param input the input object passed to each closure */ public void execute(Object input) { for (int i = 0; i < iClosures.length; i++) { iClosures[i].execute(input); } }
/** * Transforms the input to result by executing a closure. * * @param input the input object to transform * @return the transformed result */ public Object transform(Object input) { iClosure.execute(input); return input; }
/** * Executes the closure <code>count</code> times. * * @param input the input object */ public void execute(Object input) { for (int i = 0; i < iCount; i++) { iClosure.execute(input); } }
/** * Executes the closure <code>count</code> times. * * @param input the input object */ public void execute(Object input) { for (int i = 0; i < iCount; i++) { iClosure.execute(input); } }
/** * Execute a list of closures. * * @param input the input object passed to each closure */ public void execute(Object input) { for (int i = 0; i < iClosures.length; i++) { iClosures[i].execute(input); } }
/** * Transforms the input to result by executing a closure. * * @param input the input object to transform * @return the transformed result */ public Object transform(Object input) { iClosure.execute(input); return input; }
/** * Executes the given closure on each element in the collection. * <p> * If the input collection or closure is null, there is no change made. * * @param collection the collection to get the input from, may be null * @param closure the closure to perform, may be null */ public static void forAllDo(Collection collection, Closure closure) { if (collection != null && closure != null) { for (Iterator it = collection.iterator(); it.hasNext();) { closure.execute(it.next()); } } }
/** * NOTE: Should not mutate the CrawlHost instance so retrieved; depending on * the hostscache implementation, the change may not be reliably persistent. * * @see org.archive.modules.net.ServerCache#forAllHostsDo(org.apache.commons.collections.Closure) */ public void forAllHostsDo(Closure c) { for(String host : hosts.keySet()) { c.execute(hosts.get(host)); } }
public void testInvokeClosure() { StringBuffer buf = new StringBuffer("Hello"); ClosureUtils.invokerClosure("reverse").execute(buf); assertEquals("olleH", buf.toString()); buf = new StringBuffer("Hello"); ClosureUtils.invokerClosure("setLength", new Class[] {Integer.TYPE}, new Object[] {new Integer(2)}).execute(buf); assertEquals("He", buf.toString()); }
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 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 testForClosure() { MockClosure cmd = new MockClosure(); ClosureUtils.forClosure(5, cmd).execute(null); assertEquals(5, cmd.count); assertSame(NOPClosure.INSTANCE, ClosureUtils.forClosure(0, new MockClosure())); assertSame(NOPClosure.INSTANCE, ClosureUtils.forClosure(-1, new MockClosure())); assertSame(NOPClosure.INSTANCE, ClosureUtils.forClosure(1, null)); assertSame(NOPClosure.INSTANCE, ClosureUtils.forClosure(3, null)); assertSame(cmd, ClosureUtils.forClosure(1, cmd)); }