Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Oct 27, 2021
1 parent f9e36bc commit e3ebd49
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 91 deletions.
26 changes: 2 additions & 24 deletions src/main/java/net/fortuna/ical4j/model/component/Observance.java
Expand Up @@ -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;
Expand Down Expand Up @@ -120,29 +120,7 @@ protected Observance(final String name, final PropertyList<Property> 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();
}
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/net/fortuna/ical4j/validate/PropertyValidator.java
Expand Up @@ -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;

Expand All @@ -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]
Expand All @@ -53,14 +51,6 @@
*/
public final class PropertyValidator<T extends Property> implements Validator<T> {

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> ATTACH = new PropertyValidator<>(
new ValidationRule(OneOrLess, FMTTYPE));

Expand Down Expand Up @@ -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);
}
}

0 comments on commit e3ebd49

Please sign in to comment.