View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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  package net.sf.ehcache.util;
18  
19  import java.util.Collection;
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.ListIterator;
23  
24  /***
25   * Wraps a set to provide a list interface.
26   * All list methods not application to set throws an
27   * {@link UnsupportedOperationException}
28   * @author Nabib El-Rahman
29   */
30  public class SetWrapperList implements List {
31  
32      /***
33       * Wrapped collection.
34       */
35      private final Collection delegate;
36  
37      /***
38       * Collection to delegate to.
39       * @param aDelegate delegate
40       */
41      public SetWrapperList(final Collection aDelegate) {
42         this.delegate = aDelegate;
43      }
44  
45      /***
46       * {@inheritDoc}
47       */
48      public final boolean add(final Object obj) {
49         return this.delegate.add(obj);
50      }
51  
52      /***
53       * Does not support List methods {@link UnsupportedOperationException}.
54       * @param index Index
55       * @param entry Entry
56       */
57      public final void add(final int index, final Object entry) {
58        throw new UnsupportedOperationException(
59           "Delegates to set, operation not supported");
60      }
61  
62      /***
63       * {@inheritDoc}
64       */
65      public final boolean addAll(final Collection coll) {
66        return this.delegate.addAll(coll);
67      }
68  
69      /***
70       * Does not support List methods {@link UnsupportedOperationException}.
71       * @param index Index
72       * @param coll Collection
73       * @return boolean
74       */
75      public final boolean addAll(final int index, final Collection coll) {
76         throw new UnsupportedOperationException(
77            "Delegates to set, operation not supported");
78      }
79  
80      /***
81       * {@inheritDoc}
82       */
83      public final void clear() {
84        this.delegate.clear();
85      }
86  
87      /***
88       * {@inheritDoc}
89       */
90      public final boolean contains(final Object obj) {
91        return this.delegate.contains(obj);
92      }
93  
94      /***
95       * {@inheritDoc}
96       */
97      public final boolean containsAll(final Collection coll) {
98        return this.delegate.containsAll(coll);
99      }
100 
101     /***
102      * Does not support List methods {@link UnsupportedOperationException}.
103      * @param index Index
104      * @return Object
105      */
106     public final Object get(final int index) {
107       throw new UnsupportedOperationException(
108           "Delegates to set, operation not supported");
109     }
110 
111     /***
112      * Does not support List methods {@link UnsupportedOperationException}.
113      * @param object Object
114      * @return integer
115      */
116      public final int indexOf(final Object object) {
117        throw new UnsupportedOperationException(
118           "Delegates to set, operation not supported");
119      }
120 
121     /***
122      * {@inheritDoc}
123      */
124     public final boolean isEmpty() {
125       return this.delegate.isEmpty();
126     }
127 
128     /***
129      * {@inheritDoc}
130      */
131     public final Iterator iterator() {
132       return this.delegate.iterator();
133     }
134 
135     /***
136      * Does not support List methods {@link UnsupportedOperationException}.
137      * @param object Object
138      * @return integer
139      */
140     public final int lastIndexOf(final Object object) {
141       throw new UnsupportedOperationException(
142           "Delegates to set, operation not supported");
143     }
144 
145     /***
146      * Does not support List methods {@link UnsupportedOperationException}.
147      * @return ListIterator
148      */
149     public final ListIterator listIterator() {
150       throw new UnsupportedOperationException(
151          "Delegates to set, operation not supported");
152     }
153 
154     /***
155      * Does not support List methods {@link UnsupportedOperationException}.
156      * @param index Index
157      * @return ListIterator
158      */
159     public final ListIterator listIterator(final int index) {
160        throw new UnsupportedOperationException(
161           "Delegates to set, operation not supported");
162     }
163 
164     /***
165      * {@inheritDoc}
166      */
167     public final boolean remove(final Object obj) {
168       return this.delegate.remove(obj);
169     }
170 
171     /***
172      * Does not support List methods {@link UnsupportedOperationException}.
173      * @param index Index
174      * @return Object
175      */
176     public final Object remove(final int index) {
177       throw new UnsupportedOperationException(
178         "Delegates to set, operation not supported");
179     }
180 
181     /***
182      * {@inheritDoc}
183      */
184     public final boolean removeAll(final Collection coll) {
185        return this.delegate.removeAll(coll);
186     }
187 
188     /***
189      * {@inheritDoc}
190      */
191     public final boolean retainAll(final Collection coll) {
192        return this.delegate.retainAll(coll);
193     }
194 
195     /***
196      * Does not support List methods {@link UnsupportedOperationException}.
197      * @param index Index
198      * @param object Object
199      * @return Object
200      */
201     public final Object set(final int index, final Object object) {
202       throw new UnsupportedOperationException(
203         "Delegates to set, operation not supported");
204     }
205 
206     /***
207      * {@inheritDoc}
208      */
209     public final  int size() {
210       return this.delegate.size();
211     }
212 
213     /***
214      * Does not support List methods {@link UnsupportedOperationException}.
215      * @param start Start
216      * @param offset Offset
217      * @return List
218      */
219     public final List subList(final int start, final int offset) {
220        throw new UnsupportedOperationException(
221           "Delegates to set, operation not supported");
222     }
223 
224     /***
225      * {@inheritDoc}
226      */
227     public final Object[] toArray() {
228        return this.delegate.toArray();
229     }
230 
231     /***
232      * {@inheritDoc}
233      */
234     public final Object[] toArray(final Object[] arr) {
235        return this.delegate.toArray(arr);
236     }
237 
238 }