~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/util/SetAsList.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  Copyright 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
import java.util.Set;
 
24
 
 
25
/**
 
26
 * Wraps a set to provide a list interface.
 
27
 * All list methods not application to set throws an {@link UnsupportedOperationException}
 
28
 *
 
29
 * @author Chris Dennis
 
30
 * @param <E>
 
31
 */
 
32
public class SetAsList<E> implements List<E> {
 
33
 
 
34
    private final Set<E> set;
 
35
    private transient Object[] array;
 
36
 
 
37
    /**
 
38
     * @param set
 
39
     */
 
40
    public SetAsList(Set<E> set) {
 
41
        this.set = set;
 
42
    }
 
43
 
 
44
    /**
 
45
     * {@inheritDoc}
 
46
     */
 
47
    public int size() {
 
48
        return set.size();
 
49
    }
 
50
 
 
51
    /**
 
52
     * {@inheritDoc}
 
53
     */
 
54
    public boolean isEmpty() {
 
55
        return set.isEmpty();
 
56
    }
 
57
 
 
58
    /**
 
59
     * {@inheritDoc}
 
60
     */
 
61
    public boolean contains(Object o) {
 
62
        return set.contains(o);
 
63
    }
 
64
 
 
65
    /**
 
66
     * {@inheritDoc}
 
67
     */
 
68
    public Iterator<E> iterator() {
 
69
        return set.iterator();
 
70
    }
 
71
 
 
72
    /**
 
73
     * {@inheritDoc}
 
74
     */
 
75
    public Object[] toArray() {
 
76
        return set.toArray();
 
77
    }
 
78
 
 
79
    /**
 
80
     * {@inheritDoc}
 
81
     */
 
82
    public <T> T[] toArray(T[] a) {
 
83
        return set.toArray(a);
 
84
    }
 
85
 
 
86
    /**
 
87
     * {@inheritDoc}
 
88
     */
 
89
    public boolean add(E e) {
 
90
        return set.add(e);
 
91
    }
 
92
 
 
93
    /**
 
94
     * {@inheritDoc}
 
95
     */
 
96
    public boolean remove(Object o) {
 
97
        return set.remove(o);
 
98
    }
 
99
 
 
100
    /**
 
101
     * {@inheritDoc}
 
102
     */
 
103
    public boolean containsAll(Collection<?> c) {
 
104
        return set.containsAll(c);
 
105
    }
 
106
 
 
107
    /**
 
108
     * {@inheritDoc}
 
109
     */
 
110
    public boolean addAll(Collection<? extends E> c) {
 
111
        return set.addAll(c);
 
112
    }
 
113
 
 
114
    /**
 
115
     * Does not support List methods {@link UnsupportedOperationException}.
 
116
     */
 
117
    public boolean addAll(int index, Collection<? extends E> c) {
 
118
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
119
    }
 
120
 
 
121
    /**
 
122
     * {@inheritDoc}
 
123
     */
 
124
    public boolean removeAll(Collection<?> c) {
 
125
        return set.removeAll(c);
 
126
    }
 
127
 
 
128
    /**
 
129
     * {@inheritDoc}
 
130
     */
 
131
    public boolean retainAll(Collection<?> c) {
 
132
        return set.retainAll(c);
 
133
    }
 
134
 
 
135
    /**
 
136
     * {@inheritDoc}
 
137
     */
 
138
    public void clear() {
 
139
        set.clear();
 
140
    }
 
141
 
 
142
    /**
 
143
     * Does not support List methods {@link UnsupportedOperationException}.
 
144
     *
 
145
     * @param index Index
 
146
     */
 
147
    public E get(int index) {
 
148
        if (this.array == null) {
 
149
            this.array = toArray();
 
150
        }
 
151
        if (array.length <= index) {
 
152
            throw new IndexOutOfBoundsException();
 
153
        }
 
154
        return (E) this.array[index];
 
155
    }
 
156
 
 
157
    /**
 
158
     * Does not support List methods {@link UnsupportedOperationException}.
 
159
     */
 
160
    public E set(int index, E element) {
 
161
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
162
    }
 
163
 
 
164
    /**
 
165
     * Does not support List methods {@link UnsupportedOperationException}.
 
166
     */
 
167
    public void add(int index, E element) {
 
168
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
169
    }
 
170
 
 
171
    /**
 
172
     * Does not support List methods {@link UnsupportedOperationException}.
 
173
     */
 
174
    public E remove(int index) {
 
175
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
176
    }
 
177
 
 
178
    /**
 
179
     * Does not support List methods {@link UnsupportedOperationException}.
 
180
     */
 
181
    public int indexOf(Object o) {
 
182
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
183
    }
 
184
 
 
185
    /**
 
186
     * Does not support List methods {@link UnsupportedOperationException}.
 
187
     */
 
188
    public int lastIndexOf(Object o) {
 
189
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
190
    }
 
191
 
 
192
    /**
 
193
     * Does not support List methods {@link UnsupportedOperationException}.
 
194
     */
 
195
    public ListIterator<E> listIterator() {
 
196
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
197
    }
 
198
 
 
199
    /**
 
200
     * Does not support List methods {@link UnsupportedOperationException}.
 
201
     */
 
202
    public ListIterator<E> listIterator(int index) {
 
203
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
204
    }
 
205
 
 
206
    /**
 
207
     * Does not support List methods {@link UnsupportedOperationException}.
 
208
     */
 
209
    public List<E> subList(int fromIndex, int toIndex) {
 
210
        throw new UnsupportedOperationException("Delegates to set, operation not supported");
 
211
    }
 
212
}