Skip to content

Commit

Permalink
Make maps of ValidationRule static to avoid excessive memory use
Browse files Browse the repository at this point in the history
  • Loading branch information
nealeu committed May 28, 2021
1 parent 8c9f90b commit eaa0285
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 107 deletions.
12 changes: 6 additions & 6 deletions src/main/java/net/fortuna/ical4j/model/component/VAlarm.java
Expand Up @@ -195,8 +195,8 @@ public class VAlarm extends CalendarComponent {

private static final long serialVersionUID = -8193965477414653802L;

private final Map<Action, Validator> actionValidators = new HashMap<Action, Validator>();
{
private static final Map<Action, Validator> actionValidators = new HashMap<Action, Validator>();
static {
actionValidators.put(Action.AUDIO, new ComponentValidator<VAlarm>(new ValidationRule(OneOrLess, ATTACH)));
actionValidators.put(Action.DISPLAY, new ComponentValidator<VAlarm>(new ValidationRule(One, DESCRIPTION)));
actionValidators.put(Action.EMAIL, new ComponentValidator<VAlarm>(new ValidationRule(One, DESCRIPTION, SUMMARY),
Expand Down Expand Up @@ -266,21 +266,21 @@ public final void validate(final boolean recurse)
PropertyValidator.assertOne(Property.DURATION, getProperties());
PropertyValidator.assertOne(Property.REPEAT, getProperties());
}

/*
* ; the following is optional, ; and MAY occur more than once x-prop
*/

final Validator actionValidator = actionValidators.get(getAction());
if (actionValidator != null) {
actionValidator.validate(this);
}

if (recurse) {
validateProperties();
}
}

/**
* {@inheritDoc}
*/
Expand Down
82 changes: 41 additions & 41 deletions src/main/java/net/fortuna/ical4j/model/component/VEvent.java
Expand Up @@ -60,104 +60,104 @@
* $Id$ [Apr 5, 2004]
*
* Defines an iCalendar VEVENT component.
*
*
* <pre>
* 4.6.1 Event Component
*
*
* Component Name: &quot;VEVENT&quot;
*
*
* Purpose: Provide a grouping of component properties that describe an
* event.
*
*
* Format Definition: A &quot;VEVENT&quot; calendar component is defined by the
* following notation:
*
*
* eventc = &quot;BEGIN&quot; &quot;:&quot; &quot;VEVENT&quot; CRLF
* eventprop *alarmc
* &quot;END&quot; &quot;:&quot; &quot;VEVENT&quot; CRLF
*
*
* eventprop = *(
*
*
* ; the following are optional,
* ; but MUST NOT occur more than once
*
*
* class / created / description / dtstart / geo /
* last-mod / location / organizer / priority /
* dtstamp / seq / status / summary / transp /
* uid / url / recurid /
*
*
* ; either 'dtend' or 'duration' may appear in
* ; a 'eventprop', but 'dtend' and 'duration'
* ; MUST NOT occur in the same 'eventprop'
*
*
* dtend / duration /
*
*
* ; the following are optional,
* ; and MAY occur more than once
*
*
* attach / attendee / categories / comment /
* contact / exdate / exrule / rstatus / related /
* resources / rdate / rrule / x-prop
*
*
* )
* </pre>
*
*
* Example 1 - Creating a new all-day event:
*
*
* <pre><code>
* java.util.Calendar cal = java.util.Calendar.getInstance();
* cal.set(java.util.Calendar.MONTH, java.util.Calendar.DECEMBER);
* cal.set(java.util.Calendar.DAY_OF_MONTH, 25);
*
*
* VEvent christmas = new VEvent(cal.getTime(), &quot;Christmas Day&quot;);
*
*
* // initialise as an all-day event..
* christmas.getProperties().getProperty(Property.DTSTART).getParameters().add(
* Value.DATE);
*
*
* // add timezone information..
* VTimeZone tz = VTimeZone.getDefault();
* TzId tzParam = new TzId(tz.getProperties().getProperty(Property.TZID)
* .getValue());
* christmas.getProperties().getProperty(Property.DTSTART).getParameters().add(
* tzParam);
* </code></pre>
*
*
* Example 2 - Creating an event of one (1) hour duration:
*
*
* <pre><code>
* java.util.Calendar cal = java.util.Calendar.getInstance();
* // tomorrow..
* cal.add(java.util.Calendar.DAY_OF_MONTH, 1);
* cal.set(java.util.Calendar.HOUR_OF_DAY, 9);
* cal.set(java.util.Calendar.MINUTE, 30);
*
*
* VEvent meeting = new VEvent(cal.getTime(), 1000 * 60 * 60, &quot;Progress Meeting&quot;);
*
*
* // add timezone information..
* VTimeZone tz = VTimeZone.getDefault();
* TzId tzParam = new TzId(tz.getProperties().getProperty(Property.TZID)
* .getValue());
* meeting.getProperties().getProperty(Property.DTSTART).getParameters().add(
* tzParam);
* </code></pre>
*
*
* Example 3 - Retrieve a list of periods representing a recurring event in a specified range:
*
*
* <pre><code>
* Calendar weekday9AM = Calendar.getInstance();
* weekday9AM.set(2005, Calendar.MARCH, 7, 9, 0, 0);
* weekday9AM.set(Calendar.MILLISECOND, 0);
*
*
* Calendar weekday5PM = Calendar.getInstance();
* weekday5PM.set(2005, Calendar.MARCH, 7, 17, 0, 0);
* weekday5PM.set(Calendar.MILLISECOND, 0);
*
*
* // Do the recurrence until December 31st.
* Calendar untilCal = Calendar.getInstance();
* untilCal.set(2005, Calendar.DECEMBER, 31);
* untilCal.set(Calendar.MILLISECOND, 0);
*
*
* // 9:00AM to 5:00PM Rule
* Recur recur = new Recur(Recur.WEEKLY, untilCal.getTime());
* recur.getDayList().add(WeekDay.MO);
Expand All @@ -168,15 +168,15 @@
* recur.setInterval(3);
* recur.setWeekStartDay(WeekDay.MO.getDay());
* RRule rrule = new RRule(recur);
*
*
* Summary summary = new Summary(&quot;TEST EVENTS THAT HAPPEN 9-5 MON-FRI&quot;);
*
*
* weekdayNineToFiveEvents = new VEvent();
* weekdayNineToFiveEvents.getProperties().add(rrule);
* weekdayNineToFiveEvents.getProperties().add(summary);
* weekdayNineToFiveEvents.getProperties().add(new DtStart(weekday9AM.getTime()));
* weekdayNineToFiveEvents.getProperties().add(new DtEnd(weekday5PM.getTime()));
*
*
* // Test Start 04/01/2005, End One month later.
* // Query Calendar Start and End Dates.
* Calendar queryStartDate = Calendar.getInstance();
Expand All @@ -185,22 +185,22 @@
* Calendar queryEndDate = Calendar.getInstance();
* queryEndDate.set(2005, Calendar.MAY, 1, 11, 15, 0);
* queryEndDate.set(Calendar.MILLISECOND, 0);
*
*
* // This range is monday to friday every three weeks, starting from
* // March 7th 2005, which means for our query dates we need
* // April 18th through to the 22nd.
* PeriodList periods = weekdayNineToFiveEvents.getPeriods(queryStartDate
* .getTime(), queryEndDate.getTime());
* </code></pre>
*
*
* @author Ben Fortuna
*/
public class VEvent extends CalendarComponent {

private static final long serialVersionUID = 2547948989200697335L;

private final Map<Method, Validator> methodValidators = new HashMap<Method, Validator>();
{
private static final Map<Method, Validator> methodValidators = new HashMap<Method, Validator>();
static {
methodValidators.put(Method.ADD, new VEventValidator(new ValidationRule(One, DTSTAMP, DTSTART, ORGANIZER, SEQUENCE, SUMMARY, UID),
new ValidationRule(OneOrLess, CATEGORIES, CLASS, CREATED, DESCRIPTION, DTEND, DURATION, GEO,
LAST_MODIFIED, LOCATION, PRIORITY, RESOURCES, STATUS, TRANSP, URL),
Expand Down Expand Up @@ -239,7 +239,7 @@ public class VEvent extends CalendarComponent {
new ValidationRule(OneOrLess, SEQUENCE, CATEGORIES, CLASS, CREATED, DESCRIPTION, DTEND, DURATION, GEO,
LAST_MODIFIED, LOCATION, PRIORITY, RECURRENCE_ID, RESOURCES, STATUS, TRANSP, URL)));
}

private ComponentList<VAlarm> alarms;

/**
Expand Down Expand Up @@ -354,7 +354,7 @@ public final void validate(final boolean recurse) throws ValidationException {
// throw new ValidationException("Component ["
// + component.getName() + "] may not occur in VEVENT");
// }
//
//
// ((VAlarm) component).validate(recurse);
// }

Expand Down Expand Up @@ -420,7 +420,7 @@ public final void validate(final boolean recurse) throws ValidationException {
if (start != null) {
final Parameter startValue = start.getParameter(Parameter.VALUE);
final Parameter endValue = end.getParameter(Parameter.VALUE);

boolean startEndValueMismatch = false;
if (endValue != null) {
if (startValue != null && !endValue.equals(startValue)) {
Expand Down Expand Up @@ -448,12 +448,12 @@ else if (startValue != null && !Value.DATE_TIME.equals(startValue)) {
* ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment /
* contact / exdate / exrule / rstatus / related / resources / rdate / rrule / x-prop
*/

if (recurse) {
validateProperties();
}
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -519,7 +519,7 @@ public final PeriodList getConsumedTime(final Date rangeStart,
*/
public final VEvent getOccurrence(final Date date) throws IOException,
URISyntaxException, ParseException {

final PeriodList consumedTime = getConsumedTime(date, date);
for (final Period p : consumedTime) {
if (p.getStart().equals(date)) {
Expand All @@ -530,7 +530,7 @@ public final VEvent getOccurrence(final Date date) throws IOException,
}
return null;
}

/**
* @return the optional access classification property for an event
*/
Expand Down

0 comments on commit eaa0285

Please sign in to comment.