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