Package io.microsphere.collection
Class SingletonDeque<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- io.microsphere.collection.AbstractDeque<E>
-
- io.microsphere.collection.SingletonDeque<E>
-
- Type Parameters:
E
- The type of the singleton element 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 SingletonDeque<E> extends AbstractDeque<E> implements java.io.Serializable
ADeque
implementation that holds a single, immutable element.This class provides a lightweight, read-only deque structure containing exactly one element. All operations that attempt to modify the deque (e.g., add, remove, poll) will throw an
UnsupportedOperationException
because the deque is designed to be immutable.Example Usage
SingletonDeque<String> deque = new SingletonDeque<>("Hello"); System.out.println(deque.getFirst()); // Output: Hello System.out.println(deque.getLast()); // Output: Hello System.out.println(deque.size()); // Output: 1 try { deque.addFirst("World"); } catch (UnsupportedOperationException e) { System.out.println("Modification not allowed"); } Iterator<String> it = deque.iterator(); while (it.hasNext()) { System.out.println(it.next()); // Output: Hello }
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
AbstractDeque
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SingletonDeque(E element)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<E>
descendingIterator()
boolean
equals(java.lang.Object o)
E
getFirst()
E
getLast()
int
hashCode()
java.util.Iterator<E>
iterator()
boolean
offerFirst(E e)
boolean
offerLast(E e)
E
peekFirst()
E
peekLast()
E
pollFirst()
E
pollLast()
boolean
removeFirstOccurrence(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, removeLast
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
SingletonDeque
public SingletonDeque(E element)
-
-
Method Detail
-
iterator
public java.util.Iterator<E> iterator()
-
descendingIterator
public java.util.Iterator<E> descendingIterator()
- Specified by:
descendingIterator
in interfacejava.util.Deque<E>
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object o)
- Specified by:
removeFirstOccurrence
in interfacejava.util.Deque<E>
- Overrides:
removeFirstOccurrence
in classAbstractDeque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrence
in interfacejava.util.Deque<E>
-
size
public int size()
-
equals
public final boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Collection<E>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Collection<E>
- Overrides:
hashCode
in classjava.lang.Object
-
-