diff --git a/src/main/java/net/fortuna/ical4j/validate/component/VEventReplyValidator.java b/src/main/java/net/fortuna/ical4j/validate/component/VEventReplyValidator.java index ebc6ae2fc..78825120a 100644 --- a/src/main/java/net/fortuna/ical4j/validate/component/VEventReplyValidator.java +++ b/src/main/java/net/fortuna/ical4j/validate/component/VEventReplyValidator.java @@ -7,6 +7,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; /** * METHOD:REPLY Validator. @@ -71,30 +75,24 @@ public class VEventReplyValidator implements Validator { private static final long serialVersionUID = 1L; - public void validate(VEvent target) throws ValidationException { - PropertyValidator.getInstance().assertOne(Property.ATTENDEE, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.DTSTAMP, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.ORGANIZER, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.UID, target.getProperties()); + public void validate(final VEvent target) throws ValidationException { + CollectionUtils.forAllDo(Arrays.asList(Property.ATTENDEE, Property.DTSTAMP, Property.ORGANIZER, Property.UID), + new Closure() { + @Override + public void execute(String input) { + PropertyValidator.getInstance().assertOne(input, target.getProperties()); + } + }); - PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DTEND, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.GEO, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.TRANSP, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.URL, target.getProperties()); + CollectionUtils.forAllDo(Arrays.asList(Property.RECURRENCE_ID, Property.SEQUENCE, Property.CATEGORIES, Property.CLASS, + Property.CREATED, Property.DESCRIPTION, Property.DTEND, Property.DTSTART, Property.DURATION, Property.GEO, + Property.LAST_MODIFIED, Property.LOCATION, Property.PRIORITY, Property.RESOURCES, Property.STATUS, Property.SUMMARY, + Property.TRANSP, Property.URL), new Closure() { + @Override + public void execute(String input) { + PropertyValidator.getInstance().assertOneOrLess(input, target.getProperties()); + } + }); ComponentValidator.assertNone(Component.VALARM, target.getAlarms()); } diff --git a/src/main/java/net/fortuna/ical4j/validate/component/VEventRequestValidator.java b/src/main/java/net/fortuna/ical4j/validate/component/VEventRequestValidator.java index 3a79a1207..0586a1a1f 100644 --- a/src/main/java/net/fortuna/ical4j/validate/component/VEventRequestValidator.java +++ b/src/main/java/net/fortuna/ical4j/validate/component/VEventRequestValidator.java @@ -8,6 +8,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; /** * METHOD:REQUEST Validator. @@ -68,33 +72,28 @@ public class VEventRequestValidator implements Validator { private static final long serialVersionUID = 1L; - public void validate(VEvent target) throws ValidationException { + public void validate(final VEvent target) throws ValidationException { if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, target.getProperties()); } - PropertyValidator.getInstance().assertOne(Property.DTSTAMP, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.DTSTART, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.ORGANIZER, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.SUMMARY, target.getProperties()); - PropertyValidator.getInstance().assertOne(Property.UID, target.getProperties()); + CollectionUtils.forAllDo(Arrays.asList(Property.DTSTAMP, Property.DTSTART, Property.ORGANIZER, Property.SUMMARY, + Property.UID), new Closure() { + @Override + public void execute(String input) { + PropertyValidator.getInstance().assertOne(input, target.getProperties()); + } + }); - PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DTEND, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.GEO, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.TRANSP, target.getProperties()); - PropertyValidator.getInstance().assertOneOrLess(Property.URL, target.getProperties()); + CollectionUtils.forAllDo(Arrays.asList(Property.SEQUENCE, Property.CATEGORIES, Property.CLASS, Property.CREATED, + Property.DESCRIPTION, Property.DTEND, Property.DURATION, Property.GEO, Property.LAST_MODIFIED, Property.LOCATION, + Property.PRIORITY, Property.RECURRENCE_ID, Property.RESOURCES, Property.STATUS, Property.TRANSP, Property.URL), + new Closure() { + @Override + public void execute(String input) { + PropertyValidator.getInstance().assertOneOrLess(input, target.getProperties()); + } + }); for (final VAlarm alarm : target.getAlarms()) { alarm.validate(Method.REQUEST);