01: /*
02: * Copyright 2003-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.collections.set;
17:
18: import java.util.Collection;
19: import java.util.Iterator;
20: import java.util.Set;
21:
22: import org.apache.commons.collections.Unmodifiable;
23: import org.apache.commons.collections.iterators.UnmodifiableIterator;
24:
25: /**
26: * Decorates another <code>Set</code> to ensure it can't be altered.
27: * <p>
28: * This class is Serializable from Commons Collections 3.1.
29: *
30: * @since Commons Collections 3.0
31: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
32: *
33: * @author Stephen Colebourne
34: */
35: public final class UnmodifiableSet extends
36: AbstractSerializableSetDecorator implements Unmodifiable {
37:
38: /** Serialization version */
39: private static final long serialVersionUID = 6499119872185240161L;
40:
41: /**
42: * Factory method to create an unmodifiable set.
43: *
44: * @param set the set to decorate, must not be null
45: * @throws IllegalArgumentException if set is null
46: */
47: public static Set decorate(Set set) {
48: if (set instanceof Unmodifiable) {
49: return set;
50: }
51: return new UnmodifiableSet(set);
52: }
53:
54: //-----------------------------------------------------------------------
55: /**
56: * Constructor that wraps (not copies).
57: *
58: * @param set the set to decorate, must not be null
59: * @throws IllegalArgumentException if set is null
60: */
61: private UnmodifiableSet(Set set) {
62: super (set);
63: }
64:
65: //-----------------------------------------------------------------------
66: public Iterator iterator() {
67: return UnmodifiableIterator
68: .decorate(getCollection().iterator());
69: }
70:
71: public boolean add(Object object) {
72: throw new UnsupportedOperationException();
73: }
74:
75: public boolean addAll(Collection coll) {
76: throw new UnsupportedOperationException();
77: }
78:
79: public void clear() {
80: throw new UnsupportedOperationException();
81: }
82:
83: public boolean remove(Object object) {
84: throw new UnsupportedOperationException();
85: }
86:
87: public boolean removeAll(Collection coll) {
88: throw new UnsupportedOperationException();
89: }
90:
91: public boolean retainAll(Collection coll) {
92: throw new UnsupportedOperationException();
93: }
94:
95: }
|