Package io.microsphere.collection
Class EmptyDeque<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- io.microsphere.collection.AbstractDeque<E>
-
- io.microsphere.collection.EmptyDeque<E>
-
- Type Parameters:
E
- The type of elements held in this deque
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Deque<E>
,java.util.Queue<E>
public class EmptyDeque<E> extends AbstractDeque<E> implements java.io.Serializable
An empty and immutableDeque
implementation that throwsUnsupportedOperationException
for methods that attempt to modify the deque, and returns appropriate default values for read-only operations.This class is a singleton implementation, and it's serializable. It's useful as a placeholder or default value where an empty deque is needed without creating a new instance every time.
Example Usage
Deque<String> deque = EmptyDeque.INSTANCE; // Reading from the deque System.out.println(deque.isEmpty()); // true System.out.println(deque.size()); // 0 // Iterating over elements (no output) for (String element : deque) { System.out.println(element); } // Attempting to modify will throw an exception try { deque.add("test"); } catch (UnsupportedOperationException e) { System.out.println("Modification not allowed: " + e.getMessage()); }
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
AbstractDeque
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static EmptyDeque<?>
INSTANCE
-
Constructor Summary
Constructors Constructor Description EmptyDeque()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<E>
descendingIterator()
E
getFirst()
E
getLast()
java.util.Iterator<E>
iterator()
boolean
offerFirst(E e)
boolean
offerLast(E e)
E
peekFirst()
E
peekLast()
E
pollFirst()
E
pollLast()
boolean
remove(java.lang.Object o)
boolean
removeLastOccurrence(java.lang.Object o)
int
size()
-
Methods inherited from class io.microsphere.collection.AbstractDeque
addFirst, addLast, offer, peek, poll, pop, push, removeFirst, removeFirstOccurrence, removeLast
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
INSTANCE
public static final EmptyDeque<?> INSTANCE
-
-
Method Detail
-
iterator
public java.util.Iterator<E> iterator()
-
descendingIterator
public java.util.Iterator<E> descendingIterator()
- Specified by:
descendingIterator
in interfacejava.util.Deque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrence
in interfacejava.util.Deque<E>
-
remove
public boolean remove(java.lang.Object o)
-
-