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.Serializable;
23  import java.util.Collection;
24  import java.util.Iterator;
25  import java.util.Set;
26  
27  public class UnmodifiableSet implements Set, Serializable {
28  
29      // use serialVersionUID from JDK 1.2.2 for interoperability
30      private static final long serialVersionUID = 1820017752578914078L;
31  
32      protected Set c;
33  
34      public UnmodifiableSet(Set c)
35      {
36          if (c == null) {
37              throw new NullPointerException();
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 o)
53      {
54          return c.contains(o);
55      }
56  
57      public Object[] toArray()
58      {
59          return c.toArray();
60      }
61  
62      public Object[] toArray(Object[] a)
63      {
64          return c.toArray(a);
65      }
66  
67      public String toString()
68      {
69          return c.toString();
70      }
71  
72      public Iterator iterator()
73      {
74          return new Iterator()
75          {
76              Iterator i = c.iterator();
77  
78              public boolean hasNext()
79              {
80                  return i.hasNext();
81              }
82  
83              public Object next()
84              {
85                  return i.next();
86              }
87  
88              public void remove()
89              {
90                  throw new UnsupportedOperationException();
91              }
92          };
93      }
94  
95      public boolean add(Object o)
96      {
97          throw new UnsupportedOperationException();
98      }
99  
100     public boolean remove(Object o)
101     {
102         throw new UnsupportedOperationException();
103     }
104 
105     public boolean containsAll(Collection coll)
106     {
107         return c.containsAll(coll);
108     }
109 
110     public boolean addAll(Collection coll)
111     {
112         throw new UnsupportedOperationException();
113     }
114 
115     public boolean removeAll(Collection coll)
116     {
117         throw new UnsupportedOperationException();
118     }
119 
120     public boolean retainAll(Collection coll)
121     {
122         throw new UnsupportedOperationException();
123     }
124 
125     public void clear()
126     {
127         throw new UnsupportedOperationException();
128     }
129 
130     public boolean equals(Object 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 getModifiableSet()
150     {
151         return c;
152     }
153 }