Use case arrows in mergeIntoModifiedNode()
[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 static java.util.Objects.requireNonNull;
11
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  * @param <E> the type of elements held in this collection
25  */
26 public final class EmptyDeque<E> extends AbstractQueue<E> implements Deque<E>, Immutable {
27     private static final EmptyDeque<?> INSTANCE = new EmptyDeque<>();
28     private static final Object[] EMPTY_ARRAY = new Object[0];
29
30     private EmptyDeque() {
31         // No instances
32     }
33
34     @SuppressWarnings("unchecked")
35     public static <T> EmptyDeque<T> instance() {
36         return (EmptyDeque<T>) INSTANCE;
37     }
38
39     @Override
40     @SuppressWarnings("checkstyle:parameterName")
41     public boolean offer(final E e) {
42         return false;
43     }
44
45     @Override
46     @SuppressWarnings("checkstyle:parameterName")
47     public boolean offerFirst(final E e) {
48         return false;
49     }
50
51     @Override
52     @SuppressWarnings("checkstyle:parameterName")
53     public boolean offerLast(final E e) {
54         return false;
55     }
56
57     @Override
58     public E poll() {
59         return null;
60     }
61
62     @Override
63     public E pollFirst() {
64         return null;
65     }
66
67     @Override
68     public E pollLast() {
69         return null;
70     }
71
72     @Override
73     public E peek() {
74         return null;
75     }
76
77     @Override
78     public E peekFirst() {
79         return null;
80     }
81
82     @Override
83     public E peekLast() {
84         return null;
85     }
86
87     @Override
88     public Iterator<E> iterator() {
89         return Collections.emptyIterator();
90     }
91
92     @Override
93     public Spliterator<E> spliterator() {
94         return Spliterators.emptySpliterator();
95     }
96
97     @Override
98     public int size() {
99         return 0;
100     }
101
102     @Override
103     public Object[] toArray() {
104         return EMPTY_ARRAY;
105     }
106
107     @Override
108     @SuppressWarnings("checkstyle:parameterName")
109     public <T> T[] toArray(final T[] a) {
110         return requireNonNull(a);
111     }
112
113     @Override
114     @SuppressWarnings("checkstyle:parameterName")
115     public void addFirst(final E e) {
116         add(e);
117     }
118
119     @Override
120     @SuppressWarnings("checkstyle:parameterName")
121     public void addLast(final E e) {
122         add(e);
123     }
124
125     @Override
126     public E removeFirst() {
127         return remove();
128     }
129
130     @Override
131     public E removeLast() {
132         return remove();
133     }
134
135     @Override
136     public E getFirst() {
137         return element();
138     }
139
140     @Override
141     public E getLast() {
142         return element();
143     }
144
145     @Override
146     @SuppressWarnings("checkstyle:parameterName")
147     public boolean removeFirstOccurrence(final Object o) {
148         return false;
149     }
150
151     @Override
152     @SuppressWarnings("checkstyle:parameterName")
153     public boolean removeLastOccurrence(final Object o) {
154         return false;
155     }
156
157     @Override
158     @SuppressWarnings("checkstyle:parameterName")
159     public void push(final E e) {
160         addFirst(e);
161     }
162
163     @Override
164     public E pop() {
165         return removeFirst();
166     }
167
168     @Override
169     public Iterator<E> descendingIterator() {
170         return Collections.emptyIterator();
171     }
172 }