1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package net.fortuna.ical4j.model;
35
36 import java.text.ParseException;
37 import java.util.ArrayList;
38 import java.util.Iterator;
39 import java.util.List;
40 import java.util.StringTokenizer;
41
42 /***
43 * Defines a list of iCalendar periods.
44 * @author benfortuna
45 */
46 public class PeriodList {
47
48 private List periods;
49
50 /***
51 * Default constructor.
52 */
53 public PeriodList() {
54 periods = new ArrayList();
55 }
56
57 /***
58 * Parses the specified string representation to create
59 * a list of periods.
60 * @param aValue a string representation of a list of
61 * periods
62 * @throws ParseException thrown when an invalid string
63 * representation of a period list is specified
64 */
65 public PeriodList(final String aValue) throws ParseException {
66 periods = new ArrayList();
67
68 for (StringTokenizer t = new StringTokenizer(aValue, ","); t
69 .hasMoreTokens();) {
70 periods.add(new Period(t.nextToken()));
71 }
72 }
73
74 /***
75 * @see java.util.AbstractCollection#toString()
76 */
77 public final String toString() {
78
79 StringBuffer b = new StringBuffer();
80
81 for (Iterator i = periods.iterator(); i.hasNext();) {
82
83 b.append(((Period) i.next()).toString());
84
85 if (i.hasNext()) {
86 b.append(',');
87 }
88 }
89
90 return b.toString();
91 }
92
93 /***
94 * Add a period to the list.
95 * @param period the period to add
96 * @return true
97 * @see List#add(java.lang.Object)
98 */
99 public final boolean add(final Period period) {
100 return periods.add(period);
101 }
102
103 /***
104 * @return boolean indicates if the list is empty
105 * @see List#isEmpty()
106 */
107 public final boolean isEmpty() {
108 return periods.isEmpty();
109 }
110
111 /***
112 * @return an iterator
113 * @see List#iterator()
114 */
115 public final Iterator iterator() {
116 return periods.iterator();
117 }
118
119 /***
120 * Remove a period from the list
121 * @param period the period to remove
122 * @return true if the list contained the specified period
123 * @see List#remove(java.lang.Object)
124 */
125 public final boolean remove(final Period period) {
126 return periods.remove(period);
127 }
128
129 /***
130 * @return the number of periods in the list
131 * @see List#size()
132 */
133 public final int size() {
134 return periods.size();
135 }
136 }