Class PriorityDeque<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- org.rossonet.ext.utils.concurrent.PriorityDeque<E>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.Deque<E>,java.util.Queue<E>
public class PriorityDeque<E> extends java.util.AbstractQueue<E> implements java.util.Deque<E>, java.io.Serializable- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PriorityDeque()PriorityDeque(int initialCapacity)PriorityDeque(int initialCapacity, java.util.Comparator<? super E> comparator)PriorityDeque(java.util.Collection<? extends E> c)PriorityDeque(java.util.SortedSet<? extends E> c)PriorityDeque(PriorityDeque<? extends E> c)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFirst(E e)voidaddLast(E e)voidclear()java.util.Comparator<? super E>comparator()Returns the comparator used to order the elements in this queue, ornullif this queue is sorted according to the natural ordering of its elements.booleancontains(java.lang.Object o)Returnstrueif this queue contains the specified element.java.util.Iterator<E>descendingIterator()EgetFirst()EgetLast()java.util.Iterator<E>iterator()booleanoffer(E element)booleanofferFirst(E e)booleanofferLast(E e)Epeek()EpeekFirst()EpeekLast()Epoll()EpollFirst()EpollLast()Epop()voidpush(E e)Eremove()booleanremove(java.lang.Object o)Removes a single instance of the specified element from this queue, if it is present.EremoveFirst()booleanremoveFirstOccurrence(java.lang.Object o)EremoveLast()booleanremoveLastOccurrence(java.lang.Object o)intsize()java.lang.Object[]toArray()Returns an array containing all of the elements in this queue.<T> T[]toArray(T[] a)Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
PriorityDeque
public PriorityDeque()
-
PriorityDeque
public PriorityDeque(java.util.Collection<? extends E> c)
-
PriorityDeque
public PriorityDeque(int initialCapacity)
-
PriorityDeque
public PriorityDeque(int initialCapacity, java.util.Comparator<? super E> comparator)
-
PriorityDeque
public PriorityDeque(PriorityDeque<? extends E> c)
-
PriorityDeque
public PriorityDeque(java.util.SortedSet<? extends E> c)
-
-
Method Detail
-
clear
public void clear()
-
comparator
public java.util.Comparator<? super E> comparator()
Returns the comparator used to order the elements in this queue, ornullif this queue is sorted according to the natural ordering of its elements.- Returns:
- the comparator used to order this queue, or
nullif this queue is sorted according to the natural ordering of its elements
-
contains
public boolean contains(java.lang.Object o)
Returnstrueif this queue contains the specified element. More formally, returnstrueif and only if this queue contains at least one elementesuch thato.equals(e).- Specified by:
containsin interfacejava.util.Collection<E>- Specified by:
containsin interfacejava.util.Deque<E>- Overrides:
containsin classjava.util.AbstractCollection<E>- Parameters:
o- object to be checked for containment in this queue- Returns:
trueif this queue contains the specified element
-
descendingIterator
public java.util.Iterator<E> descendingIterator()
- Specified by:
descendingIteratorin interfacejava.util.Deque<E>
-
iterator
public java.util.Iterator<E> iterator()
-
offer
public boolean offer(E element)
-
peek
public E peek()
-
poll
public E poll()
-
remove
public E remove()
-
remove
public boolean remove(java.lang.Object o)
Removes a single instance of the specified element from this queue, if it is present. More formally, removes an elementesuch thato.equals(e), if this queue contains one or more such elements. Returnstrueif and only if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).
-
removeFirstOccurrence
public boolean removeFirstOccurrence(java.lang.Object o)
- Specified by:
removeFirstOccurrencein interfacejava.util.Deque<E>
-
removeLastOccurrence
public boolean removeLastOccurrence(java.lang.Object o)
- Specified by:
removeLastOccurrencein interfacejava.util.Deque<E>
-
size
public int size()
-
toArray
public java.lang.Object[] toArray()
Returns an array containing all of the elements in this queue. The elements are in no particular order.The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
-
toArray
public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array. The returned array elements are in no particular order. If the queue fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this queue.If the queue fits in the specified array with room to spare (i.e., the array has more elements than the queue), the element in the array immediately following the end of the collection is set to
null.Like the
toArray()method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.Suppose x is a queue known to contain only strings. The following code can be used to dump the queue into a newly allocated array of String:
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().- Specified by:
toArrayin interfacejava.util.Collection<E>- Overrides:
toArrayin classjava.util.AbstractCollection<E>- Parameters:
a- the array into which the elements of the queue are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing all of the elements in this queue
- Throws:
java.lang.ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of every element in this queuejava.lang.NullPointerException- if the specified array is null
-
-