/** * Creates a closure with a single free variable and binds it to the current thread * @param type1 The type of the free variable of the newly created closure * @return The newly created closure */ public static <A> Closure1<A> createClosure(Class<A> type1) { Closure1<A> closure = new Closure1<A>(); CLOSURES.set(closure); return closure; }
/** * Invokes this closure once for each passed variable. * @param vars The set of variables used to invoke this closure once for each variable * @return A list of Object containing the results of each closure invocation */ public List<?> each(A... vars) { return closeAll(vars); }
/** * Invokes this closure once by applying the given variable to it. * @param var The variable used to invoke this closure * @return The result of the closure invocation */ public Object apply(A var) { return closeOne(var); }
/** * Curry this closure by fixing its only free variable to a given value. * @param curry The value to which the free variable should be curry * @return A Closure having no free variable */ public Closure0 curry(A curry) { return curry(new Closure0(), curry, 1); }
/** * {@inheritDoc} */ @Override public void createPoll(Poll poll) { this.getDao().saveOrUpdate(poll); Closure1<PollItem> closure = closure(PollItem.class); of(pollOptionDao).saveOrUpdate(var(PollItem.class)); closure.each(poll.getPollItems()); securityService.createAclBuilder().grant(GeneralPermission.WRITE) .to(groupDao.getGroupByName(AdministrationGroup.USER.getName())) .on(poll).flush(); }
/** * Curry this closure by fixing its first free variable to a given value. * @param curry The value to which the first variable should be curry * @return A Closure having a single free variable */ public Closure1<B> curry1(A curry) { return curry(new Closure1<B>(), curry, 1); }
/** * Invokes this closure once for each item in the given iterable. * @param vars The variables used to invoke this closure once for each of its item * @return A list of Object containing the results of each closure invocation */ public List<?> each(Iterable<? extends A> vars) { return closeAll(vars); }
/** * Curry this closure by fixing its second free variable to a given value. * @param curry The value to which the second variable should be curry * @return A Closure having a single variable */ public Closure1<A> curry2(B curry) { return curry(new Closure1<A>(), curry, 2); }