Fix eclipse/checkstyle warnings
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / EmptyDeque.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import java.util.AbstractQueue;
13 import java.util.Collections;
14 import java.util.Deque;
15 import java.util.Iterator;
16 import java.util.Spliterator;
17 import java.util.Spliterators;
18 import org.opendaylight.yangtools.concepts.Immutable;
19
20 /**
21  * A specialized always-empty implementation of {@link java.util.Deque}. This implementation will always refuse new
22  * elements in its {@link #offer(Object)} method.
23
24  * @author Robert Varga
25  *
26  * @param <E> the type of elements held in this collection
27  */
28 @Beta
29 public final class EmptyDeque<E> extends AbstractQueue<E> implements Deque<E>, Immutable {
30     private static final EmptyDeque<?> INSTANCE = new EmptyDeque<>();
31     private static final Object[] EMPTY_ARRAY = new Object[0];
32
33     private EmptyDeque() {
34         // No instances
35     }
36
37     @SuppressWarnings("unchecked")
38     public static <T> EmptyDeque<T> instance() {
39         return (EmptyDeque<T>) INSTANCE;
40     }
41
42     @Override
43     @SuppressWarnings("checkstyle:parameterName")
44     public boolean offer(final E e) {
45         return false;
46     }
47
48     @Override
49     @SuppressWarnings("checkstyle:parameterName")
50     public boolean offerFirst(final E e) {
51         return false;
52     }
53
54     @Override
55     @SuppressWarnings("checkstyle:parameterName")
56     public boolean offerLast(final E e) {
57         return false;
58     }
59
60     @Override
61     public E poll() {
62         return null;
63     }
64
65     @Override
66     public E pollFirst() {
67         return null;
68     }
69
70     @Override
71     public E pollLast() {
72         return null;
73     }
74
75     @Override
76     public E peek() {
77         return null;
78     }
79
80     @Override
81     public E peekFirst() {
82         return null;
83     }
84
85     @Override
86     public E peekLast() {
87         return null;
88     }
89
90     @Override
91     public Iterator<E> iterator() {
92         return Collections.emptyIterator();
93     }
94
95     @Override
96     public Spliterator<E> spliterator() {
97         return Spliterators.emptySpliterator();
98     }
99
100     @Override
101     public int size() {
102         return 0;
103     }
104
105     @Override
106     public Object[] toArray() {
107         return EMPTY_ARRAY;
108     }
109
110     @Override
111     @SuppressWarnings("checkstyle:parameterName")
112     public <T> T[] toArray(final T[] a) {
113         return Preconditions.checkNotNull(a);
114     }
115
116     @Override
117     @SuppressWarnings("checkstyle:parameterName")
118     public void addFirst(final E e) {
119         add(e);
120     }
121
122     @Override
123     @SuppressWarnings("checkstyle:parameterName")
124     public void addLast(final E e) {
125         add(e);
126     }
127
128     @Override
129     public E removeFirst() {
130         return remove();
131     }
132
133     @Override
134     public E removeLast() {
135         return remove();
136     }
137
138     @Override
139     public E getFirst() {
140         return element();
141     }
142
143     @Override
144     public E getLast() {
145         return element();
146     }
147
148     @Override
149     @SuppressWarnings("checkstyle:parameterName")
150     public boolean removeFirstOccurrence(final Object o) {
151         return false;
152     }
153
154     @Override
155     @SuppressWarnings("checkstyle:parameterName")
156     public boolean removeLastOccurrence(final Object o) {
157         return false;
158     }
159
160     @Override
161     @SuppressWarnings("checkstyle:parameterName")
162     public void push(final E e) {
163         addFirst(e);
164     }
165
166     @Override
167     public E pop() {
168         return removeFirst();
169     }
170
171     @Override
172     public Iterator<E> descendingIterator() {
173         return Collections.emptyIterator();
174     }
175 }