2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.util;
10 import static java.util.Objects.requireNonNull;
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;
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.
24 * @param <E> the type of elements held in this collection
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];
30 private EmptyDeque() {
34 @SuppressWarnings("unchecked")
35 public static <T> EmptyDeque<T> instance() {
36 return (EmptyDeque<T>) INSTANCE;
40 @SuppressWarnings("checkstyle:parameterName")
41 public boolean offer(final E e) {
46 @SuppressWarnings("checkstyle:parameterName")
47 public boolean offerFirst(final E e) {
52 @SuppressWarnings("checkstyle:parameterName")
53 public boolean offerLast(final E e) {
63 public E pollFirst() {
78 public E peekFirst() {
88 public Iterator<E> iterator() {
89 return Collections.emptyIterator();
93 public Spliterator<E> spliterator() {
94 return Spliterators.emptySpliterator();
103 public Object[] toArray() {
108 @SuppressWarnings("checkstyle:parameterName")
109 public <T> T[] toArray(final T[] a) {
110 return requireNonNull(a);
114 @SuppressWarnings("checkstyle:parameterName")
115 public void addFirst(final E e) {
120 @SuppressWarnings("checkstyle:parameterName")
121 public void addLast(final E e) {
126 public E removeFirst() {
131 public E removeLast() {
136 public E getFirst() {
146 @SuppressWarnings("checkstyle:parameterName")
147 public boolean removeFirstOccurrence(final Object o) {
152 @SuppressWarnings("checkstyle:parameterName")
153 public boolean removeLastOccurrence(final Object o) {
158 @SuppressWarnings("checkstyle:parameterName")
159 public void push(final E e) {
165 return removeFirst();
169 public Iterator<E> descendingIterator() {
170 return Collections.emptyIterator();