1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.webmancer.util.immutable;
22
23 import java.util.Collection;
24 import java.util.Iterator;
25
26
27
28
29
30 public final class ImmutableCollection<T> implements Collection<T> {
31 private Collection<? extends T> collection;
32
33
34
35
36 public ImmutableCollection(final Collection<? extends T> collection) {
37 super();
38 this.collection = collection;
39 }
40
41
42
43
44 public boolean containsAll(final Collection<?> c) {
45 return this.collection.containsAll(c);
46 }
47
48
49
50
51 public boolean contains(final Object o) {
52 return this.collection.contains(o);
53 }
54
55
56
57
58 @Override
59 public boolean equals(final Object o) {
60 return this.collection.equals(o);
61 }
62
63
64
65
66 @Override
67 public int hashCode() {
68 return this.collection.hashCode();
69 }
70
71
72
73
74 public boolean isEmpty() {
75 return this.collection.isEmpty();
76 }
77
78
79
80
81 public int size() {
82 return this.collection.size();
83 }
84
85
86
87
88 public <K> K[] toArray(final K[] a) {
89 return this.collection.toArray(a);
90 }
91
92
93
94
95 public Object[] toArray() {
96 return this.collection.toArray();
97 }
98
99
100
101
102 public Iterator<T> iterator() {
103 return new ImmutableIterator<T>(this.collection.iterator());
104 }
105
106
107
108
109 public boolean add(final T o) {
110 throw new UnsupportedOperationException("ImmutableCollection.add");
111 }
112
113
114
115
116 public boolean remove(final Object o) {
117 throw new UnsupportedOperationException("ImmutableCollection.remove");
118 }
119
120
121
122
123 public boolean addAll(final Collection<? extends T> c) {
124 throw new UnsupportedOperationException("ImmutableCollection.addAll");
125 }
126
127
128
129
130 public boolean removeAll(final Collection<?> c) {
131 throw new UnsupportedOperationException("ImmutableCollection.removeAll");
132 }
133
134
135
136
137 public boolean retainAll(final Collection<?> c) {
138 throw new UnsupportedOperationException("ImmutableCollection.retainAll");
139 }
140
141
142
143
144 public void clear() {
145 throw new UnsupportedOperationException("ImmutableCollection.clear");
146 }
147
148 }