View Javadoc

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.*;
23  import java.util.*;
24  
25  public class UnmodifiableSet implements Set, Serializable {
26  
27      // use serialVersionUID from JDK 1.2.2 for interoperability
28      private static final long serialVersionUID = 1820017752578914078L;
29  
30      protected Set c;
31  
32      public UnmodifiableSet(Set c)
33      {
34          if (c == null) {
35              throw new NullPointerException();
36          }
37          this.c = c;
38      }
39  
40      public int size()
41      {
42          return c.size();
43      }
44  
45      public boolean isEmpty()
46      {
47          return c.isEmpty();
48      }
49  
50      public boolean contains(Object o)
51      {
52          return c.contains(o);
53      }
54  
55      public Object[] toArray()
56      {
57          return c.toArray();
58      }
59  
60      public Object[] toArray(Object[] a)
61      {
62          return c.toArray(a);
63      }
64  
65      public String toString()
66      {
67          return c.toString();
68      }
69  
70      public Iterator iterator()
71      {
72          return new Iterator()
73          {
74              Iterator i = c.iterator();
75  
76              public boolean hasNext()
77              {
78                  return i.hasNext();
79              }
80  
81              public Object next()
82              {
83                  return i.next();
84              }
85  
86              public void remove()
87              {
88                  throw new UnsupportedOperationException();
89              }
90          };
91      }
92  
93      public boolean add(Object o)
94      {
95          throw new UnsupportedOperationException();
96      }
97  
98      public boolean remove(Object o)
99      {
100         throw new UnsupportedOperationException();
101     }
102 
103     public boolean containsAll(Collection coll)
104     {
105         return c.containsAll(coll);
106     }
107 
108     public boolean addAll(Collection coll)
109     {
110         throw new UnsupportedOperationException();
111     }
112 
113     public boolean removeAll(Collection coll)
114     {
115         throw new UnsupportedOperationException();
116     }
117 
118     public boolean retainAll(Collection coll)
119     {
120         throw new UnsupportedOperationException();
121     }
122 
123     public void clear()
124     {
125         throw new UnsupportedOperationException();
126     }
127 
128     public boolean equals(Object o)
129     {
130         return c.equals(o);
131     }
132 
133     public int hashCode()
134     {
135         return c.hashCode();
136     }
137 
138     // additional methods.
139 
140     /***
141      * This method is only used by the ControllerFactoryImpl
142      * to unwrap the unmodifiable Set and allow to
143      * modify the set via controllers
144      * 
145      * @return the modifiable set
146      */
147     public Set getModifiableSet()
148     {
149         return c;
150     }
151 }