Package gov.usgs.earthquake.util
Class RoundRobinQueue<T>
java.lang.Object
gov.usgs.earthquake.util.RoundRobinQueue<T>
- Type Parameters:
T- type of object being queued.
- All Implemented Interfaces:
Iterable<T>,Collection<T>,Queue<T>
- Direct Known Subclasses:
RoundRobinBlockingQueue
An abstract base class for round-robin queueing.
Sub classes should implement the
getQueueId(Object) to control how
objects are added to queues.-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.RoundRobinQueue(RoundRobinQueue<T> that) Deep copy of another RoundRobinQueue. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an item to the queue.booleanaddAll(Collection<? extends T> c) ======================= COLLECTION METHODS =========================voidclear()booleanbooleancontainsAll(Collection<?> c) element()Retrieves, but does not remove, the head of this queue.protected StringgetQueueId(T object) This method determines which queue an object uses.booleanisEmpty()iterator()booleanAdd an item to the queue, if possible.peek()Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.poll()Retrieves and removes the head of this queue.remove()Retrieves and removes the head of this queue.booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T2> T2[]toArray(T2[] array) toList()Flatten queue to a list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
RoundRobinQueue
public RoundRobinQueue()Default constructor. -
RoundRobinQueue
Deep copy of another RoundRobinQueue. This method is used for semi-destructive iteration methods. NOTE: this assumesgetQueueId(Object)behaves the same for this and that.- Parameters:
that- a RoundRobinQueue to make a deep copy of
-
-
Method Details
-
getQueueId
This method determines which queue an object uses.- Parameters:
object- the object being added.- Returns:
- id of the queue where object should be added.
-
add
Add an item to the queue. -
offer
Add an item to the queue, if possible. -
remove
Retrieves and removes the head of this queue.- Specified by:
removein interfaceQueue<T>- Returns:
- first element in queue.
- Throws:
NoSuchElementException- if queue is empty.
-
element
Retrieves, but does not remove, the head of this queue. This method differs from thepeek()method only in that it throws an exception if this queue is empty.- Specified by:
elementin interfaceQueue<T>- Returns:
- the head of this queue.
- Throws:
NoSuchElementException- if this queue is empty.
-
poll
Retrieves and removes the head of this queue. -
peek
Retrieves, but does not remove, the head of this queue, returning null if this queue is empty. -
addAll
======================= COLLECTION METHODS =========================- Specified by:
addAllin interfaceCollection<T>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>
-
size
public int size()- Specified by:
sizein interfaceCollection<T>
-
contains
- Specified by:
containsin interfaceCollection<T>
-
remove
- Specified by:
removein interfaceCollection<T>
-
toList
Flatten queue to a list. Creates a copy (seeRoundRobinQueue(RoundRobinQueue), then builds list by polling until it is empty.- Returns:
- list of all items currently in queue.
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <T2> T2[] toArray(T2[] array) - Specified by:
toArrayin interfaceCollection<T>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T>
-