KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > common > UnmodifiableSet


1 /*
2  * Copyright 2004,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.cocoon.portal.pluto.om.common;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 /**
24  *
25  *
26  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
27  *
28  * @version CVS $Id: UnmodifiableSet.java 123407 2004-12-27 13:51:59Z cziegeler $
29  */

30 public class UnmodifiableSet implements Set JavaDoc, Serializable JavaDoc {
31
32     // use serialVersionUID from JDK 1.2.2 for interoperability
33
private static final long serialVersionUID = 1820017752578914078L;
34
35     protected Set JavaDoc c;
36
37     public UnmodifiableSet(Set JavaDoc c) {
38         if (c == null) {
39             throw new NullPointerException JavaDoc();
40         }
41         this.c = c;
42     }
43
44     public int size() {
45         return c.size();
46     }
47
48     public boolean isEmpty() {
49         return c.isEmpty();
50     }
51
52     public boolean contains(Object JavaDoc o) {
53         return c.contains(o);
54     }
55
56     public Object JavaDoc[] toArray() {
57         return c.toArray();
58     }
59
60     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
61         return c.toArray(a);
62     }
63
64     public String JavaDoc toString() {
65         return c.toString();
66     }
67
68     public Iterator JavaDoc iterator() {
69         return new Iterator JavaDoc() {
70             Iterator JavaDoc i = c.iterator();
71
72             public boolean hasNext() {
73                 return i.hasNext();
74             }
75
76             public Object JavaDoc next() {
77                 return i.next();
78             }
79
80             public void remove() {
81                 throw new UnsupportedOperationException JavaDoc();
82             }
83         };
84     }
85
86     public boolean add(Object JavaDoc o) {
87         throw new UnsupportedOperationException JavaDoc();
88     }
89
90     public boolean remove(Object JavaDoc o) {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94     public boolean containsAll(Collection JavaDoc coll) {
95         return c.containsAll(coll);
96     }
97
98     public boolean addAll(Collection JavaDoc coll) {
99         throw new UnsupportedOperationException JavaDoc();
100     }
101
102     public boolean removeAll(Collection JavaDoc coll) {
103         throw new UnsupportedOperationException JavaDoc();
104     }
105
106     public boolean retainAll(Collection JavaDoc coll) {
107         throw new UnsupportedOperationException JavaDoc();
108     }
109
110     public void clear() {
111         throw new UnsupportedOperationException JavaDoc();
112     }
113
114     public boolean equals(Object JavaDoc o) {
115         return c.equals(o);
116     }
117
118     public int hashCode() {
119         return c.hashCode();
120     }
121
122     // additional methods.
123

124     /**
125      * This method is only used by the ControllerFactoryImpl
126      * to unwrap the unmodifiable Set and allow to
127      * modify the set via controllers
128      *
129      * @return the modifiable set
130      */

131     public Set JavaDoc getModifiableSet() {
132         return c;
133     }
134 }
135
Popular Tags