1 /*
2 * File: ImmutableSet.java
3 * Created: 11-čen-06 8:31:34
4 *
5 * Copyright 2006 Michal Burda.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 package net.sf.webmancer.util.immutable;
22
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.Set;
26
27 /**
28 * @author Michal Burda
29 * @param <T>
30 */
31 public final class ImmutableSet<T> implements Set<T> {
32 /**
33 *
34 */
35 private Set<? extends T> set;
36
37 /**
38 *
39 */
40 public ImmutableSet(final Set<? extends T> set) {
41 super();
42 this.set = set;
43 }
44
45 /**
46 * @see java.util.Set#containsAll(java.util.Collection)
47 */
48 public boolean containsAll(final Collection<?> c) {
49 return this.set.containsAll(c);
50 }
51
52 /**
53 * @see java.util.Set#contains(java.lang.Object)
54 */
55 public boolean contains(final Object o) {
56 return this.set.contains(o);
57 }
58
59 /**
60 * @see java.util.Set#equals(java.lang.Object)
61 */
62 @Override
63 public boolean equals(final Object o) {
64 return this.set.equals(o);
65 }
66
67 /**
68 * @see java.util.Set#hashCode()
69 */
70 @Override
71 public int hashCode() {
72 return this.set.hashCode();
73 }
74
75 /**
76 * @see java.util.Set#isEmpty()
77 */
78 public boolean isEmpty() {
79 return this.set.isEmpty();
80 }
81
82 /**
83 * @see java.util.Set#size()
84 */
85 public int size() {
86 return this.set.size();
87 }
88
89 /**
90 * @see java.util.Set#toArray(T[])
91 */
92 public <K> K[] toArray(final K[] a) {
93 return this.set.toArray(a);
94 }
95
96 /**
97 * @see java.util.Set#toArray()
98 */
99 public Object[] toArray() {
100 return this.set.toArray();
101 }
102
103 /**
104 * @see java.util.Set#iterator()
105 */
106 public Iterator<T> iterator() {
107 return new ImmutableIterator<T>(this.set.iterator());
108 }
109
110 /**
111 * @see java.util.Set#add(E)
112 */
113 public boolean add(final T o) {
114 throw new UnsupportedOperationException("ImmutableSet.add");
115 }
116
117 /**
118 * @see java.util.Set#remove(java.lang.Object)
119 */
120 public boolean remove(final Object o) {
121 throw new UnsupportedOperationException("ImmutableSet.remove");
122 }
123
124 /**
125 * @see java.util.Set#addAll(java.util.Collection)
126 */
127 public boolean addAll(final Collection<? extends T> c) {
128 throw new UnsupportedOperationException("ImmutableSet.addAll");
129 }
130
131 /**
132 * @see java.util.Set#retainAll(java.util.Collection)
133 */
134 public boolean retainAll(final Collection<?> c) {
135 throw new UnsupportedOperationException("ImmutableSet.retainAll");
136 }
137
138 /**
139 * @see java.util.Set#removeAll(java.util.Collection)
140 */
141 public boolean removeAll(final Collection<?> c) {
142 throw new UnsupportedOperationException("ImmutableSet.removeAll");
143 }
144
145 /**
146 * @see java.util.Set#clear()
147 */
148 public void clear() {
149 throw new UnsupportedOperationException("ImmutableSet.clear");
150 }
151
152 }