##// END OF EJS Templates
sync
cin -
r17:4277fa402608 default
parent child
Show More
@@ -10,12 +10,25 public final class Closures {
10 private Closures() {
10 private Closures() {
11 }
11 }
12
12
13 /**
14 * Wraps {@link Action} around the specified closure. The parameter
15 * of the action will be used as delegate in the specified closure.
16 *
17 * @param <T> The type of the action parameter
18 * @param closure The closure
19 * @return
20 */
13 public static <T> Action<T> action(Closure<?> closure) {
21 public static <T> Action<T> action(Closure<?> closure) {
14 return arg -> apply(closure, arg);
22 return arg -> apply(closure, arg);
15 }
23 }
16
24
17 public static void apply(Closure<?> action, Object target) {
25 public static void apply(Closure<?> action, Object target) {
26 var prevDelegate = action.getDelegate();
27 try {
18 action.setDelegate(target);
28 action.setDelegate(target);
19 action.call(target);
29 action.call(target);
30 } finally {
31 action.setDelegate(prevDelegate);
20 }
32 }
21 }
33 }
34 }
General Comments 0
You need to be logged in to leave comments. Login now