KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > set > UnmodifiableSet


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Set JavaDoc;
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: 1.7 $ $Date: 2004/06/03 22:02:13 $
32  *
33  * @author Stephen Colebourne
34  */

35 public final class UnmodifiableSet
36         extends AbstractSerializableSetDecorator
37         implements Unmodifiable {
38
39     /** Serialization version */
40     private static final long serialVersionUID = 6499119872185240161L;
41
42     /**
43      * Factory method to create an unmodifiable set.
44      *
45      * @param set the set to decorate, must not be null
46      * @throws IllegalArgumentException if set is null
47      */

48     public static Set JavaDoc decorate(Set JavaDoc set) {
49         if (set instanceof Unmodifiable) {
50             return set;
51         }
52         return new UnmodifiableSet(set);
53     }
54
55     //-----------------------------------------------------------------------
56
/**
57      * Constructor that wraps (not copies).
58      *
59      * @param set the set to decorate, must not be null
60      * @throws IllegalArgumentException if set is null
61      */

62     private UnmodifiableSet(Set JavaDoc set) {
63         super(set);
64     }
65
66     //-----------------------------------------------------------------------
67
public Iterator JavaDoc iterator() {
68         return UnmodifiableIterator.decorate(getCollection().iterator());
69     }
70
71     public boolean add(Object JavaDoc object) {
72         throw new UnsupportedOperationException JavaDoc();
73     }
74
75     public boolean addAll(Collection JavaDoc coll) {
76         throw new UnsupportedOperationException JavaDoc();
77     }
78
79     public void clear() {
80         throw new UnsupportedOperationException JavaDoc();
81     }
82
83     public boolean remove(Object JavaDoc object) {
84         throw new UnsupportedOperationException JavaDoc();
85     }
86
87     public boolean removeAll(Collection JavaDoc coll) {
88         throw new UnsupportedOperationException JavaDoc();
89     }
90
91     public boolean retainAll(Collection JavaDoc coll) {
92         throw new UnsupportedOperationException JavaDoc();
93     }
94
95 }
96
Popular Tags