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 TypeMethodDescriptionboolean
Add an item to the queue.boolean
addAll
(Collection<? extends T> c) ======================= COLLECTION METHODS =========================void
clear()
boolean
boolean
containsAll
(Collection<?> c) element()
Retrieves, but does not remove, the head of this queue.protected String
getQueueId
(T object) This method determines which queue an object uses.boolean
isEmpty()
iterator()
boolean
Add 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.boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
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, wait
Methods 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:
remove
in 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:
element
in 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:
addAll
in interfaceCollection<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
-
remove
- Specified by:
remove
in 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:
toArray
in interfaceCollection<T>
-
toArray
public <T2> T2[] toArray(T2[] array) - Specified by:
toArray
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-