E
- The type of the objects stored in this structure.public class FastSiblingDeque<E>
extends java.lang.Object
implements java.util.Deque<E>
Deque
with support for access of siblings of a particular element. It is logically
that, to uniquely identify the elements from this Collection
for querying its sibling
there must NOT be duplicated entries. The implementation prevents this by throwing
exceptions or returning false at any attempt to duplicate an entry.Modifier and Type | Class and Description |
---|---|
private static class |
FastSiblingDeque.FsdNode<E>
A node in double-linked list of
FastSiblingDeque . |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<E,FastSiblingDeque.FsdNode<E>> |
data
Internal data structure is a map for fast direct access to independent elements.
|
private FastSiblingDeque.FsdNode<E> |
first
The head of the deque.
|
private FastSiblingDeque.FsdNode<E> |
last
The tail of the deque.
|
Constructor and Description |
---|
FastSiblingDeque() |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Inserts the specified element into the queue represented by this deque (in other words, at
the tail of this deque) if it is possible to do so immediately without violating capacity
restrictions, returning
true upon success and throwing an
IllegalStateException if no space is currently available. |
boolean |
addAll(java.util.Collection<? extends E> c) |
void |
addFirst(E e) |
void |
addLast(E e) |
void |
clear() |
boolean |
contains(java.lang.Object o)
Returns
true if this deque contains the specified element. |
boolean |
containsAll(java.util.Collection<?> c) |
java.util.Iterator<E> |
descendingIterator() |
E |
element() |
E |
getFirst() |
E |
getLast() |
E |
getNext(E e)
Get the next element after
e . |
E |
getPrevious(E e)
Get the previous element before
e . |
boolean |
isEmpty()
Returns
true if this collection contains no elements. |
java.util.Iterator<E> |
iterator() |
static void |
main(java.lang.String[] args)
Quick testing.
|
boolean |
offer(E e) |
boolean |
offerFirst(E e) |
boolean |
offerLast(E e) |
E |
peek() |
E |
peekFirst()
Retrieves, but does not remove, the first element of this deque, or returns
null if
this deque is empty. |
E |
peekLast()
Retrieves, but does not remove, the last element of this deque, or returns
null if
this deque is empty. |
E |
poll() |
E |
pollFirst() |
E |
pollLast() |
E |
pop() |
void |
push(E e) |
E |
remove() |
boolean |
remove(java.lang.Object o)
Removes the first occurrence of the specified element from this deque.
|
boolean |
removeAll(java.util.Collection<?> c) |
E |
removeFirst() |
boolean |
removeFirstOccurrence(java.lang.Object o) |
E |
removeLast() |
boolean |
removeLastOccurrence(java.lang.Object o) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
private java.util.Map<E,FastSiblingDeque.FsdNode<E>> data
private FastSiblingDeque.FsdNode<E> first
private FastSiblingDeque.FsdNode<E> last
public E getNext(E e)
e
. If the collection is empty or the element is the last
one, then null
is returned.e
- An element from collection to obtain its next sibling.e
when iterating this collection.public E getPrevious(E e)
e
. If the collection is empty or the element is the
first one, then null
is returned.e
- An element from collection to obtain its previous sibling.e
when reverse iterating this collection.public E peekFirst()
null
if
this deque is empty.peekFirst
in interface java.util.Deque<E>
null
if this deque is emptypublic E peekLast()
null
if
this deque is empty.peekLast
in interface java.util.Deque<E>
null
if this deque is emptypublic boolean removeFirstOccurrence(java.lang.Object o)
removeFirstOccurrence
in interface java.util.Deque<E>
public boolean removeLastOccurrence(java.lang.Object o)
removeLastOccurrence
in interface java.util.Deque<E>
public boolean add(E e)
true
upon success and throwing an
IllegalStateException
if no space is currently available.
This method is equivalent to addLast(E)
.
add
in interface java.util.Collection<E>
add
in interface java.util.Deque<E>
add
in interface java.util.Queue<E>
e
- the element to addtrue
(as specified by Collection.add(E)
)java.lang.ClassCastException
- if the class of the specified element prevents it from being added to this dequepublic boolean offer(E e)
public E remove()
public E poll()
public E element()
public E peek()
public boolean remove(java.lang.Object o)
true
if this deque contained the specified element (or equivalently, if this
deque changed as a result of the call).remove
in interface java.util.Collection<E>
remove
in interface java.util.Deque<E>
o
- element to be removed from this deque, if presenttrue
if an element was removed as a result of this calljava.lang.ClassCastException
- if the class of the specified element is incompatible with this
structurepublic boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E>
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E>
public void clear()
clear
in interface java.util.Collection<E>
public boolean contains(java.lang.Object o)
true
if this deque contains the specified element.contains
in interface java.util.Collection<E>
contains
in interface java.util.Deque<E>
o
- element whose presence in this deque is to be testedtrue
if this deque contains the specified elementjava.lang.ClassCastException
- if the type of the specified element is incompatible with this dequepublic int size()
public boolean isEmpty()
true
if this collection contains no elements.isEmpty
in interface java.util.Collection<E>
true
if this collection contains no elementspublic java.util.Iterator<E> iterator()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
public java.util.Iterator<E> descendingIterator()
descendingIterator
in interface java.util.Deque<E>
public static void main(java.lang.String[] args)