001 package biweekly.property;
002
003 import java.util.Date;
004 import java.util.List;
005
006 import biweekly.Warning;
007 import biweekly.component.ICalComponent;
008 import biweekly.component.VTimezone;
009 import biweekly.util.ICalDateFormatter;
010 import biweekly.util.Period;
011
012 /*
013 Copyright (c) 2013, Michael Angstadt
014 All rights reserved.
015
016 Redistribution and use in source and binary forms, with or without
017 modification, are permitted provided that the following conditions are met:
018
019 1. Redistributions of source code must retain the above copyright notice, this
020 list of conditions and the following disclaimer.
021 2. Redistributions in binary form must reproduce the above copyright notice,
022 this list of conditions and the following disclaimer in the documentation
023 and/or other materials provided with the distribution.
024
025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
026 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
028 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
029 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
032 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
033 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
034 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
035 */
036
037 /**
038 * <p>
039 * Defines a list of dates or periods that help define a recurrence rule. It
040 * must contain either dates or time periods. It cannot contain a combination of
041 * both.
042 * </p>
043 * <p>
044 * <b>Examples:</b>
045 *
046 * <pre class="brush:java">
047 * //date-time values
048 * Date datetime1 = ...
049 * Date datetime2 = ...
050 * List<Date> datetimes = Arrays.asList(datetime1, datetime2);
051 * RecurrenceDates prop = new RecurrenceDates(datetimes, true);
052 *
053 * //date values
054 * Date date1 = ...
055 * Date date2 = ...
056 * List<Date> dates = Arrays.asList(date1, date2);
057 * RecurrenceDates prop = new RecurrenceDates(dates, false);
058 *
059 * //periods
060 * Period period1 = ...
061 * Period period2 = ...
062 * List<Period> periods = Arrays.asList(period1, period2);
063 * RecurrenceDates prop = new RecurrenceDates(periods, true);
064 * </pre>
065 *
066 * </p>
067 * @author Michael Angstadt
068 * @rfc 5545 p.120-2
069 */
070 public class RecurrenceDates extends ICalProperty {
071 private List<Date> dates;
072 private boolean hasTime;
073 private List<Period> periods;
074
075 /**
076 * Creates a recurrence dates property.
077 * @param dates the recurrence dates
078 * @param hasTime true if the dates have a time component, false if they are
079 * strictly dates
080 */
081 public RecurrenceDates(List<Date> dates, boolean hasTime) {
082 this.dates = dates;
083 this.hasTime = hasTime;
084 }
085
086 /**
087 * Creates a recurrence dates property.
088 * @param periods the time periods
089 */
090 public RecurrenceDates(List<Period> periods) {
091 this.periods = periods;
092 }
093
094 /**
095 * Gets the recurrence dates.
096 * @return the dates or null if this property contains periods
097 */
098 public List<Date> getDates() {
099 return dates;
100 }
101
102 /**
103 * Gets whether the recurrence dates have time components.
104 * @return true if the dates have a time component, false if they are
105 * strictly dates
106 */
107 public boolean hasTime() {
108 return hasTime;
109 }
110
111 /**
112 * Gets the time periods.
113 * @return the time periods or null if this property contains dates
114 */
115 public List<Period> getPeriods() {
116 return periods;
117 }
118
119 @Override
120 public String getTimezoneId() {
121 return super.getTimezoneId();
122 }
123
124 @Override
125 public void setTimezoneId(String timezoneId) {
126 super.setTimezoneId(timezoneId);
127 }
128
129 @Override
130 public void setTimezone(VTimezone timezone) {
131 super.setTimezone(timezone);
132 }
133
134 @Override
135 protected void validate(List<ICalComponent> components, List<Warning> warnings) {
136 String tzid = getTimezoneId();
137 if (tzid != null && tzid.contains("/") && ICalDateFormatter.parseTimeZoneId(tzid) == null) {
138 warnings.add(Warning.validate(27, tzid));
139 }
140 }
141 }