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.util.ArrayList;
37 import java.util.Iterator;
38 import java.util.List;
39
40 /***
41 * Defines a list of iCalendar properties.
42 *
43 * @author benf
44 */
45 public class PropertyList {
46
47 private List properties;
48
49 /***
50 * Constructor.
51 */
52 public PropertyList() {
53 properties = new ArrayList();
54 }
55
56 /***
57 * @see java.util.AbstractCollection#toString()
58 */
59 public final String toString() {
60
61 StringBuffer buffer = new StringBuffer();
62
63 for (Iterator i = properties.iterator(); i.hasNext();) {
64
65 buffer.append(i.next().toString());
66 }
67
68 return buffer.toString();
69 }
70
71 /***
72 * Returns the first property of specified name.
73 * @param aName name of property to return
74 * @return a property or null if no matching property found
75 */
76 public final Property getProperty(final String aName) {
77
78 for (Iterator i = properties.iterator(); i.hasNext();) {
79 Property p = (Property) i.next();
80
81 if (p.getName().equals(aName)) {
82 return p;
83 }
84 }
85
86 return null;
87 }
88
89 /***
90 * Returns a list of properties with the specified name.
91 * @param name
92 * name of properties to return
93 * @return a property list
94 */
95 public final PropertyList getProperties(final String name) {
96 PropertyList list = new PropertyList();
97
98 for (Iterator i = properties.iterator(); i.hasNext();) {
99 Property p = (Property) i.next();
100
101 if (p.getName().equals(name)) {
102 list.add(p);
103 }
104 }
105 return list;
106 }
107
108 /***
109 * Add a property to the list.
110 * @param property the property to add
111 * @return true
112 * @see List#add(java.lang.Object)
113 */
114 public final boolean add(final Property property) {
115 return properties.add(property);
116 }
117
118 /***
119 * @return boolean indicates if the list is empty
120 * @see List#isEmpty()
121 */
122 public final boolean isEmpty() {
123 return properties.isEmpty();
124 }
125
126 /***
127 * @return an iterator
128 * @see List#iterator()
129 */
130 public final Iterator iterator() {
131 return properties.iterator();
132 }
133
134 /***
135 * Remove a property from the list
136 * @param property the property to remove
137 * @return true if the list contained the specified property
138 * @see List#remove(java.lang.Object)
139 */
140 public final boolean remove(final Property property) {
141 return properties.remove(property);
142 }
143
144 /***
145 * @return the number of properties in the list
146 * @see List#size()
147 */
148 public final int size() {
149 return properties.size();
150 }
151 }