1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.collections15.set;
17
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.Set;
21
22 import net.sf.collections15.Unmodifiable;
23 import net.sf.collections15.iterators.UnmodifiableIterator;
24
25
26 /***
27 * Decorates another <code>Set</code> to ensure it can't be altered.
28 * <p>
29 * This class is Serializable from Commons Collections 3.1.
30 *
31 * @since Commons Collections 3.0
32 * @version $Revision: 1.1 $ $Date: 2005/05/03 22:45:38 $
33 *
34 * @author Stephen Colebourne
35 */
36 public final class UnmodifiableSet<E>
37 extends AbstractSerializableSetDecorator<E>
38 implements Unmodifiable {
39
40 /*** Serialization version */
41 private static final long serialVersionUID = 3835152865663793205L;
42
43 /***
44 * Factory method to create an unmodifiable set.
45 *
46 * @param set the set to decorate, must not be null
47 * @throws IllegalArgumentException if set is null
48 */
49 public static <T> Set<T> decorate(Set<T> set) {
50 if (set instanceof Unmodifiable) {
51 return set;
52 }
53 return new UnmodifiableSet<T>(set);
54 }
55
56
57 /***
58 * Constructor that wraps (not copies).
59 *
60 * @param set the set to decorate, must not be null
61 * @throws IllegalArgumentException if set is null
62 */
63 private UnmodifiableSet(Set<E> set) {
64 super(set);
65 }
66
67
68 public Iterator<E> iterator() {
69 return UnmodifiableIterator.<E>decorate(getCollection().iterator());
70 }
71
72 public boolean add(E object) {
73 throw new UnsupportedOperationException();
74 }
75
76 public boolean addAll(Collection<? extends E> coll) {
77 throw new UnsupportedOperationException();
78 }
79
80 public void clear() {
81 throw new UnsupportedOperationException();
82 }
83
84 public boolean remove(Object object) {
85 throw new UnsupportedOperationException();
86 }
87
88 public boolean removeAll(Collection<?> coll) {
89 throw new UnsupportedOperationException();
90 }
91
92 public boolean retainAll(Collection<?> coll) {
93 throw new UnsupportedOperationException();
94 }
95
96 }