/** * Invokes the method. Also private method also can be invoked. * * @return result of execution */ @Override public Object executeWithArgs(ExecutionType executionType, Object[] args) throws CommandActionExecutionException { if(ExecutionType.ASYNCHRONOUS == executionType){ Closure closure = AsyncClosureFactory.getInstance().createClosure(metaHolder, method, object, args); return executeClj(closure.getClosureObj(), closure.getClosureMethod()); } return execute(object, method, args); }
/** * Creates closure. * * @param rootMethodName the name of external method within which closure is created. * @param closureObj the instance of specific anonymous class * @return new {@link Closure} instance * @throws Exception */ Closure createClosure(String rootMethodName, final Object closureObj) throws Exception { if (!isClosureCommand(closureObj)) { throw new RuntimeException(format(ERROR_TYPE_MESSAGE, rootMethodName, getClosureCommandType().getName()).getMessage()); } Method closureMethod = closureObj.getClass().getMethod(INVOKE_METHOD); return new Closure(closureMethod, closureObj); }
@Override public Closure createClosure(MetaHolder metaHolder, Method method, Object o, Object... args) { try { Object closureObj; method.setAccessible(true); if (isCompileWeaving()) { closureObj = invokeAjcMethod(metaHolder.getAjcMethod(), o, metaHolder, args); } else { closureObj = method.invoke(o, args); // creates instance of an anonymous class } return createClosure(method.getName(), closureObj); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } catch (Exception e) { throw Throwables.propagate(e); } }
Switcher<List<T>> sortStrategy = new Switcher<List<T>>() .addCase(having(on(List.class).get(0), instanceOf(String.class))), new Closure() {{ of(this).sortStrings(var(List.class)); }}) .addCase(having(on(List.class).size(), lessThan(100))), new Closure() {{ of(this).sortSmallList(var(List.class)); }}) .setDefault(new Closure() {{ of(this).sort(var(List.class)); }});
/** * Invokes the method. Also private method also can be invoked. * * @return result of execution */ @Override public Object executeWithArgs(ExecutionType executionType, Object[] args) throws CommandActionExecutionException { if(ExecutionType.ASYNCHRONOUS == executionType){ Closure closure = AsyncClosureFactory.getInstance().createClosure(metaHolder, method, object, args); return executeClj(closure.getClosureObj(), closure.getClosureMethod()); } return execute(object, method, args); }
/** * Creates closure. * * @param rootMethodName the name of external method within which closure is created. * @param closureObj the instance of specific anonymous class * @return new {@link Closure} instance * @throws Exception */ Closure createClosure(String rootMethodName, final Object closureObj) throws Exception { if (!isClosureCommand(closureObj)) { throw new RuntimeException(format(ERROR_TYPE_MESSAGE, rootMethodName, getClosureCommandType().getName()).getMessage()); } Method closureMethod = closureObj.getClass().getMethod(INVOKE_METHOD); return new Closure(closureMethod, closureObj); }
Closure closure = new Closure(null) { public Object doCall() { /* some code here */ } };
@Override public Closure createClosure(MetaHolder metaHolder, Method method, Object o, Object... args) { try { Object closureObj; method.setAccessible(true); if (isCompileWeaving()) { closureObj = invokeAjcMethod(metaHolder.getAjcMethod(), o, metaHolder, args); } else { closureObj = method.invoke(o, args); // creates instance of an anonymous class } return createClosure(method.getName(), closureObj); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } catch (Exception e) { throw Throwables.propagate(e); } }
Closure c = new Closure() { public void execute(Object obj) { ... } }; Predicate p = new Predicate() { public boolean evaluate(Object obj) { ... } } Trace(c, p);
CollectionUtils.forAllDo( yourCollection, new Closure() { void execute(java.lang.Object element) { // do smt with element } } );
Closure closure = new Closure() { public void exec(){ // code here } }
function Closure() { var o = { a: { b:2 } }; this.getO = function () { return o; }; } var closure = new Closure(), newO = closure.getO(); newO.a = 111; console.dir(closure.getO());
List<Item> list; @SuppressWarnings("unchecked") Map<Key, Item> map = new HashMap<Key, Item>>(){{ CollectionUtils.forAllDo(list, new Closure() { @Override public void execute(Object input) { Item item = (Item) input; put(i.getKey(), item); } }); }};
Closure closure = new Closure() { public void run(ExpectState expectState) throws Exception { buffer.append(expectState.getBuffer()); lstPattern.add(new EofMatch( new Closure() { // should cause entire page to be collected public void run(ExpectState state) { lstPattern.add(new TimeoutMatch(defaultTimeOut, new Closure() { public void run(ExpectState state) {
Closure closure = new Closure() { public void run(ExpectState expectState) throws Exception { lstPattern.add(new EofMatch( new Closure() { // should cause entire page to be collected public void run(ExpectState state) { lstPattern.add(new TimeoutMatch(defaultTimeOut, new Closure() { public void run(ExpectState state) {
Closure closure = new Closure() { public void run(ExpectState expectState) throws Exception { lstPattern.add(new EofMatch( new Closure() { // should cause entire page to be collected public void run(ExpectState state) { lstPattern.add(new TimeoutMatch(defaultTimeOut, new Closure() { public void run(ExpectState state) {