KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > common > impl > 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 /*
17
18  */

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

142     /**
143      * This method is only used by the ControllerFactoryImpl
144      * to unwrap the unmodifiable Set and allow to
145      * modify the set via controllers
146      *
147      * @return the modifiable set
148      */

149     public Set JavaDoc getModifiableSet()
150     {
151         return c;
152     }
153 }
154
Popular Tags