/** * 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()); } } }
/** * 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)); } }
/** * Walk entries. * * @param handler * handler to call. * @param filter * filter to use. * @throws IllegalArgumentException * if closure or filter is null. */ public void walk( final Closure handler, final Predicate filter ) throws IllegalArgumentException { Assert.assertNotNull( handler, "Handler cannot be null" ); Assert.assertNotNull( filter, "Filter cannot be null" ); for ( KeyValue<?> keyValue : this.entries.values() ) { if ( filter.evaluate( keyValue ) ) { handler.execute( keyValue ); } } }
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(); }