blob: c3bdb8a1032e059b4ad13d12496e4b259a4a60e6 [file] [log] [blame]
HIGUCHI Yuta9092db82016-01-03 18:45:01 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16package org.onlab.util;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Collection;
21import java.util.Deque;
22import java.util.Iterator;
23import java.util.Spliterator;
24import java.util.function.Consumer;
25import java.util.function.Predicate;
26import java.util.stream.Stream;
27import com.google.common.collect.Iterators;
28
29/**
30 * Unmodifiable view of the specified Deque.
31 */
32public class UnmodifiableDeque<E> implements Deque<E> {
33
34 private final Deque<E> deque;
35
36 UnmodifiableDeque(Deque<E> deque) {
37 this.deque = checkNotNull(deque);
38 }
39
40 /**
41 * Returns an unmodifiable view of the specified Deque.
42 *
43 * @param deque underlying {@link Deque} to use.
44 * @return unmodifiable view of {@code deque}
45 */
46 public static <T> Deque<T> unmodifiableDeque(Deque<T> deque) {
47 return new UnmodifiableDeque<T>(deque);
48 }
49
50 @Override
51 public void forEach(Consumer<? super E> action) {
52 deque.forEach(action);
53 }
54
55 @Override
56 public void addFirst(E e) {
57 throw new UnsupportedOperationException();
58 }
59
60 @Override
61 public boolean isEmpty() {
62 return deque.isEmpty();
63 }
64
65 @Override
66 public void addLast(E e) {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public Object[] toArray() {
72 return deque.toArray();
73 }
74
75 @Override
76 public boolean offerFirst(E e) {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override
81 public <T> T[] toArray(T[] a) {
82 return deque.toArray(a);
83 }
84
85 @Override
86 public boolean offerLast(E e) {
87 throw new UnsupportedOperationException();
88 }
89
90 @Override
91 public E removeFirst() {
92 throw new UnsupportedOperationException();
93 }
94
95 @Override
96 public E removeLast() {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public E pollFirst() {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
106 public E pollLast() {
107 throw new UnsupportedOperationException();
108 }
109
110 @Override
111 public E getFirst() {
112 return deque.getFirst();
113 }
114
115 @Override
116 public E getLast() {
117 return deque.getLast();
118 }
119
120 @Override
121 public E peekFirst() {
122 return deque.peekFirst();
123 }
124
125 @Override
126 public E peekLast() {
127 return deque.peekLast();
128 }
129
130 @Override
131 public boolean removeFirstOccurrence(Object o) {
132 throw new UnsupportedOperationException();
133 }
134
135 @Override
136 public boolean removeLastOccurrence(Object o) {
137 throw new UnsupportedOperationException();
138 }
139
140 @Override
141 public boolean containsAll(Collection<?> c) {
142 return deque.containsAll(c);
143 }
144
145 @Override
146 public boolean add(E e) {
147 throw new UnsupportedOperationException();
148 }
149
150 @Override
151 public boolean addAll(Collection<? extends E> c) {
152 throw new UnsupportedOperationException();
153 }
154
155 @Override
156 public boolean offer(E e) {
157 throw new UnsupportedOperationException();
158 }
159
160 @Override
161 public boolean removeAll(Collection<?> c) {
162 throw new UnsupportedOperationException();
163 }
164
165 @Override
166 public E remove() {
167 throw new UnsupportedOperationException();
168 }
169
170 @Override
171 public E poll() {
172 throw new UnsupportedOperationException();
173 }
174
175 @Override
176 public E element() {
177 return deque.element();
178 }
179
180 @Override
181 public boolean removeIf(Predicate<? super E> filter) {
182 throw new UnsupportedOperationException();
183 }
184
185 @Override
186 public E peek() {
187 return deque.peek();
188 }
189
190 @Override
191 public void push(E e) {
192 throw new UnsupportedOperationException();
193 }
194
195 @Override
196 public boolean retainAll(Collection<?> c) {
197 throw new UnsupportedOperationException();
198 }
199
200 @Override
201 public E pop() {
202 throw new UnsupportedOperationException();
203 }
204
205 @Override
206 public boolean remove(Object o) {
207 throw new UnsupportedOperationException();
208 }
209
210 @Override
211 public void clear() {
212 throw new UnsupportedOperationException();
213 }
214
215 @Override
216 public boolean equals(Object o) {
217 return deque.equals(o);
218 }
219
220 @Override
221 public boolean contains(Object o) {
222 return deque.contains(o);
223 }
224
225 @Override
226 public int size() {
227 return deque.size();
228 }
229
230 @Override
231 public Iterator<E> iterator() {
232 return Iterators.unmodifiableIterator(deque.iterator());
233 }
234
235 @Override
236 public Iterator<E> descendingIterator() {
237 return Iterators.unmodifiableIterator(deque.descendingIterator());
238 }
239
240 @Override
241 public int hashCode() {
242 return deque.hashCode();
243 }
244
245 @Override
246 public Spliterator<E> spliterator() {
247 return deque.spliterator();
248 }
249
250 @Override
251 public Stream<E> stream() {
252 return deque.stream();
253 }
254
255 @Override
256 public Stream<E> parallelStream() {
257 return deque.parallelStream();
258 }
259
260 @Override
261 public String toString() {
262 return deque.toString();
263 }
264}