BUG-5280: fix InversibleLock race
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / EmptyQueue.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.controller.cluster.access.client;
9
10 import com.google.common.annotations.Beta;
11 import java.util.AbstractQueue;
12 import java.util.Collections;
13 import java.util.Iterator;
14 import java.util.Queue;
15 import org.opendaylight.yangtools.concepts.Immutable;
16
17 /**
18  * A specialized always-empty implementation of {@link java.util.Queue}. This implementation will always refuse new
19  * elements in its {@link #offer(Object)} method.
20
21  * @author Robert Varga
22  *
23  * @param <E> the type of elements held in this collection
24  */
25 // TODO: move this class into yangtools.util
26 @Beta
27 public final class EmptyQueue<E> extends AbstractQueue<E> implements Immutable {
28     private static final EmptyQueue<?> INSTANCE = new EmptyQueue<>();
29
30     private EmptyQueue() {
31         // No instances
32     }
33
34     @SuppressWarnings("unchecked")
35     public static <T> Queue<T> getInstance() {
36         return (Queue<T>) INSTANCE;
37     }
38
39     @Override
40     public boolean offer(final E entry) {
41         return false;
42     }
43
44     @Override
45     public E poll() {
46         return null;
47     }
48
49     @Override
50     public E peek() {
51         return null;
52     }
53
54     @Override
55     public Iterator<E> iterator() {
56         return Collections.emptyIterator();
57     }
58
59     @Override
60     public int size() {
61         return 0;
62     }
63 }