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>
@Immutable public class SingletonDeque<E> extends AbstractDeque<E> implements java.io.Serializable
ADequeimplementation 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
UnsupportedOperationExceptionbecause 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()booleanequals(java.lang.Object o)EgetFirst()EgetLast()inthashCode()java.util.Iterator<E>iterator()booleanofferFirst(E e)booleanofferLast(E e)EpeekFirst()EpeekLast()EpollFirst()EpollLast()booleanremoveFirstOccurrence(java.lang.Object o)booleanremoveLastOccurrence(java.lang.Object o)intsize()-
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:
descendingIteratorin interfacejava.util.Deque<E>
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object o)
- Specified by:
removeFirstOccurrencein interfacejava.util.Deque<E>- Overrides:
removeFirstOccurrencein classAbstractDeque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrencein interfacejava.util.Deque<E>
-
size
public int size()
-
equals
public final boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Collection<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<E>- Overrides:
hashCodein classjava.lang.Object
-
-