1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.osgi.service.importer.support.internal.collection;
17
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.Set;
21
22 /**
23 * Wrapper extension to {@link DynamicCollection} which prevents duplicates.
24 *
25 * @see DynamicCollection
26 * @see Set
27 * @author Costin Leau
28 *
29 */
30 public class DynamicSet extends DynamicCollection implements Set {
31
32
33 public DynamicSet() {
34 super();
35 }
36
37 public DynamicSet(Collection c) {
38 super(c);
39 }
40
41 public DynamicSet(int size) {
42 super(size);
43 }
44
45 public boolean add(Object o) {
46 synchronized (storage) {
47 if (storage.contains(o))
48 return false;
49 storage.add(o);
50 }
51 return true;
52 }
53
54 public boolean addAll(Collection c) {
55 if (c == null)
56 throw new NullPointerException();
57 boolean result = false;
58 synchronized (storage) {
59 for (Iterator iter = c.iterator(); iter.hasNext();) {
60 result |= add(iter.next());
61 }
62 }
63
64 return result;
65 }
66
67 }