Permalink
Browse files

Use closures to reduce duplicate code

  • Loading branch information...
benfortuna committed Sep 19, 2015
1 parent 923292b commit ce778d66c5ef09aa960c6b62be83aac25bfe930a
Showing with 19 additions and 9 deletions.
  1. +19 −9 src/main/java/net/fortuna/ical4j/validate/component/VFreeBusyPublishValidator.java
@@ -5,6 +5,10 @@
import net.fortuna.ical4j.validate.PropertyValidator;
import net.fortuna.ical4j.validate.ValidationException;
import net.fortuna.ical4j.validate.Validator;
+import org.apache.commons.collections4.Closure;
+import org.apache.commons.collections4.CollectionUtils;
+
+import java.util.Arrays;
/**
* <pre>
@@ -45,19 +49,25 @@
private static final long serialVersionUID = 1L;
- public void validate(VFreeBusy target) throws ValidationException {
+ public void validate(final VFreeBusy target) throws ValidationException {
PropertyValidator.getInstance().assertOneOrMore(Property.FREEBUSY, target.getProperties());
- PropertyValidator.getInstance().assertOne(Property.DTSTAMP, target.getProperties());
- PropertyValidator.getInstance().assertOne(Property.DTSTART, target.getProperties());
- PropertyValidator.getInstance().assertOne(Property.DTEND, target.getProperties());
- PropertyValidator.getInstance().assertOne(Property.ORGANIZER, target.getProperties());
- PropertyValidator.getInstance().assertOne(Property.UID, target.getProperties());
+ CollectionUtils.forAllDo(Arrays.asList(Property.DTSTAMP, Property.DTSTART, Property.DTEND, Property.ORGANIZER,
+ Property.UID), new Closure<String>() {
+ @Override
+ public void execute(String input) {
+ PropertyValidator.getInstance().assertOne(input, target.getProperties());
+ }
+ });
PropertyValidator.getInstance().assertOneOrLess(Property.URL, target.getProperties());
- PropertyValidator.getInstance().assertNone(Property.ATTENDEE, target.getProperties());
- PropertyValidator.getInstance().assertNone(Property.DURATION, target.getProperties());
- PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, target.getProperties());
+ CollectionUtils.forAllDo(Arrays.asList(Property.ATTENDEE, Property.DURATION, Property.REQUEST_STATUS),
+ new Closure<String>() {
+ @Override
+ public void execute(String input) {
+ PropertyValidator.getInstance().assertNone(input, target.getProperties());
+ }
+ });
}
}

0 comments on commit ce778d6

Please sign in to comment.