From e3ebd498f34e15f75aa2bbb5712bdf664acc0f93 Mon Sep 17 00:00:00 2001 From: Ben Fortuna Date: Wed, 27 Oct 2021 14:16:51 +1100 Subject: [PATCH] Code cleanup --- .../ical4j/model/component/Observance.java | 26 +------ .../ical4j/validate/PropertyValidator.java | 67 ------------------- 2 files changed, 2 insertions(+), 91 deletions(-) diff --git a/src/main/java/net/fortuna/ical4j/model/component/Observance.java b/src/main/java/net/fortuna/ical4j/model/component/Observance.java index 009540f65..f9378ab22 100644 --- a/src/main/java/net/fortuna/ical4j/model/component/Observance.java +++ b/src/main/java/net/fortuna/ical4j/model/component/Observance.java @@ -36,7 +36,7 @@ import net.fortuna.ical4j.model.property.*; import net.fortuna.ical4j.util.Dates; import net.fortuna.ical4j.util.TimeZones; -import net.fortuna.ical4j.validate.PropertyValidator; +import net.fortuna.ical4j.validate.ComponentValidator; import net.fortuna.ical4j.validate.ValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -120,29 +120,7 @@ protected Observance(final String name, final PropertyList properties) */ @Override public final void validate(final boolean recurse) throws ValidationException { - - // From "4.8.3.3 Time Zone Offset From": - // Conformance: This property MUST be specified in a "VTIMEZONE" - // calendar component. - PropertyValidator.assertOne(Property.TZOFFSETFROM, - getProperties()); - - // From "4.8.3.4 Time Zone Offset To": - // Conformance: This property MUST be specified in a "VTIMEZONE" - // calendar component. - PropertyValidator.assertOne(Property.TZOFFSETTO, - getProperties()); - - /* - * ; the following are each REQUIRED, ; but MUST NOT occur more than once dtstart / tzoffsetto / tzoffsetfrom / - */ - PropertyValidator.assertOne(Property.DTSTART, - getProperties()); - - /* - * ; the following are optional, ; and MAY occur more than once comment / rdate / rrule / tzname / x-prop - */ - + ComponentValidator.OBSERVANCE_ITIP.validate(this); if (recurse) { validateProperties(); } diff --git a/src/main/java/net/fortuna/ical4j/validate/PropertyValidator.java b/src/main/java/net/fortuna/ical4j/validate/PropertyValidator.java index 0be6282d5..9a2453a39 100644 --- a/src/main/java/net/fortuna/ical4j/validate/PropertyValidator.java +++ b/src/main/java/net/fortuna/ical4j/validate/PropertyValidator.java @@ -32,7 +32,6 @@ package net.fortuna.ical4j.validate; import net.fortuna.ical4j.model.Property; -import net.fortuna.ical4j.model.PropertyList; import net.fortuna.ical4j.model.property.*; import net.fortuna.ical4j.util.CompatibilityHints; @@ -42,7 +41,6 @@ import static net.fortuna.ical4j.model.Parameter.*; import static net.fortuna.ical4j.validate.ValidationRule.ValidationType.None; import static net.fortuna.ical4j.validate.ValidationRule.ValidationType.OneOrLess; -import static net.fortuna.ical4j.validate.Validator.assertFalse; /** * $Id$ [15-May-2004] @@ -53,14 +51,6 @@ */ public final class PropertyValidator implements Validator { - public static final String ASSERT_NONE_MESSAGE = "Property [{0}] is not applicable"; - - public static final String ASSERT_ONE_OR_LESS_MESSAGE = "Property [{0}] must only be specified once"; - - public static final String ASSERT_ONE_MESSAGE = "Property [{0}] must be specified once"; - - public static final String ASSERT_ONE_OR_MORE_MESSAGE = "Property [{0}] must be specified at least once"; - public static final Validator ATTACH = new PropertyValidator<>( new ValidationRule(OneOrLess, FMTTYPE)); @@ -164,61 +154,4 @@ public void validate(Property target) throws ValidationException { throw new ValidationException(result); } } - - /** - * Ensure a property occurs no more than once. - * - * @param propertyName - * the property name - * @param properties - * a list of properties to query - * @throws ValidationException - * when the specified property occurs more than once - */ - public static void assertOneOrLess(final String propertyName, final PropertyList properties) throws ValidationException { - assertFalse(input -> input.getProperties(propertyName).size() > 1, ASSERT_ONE_OR_LESS_MESSAGE, false, - properties, propertyName); - } - - /** - * Ensure a property occurs at least once. - * - * @param propertyName - * the property name - * @param properties - * a list of properties to query - * @throws ValidationException - * when the specified property occurs more than once - */ - public static void assertOneOrMore(final String propertyName, final PropertyList properties) throws ValidationException { - assertFalse(input -> input.getProperties(propertyName).size() < 1, ASSERT_ONE_OR_MORE_MESSAGE, false, - properties, propertyName); - } - - /** - * Ensure a property occurs once. - * - * @param propertyName - * the property name - * @param properties - * a list of properties to query - * @throws ValidationException - * when the specified property does not occur once - */ - public static void assertOne(final String propertyName, final PropertyList properties) throws ValidationException { - assertFalse(input -> input.getProperties(propertyName).size() != 1, ASSERT_ONE_MESSAGE, false, - properties, propertyName); - } - - /** - * Ensure a property doesn't occur in the specified list. - * @param propertyName the name of a property - * @param properties a list of properties - * @throws ValidationException thrown when the specified property - * is found in the list of properties - */ - public static void assertNone(final String propertyName, final PropertyList properties) throws ValidationException { - assertFalse(input -> input.getProperty(propertyName) != null, ASSERT_NONE_MESSAGE, false, - properties, propertyName); - } }