/** * 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); }
CollectionUtils.forAllDo( yourCollection, new Closure() { void execute(java.lang.Object element) { // do smt with element } } );
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)); }});
Closure closure = new Closure() { public void exec(){ // code here } }
Closure closure = new Closure(null) { public Object doCall() { /* some code here */ } };
Closure c = new Closure() { public void execute(Object obj) { ... } }; Predicate p = new Predicate() { public boolean evaluate(Object obj) { ... } } Trace(c, p);
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); } }); }};
/** * 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() { 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) {