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 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;
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 * @author Robert Varga
26 * @param <E> the type of elements held in this collection
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];
33 private EmptyDeque() {
37 @SuppressWarnings("unchecked")
38 public static <T> EmptyDeque<T> instance() {
39 return (EmptyDeque<T>) INSTANCE;
43 @SuppressWarnings("checkstyle:parameterName")
44 public boolean offer(final E e) {
49 @SuppressWarnings("checkstyle:parameterName")
50 public boolean offerFirst(final E e) {
55 @SuppressWarnings("checkstyle:parameterName")
56 public boolean offerLast(final E e) {
66 public E pollFirst() {
81 public E peekFirst() {
91 public Iterator<E> iterator() {
92 return Collections.emptyIterator();
96 public Spliterator<E> spliterator() {
97 return Spliterators.emptySpliterator();
106 public Object[] toArray() {
111 @SuppressWarnings("checkstyle:parameterName")
112 public <T> T[] toArray(final T[] a) {
113 return Preconditions.checkNotNull(a);
117 @SuppressWarnings("checkstyle:parameterName")
118 public void addFirst(final E e) {
123 @SuppressWarnings("checkstyle:parameterName")
124 public void addLast(final E e) {
129 public E removeFirst() {
134 public E removeLast() {
139 public E getFirst() {
149 @SuppressWarnings("checkstyle:parameterName")
150 public boolean removeFirstOccurrence(final Object o) {
155 @SuppressWarnings("checkstyle:parameterName")
156 public boolean removeLastOccurrence(final Object o) {
161 @SuppressWarnings("checkstyle:parameterName")
162 public void push(final E e) {
168 return removeFirst();
172 public Iterator<E> descendingIterator() {
173 return Collections.emptyIterator();