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 components.
42 *
43 * @author benf
44 */
45 public class ComponentList {
46
47 private List components;
48
49 /***
50 * Constructor.
51 */
52 public ComponentList() {
53 components = 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 = components.iterator(); i.hasNext();) {
64
65 buffer.append(i.next().toString());
66 }
67
68 return buffer.toString();
69 }
70
71 /***
72 * Returns the first component of specified name.
73 * @param aName name of component to return
74 * @return a component or null if no matching component
75 * found
76 */
77 public final Component getComponent(final String aName) {
78
79 for (Iterator i = components.iterator(); i.hasNext();) {
80 Component c = (Component) i.next();
81
82 if (c.getName().equals(aName)) {
83 return c;
84 }
85 }
86
87 return null;
88 }
89
90 /***
91 * Add a component to the list.
92 * @param component the component to add
93 * @return true
94 * @see List#add(java.lang.Object)
95 */
96 public final boolean add(final Component component) {
97 return components.add(component);
98 }
99
100 /***
101 * @return boolean indicates if the list is empty
102 * @see List#isEmpty()
103 */
104 public final boolean isEmpty() {
105 return components.isEmpty();
106 }
107
108 /***
109 * @return an iterator
110 * @see List#iterator()
111 */
112 public final Iterator iterator() {
113 return components.iterator();
114 }
115
116 /***
117 * Remove a component from the list
118 * @param component the component to remove
119 * @return true if the list contained the specified component
120 * @see List#remove(java.lang.Object)
121 */
122 public final boolean remove(final Component component) {
123 return components.remove(component);
124 }
125
126 /***
127 * @return the number of components in the list
128 * @see List#size()
129 */
130 public final int size() {
131 return components.size();
132 }
133
134 /***
135 * Provides a list containing all components contained
136 * in this component list.
137 * @return a list
138 */
139 public final List toList() {
140 return new ArrayList(components);
141 }
142 }