Permalink
Browse files

Use closures to reduce code duplication

  • Loading branch information...
benfortuna committed Oct 5, 2016
1 parent 4860a73 commit b0c4d928aa1ee9b9993755dd1a0c19d3b3ad00b7
@@ -118,28 +118,14 @@ public final void validate() throws ValidationException {
* roleparam) / (";" partstatparam) / (";" rsvpparam) / (";" deltoparam) / (";" delfromparam) / (";"
* sentbyparam) / (";"cnparam) / (";" dirparam) / (";" languageparam) /
*/
- ParameterValidator.getInstance().assertOneOrLess(Parameter.CUTYPE,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.MEMBER,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.ROLE,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.PARTSTAT,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.RSVP,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(
- Parameter.DELEGATED_TO, getParameters());
- ParameterValidator.getInstance().assertOneOrLess(
- Parameter.DELEGATED_FROM, getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.SENT_BY,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.CN,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.DIR,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.LANGUAGE,
- getParameters());
+ CollectionUtils.forAllDo(Arrays.asList(Parameter.CUTYPE, Parameter.MEMBER, Parameter.ROLE, Parameter.PARTSTAT,
+ Parameter.RSVP, Parameter.DELEGATED_TO, Parameter.DELEGATED_FROM, Parameter.SENT_BY, Parameter.CN,
+ Parameter.DIR, Parameter.LANGUAGE), new Closure<String>() {
+ @Override
+ public void execute(String input) {
+ PropertyValidator.getInstance().assertOneOrLess(input, getParameters());
+ }
+ });
/* scheduleagent and schedulestatus added for CalDAV scheduling
*/
@@ -189,14 +189,13 @@ public final void validate() throws ValidationException {
* ; the following are optional, ; but MUST NOT occur more than once (";" cnparam) / (";" dirparam) / (";"
* sentbyparam) / (";" languageparam) /
*/
- ParameterValidator.getInstance().assertOneOrLess(Parameter.CN,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.DIR,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.SENT_BY,
- getParameters());
- ParameterValidator.getInstance().assertOneOrLess(Parameter.LANGUAGE,
- getParameters());
+ CollectionUtils.forAllDo(Arrays.asList(Parameter.CN, Parameter.DIR, Parameter.SENT_BY,
+ Parameter.LANGUAGE), new Closure<String>() {
+ @Override
+ public void execute(String input) {
+ PropertyValidator.getInstance().assertOneOrLess(input, getParameters());
+ }
+ });
/* schedulestatus added for CalDAV scheduling
*/

0 comments on commit b0c4d92

Please sign in to comment.