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.net.URI;
37 import java.net.URISyntaxException;
38 import java.util.ArrayList;
39 import java.util.Iterator;
40 import java.util.List;
41 import java.util.StringTokenizer;
42
43 import net.fortuna.ical4j.util.StringUtils;
44
45
46 /***
47 * Defines a list of iCalendar addresses.
48 * @author benfortuna
49 */
50 public class AddressList {
51
52 private List addresses;
53
54 /***
55 * Default constructor.
56 */
57 public AddressList() {
58 addresses = new ArrayList();
59 }
60
61 /***
62 * Parses the specified string representation to create
63 * a list of addresses.
64 * @param aValue a string representation of a list of
65 * addresses
66 * @throws URISyntaxException where the specified string
67 * is not a valid representation
68 */
69 public AddressList(final String aValue) throws URISyntaxException {
70 addresses = new ArrayList();
71
72 for (StringTokenizer t = new StringTokenizer(aValue, ","); t
73 .hasMoreTokens();) {
74 addresses.add(new URI(StringUtils.unquote(t.nextToken())));
75 }
76 }
77
78 /***
79 * @see java.util.AbstractCollection#toString()
80 */
81 public final String toString() {
82
83 StringBuffer b = new StringBuffer();
84
85 for (Iterator i = addresses.iterator(); i.hasNext();) {
86
87 b.append(StringUtils.quote(i.next()));
88
89 if (i.hasNext()) {
90 b.append(',');
91 }
92 }
93
94 return b.toString();
95 }
96
97 /***
98 * Add an address to the list.
99 * @param address the address to add
100 * @return true
101 * @see List#add(java.lang.Object)
102 */
103 public final boolean add(final URI address) {
104 return addresses.add(address);
105 }
106
107 /***
108 * @return boolean indicates if the list is empty
109 * @see List#isEmpty()
110 */
111 public final boolean isEmpty() {
112 return addresses.isEmpty();
113 }
114
115 /***
116 * @return an iterator
117 * @see List#iterator()
118 */
119 public final Iterator iterator() {
120 return addresses.iterator();
121 }
122
123 /***
124 * Remove an address from the list
125 * @param address the address to remove
126 * @return true if the list contained the specified address
127 * @see List#remove(java.lang.Object)
128 */
129 public final boolean remove(final URI address) {
130 return addresses.remove(address);
131 }
132
133 /***
134 * @return the number of addresses in the list
135 * @see List#size()
136 */
137 public final int size() {
138 return addresses.size();
139 }
140 }