public class Queue<E extends Entity> extends QueueBased implements java.lang.Iterable<E>
QueueBased and the derived classes from QueueList.
The capacity of the Queue, that is the maximum number of entities enqueued,
can be chosen, too.
For queueing SimProcesses the usage of class
ProcessQueue is recommended.
QueueBased,
QueueList,
QueueListFifo,
QueueListLifo,
ProcessQueueQueueBased.QueueActionFIFO, LIFO, RANDOM, UNDEFINED| Constructor and Description |
|---|
Queue(Model owner,
java.lang.String name,
boolean showInReport,
boolean showInTrace)
Constructs a simple priority and FIFO based waiting-queue for
entities with a maximum capacity of 2,147,483,647 waiting
entities, which should serve as an approximation of infinite
queues sufficiently well for most purposes.Note that since SimProcesses
are derived from Entities, they can be queued inside this queue, too.
|
Queue(Model owner,
java.lang.String name,
int sortOrder,
int qCapacity,
boolean showInReport,
boolean showInTrace)
Constructs a simple priority based waiting-queue for entities, the kind
of queue sort order and the capacity of the queue can be chosen.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(E e)
Returns
true if the given Entity is
contained in the queue; false otherwise. |
Reporter |
createDefaultReporter()
Returns a special queue reporter to produce a report about this queue.
|
E |
first()
Returns the first entity queued in this queue or
null in
case the queue is empty. |
E |
first(Condition<E> c)
Returns the first entity queued in this queue that fulfills the given
condition.
|
int |
get(E e)
Returns the queue index of a given
Entity. |
E |
get(int index)
Returns the
Entity queued at the named position. |
QueueList<E> |
getQueueList()
Returns the underlying queue implementation, providing access to the
QueueList implementation, e.g. to add PropertyChangeListeners.
|
java.lang.String |
getQueueStrategy()
Returns the implemented queueing discipline of the underlying queue as a
String, so it can be displayed in the report.
|
long |
getRefused()
Returns the number of entities refused to be enqueued in the queue.
|
boolean |
insert(E e)
Enters a new Entity into the queue.
|
boolean |
insertAfter(E e,
E after)
Enters a new Entity into the queue and places it after the given Entity.
|
boolean |
insertBefore(E e,
E before)
Enters a new Entity into the queue and places it in front of the given
Entity.
|
boolean |
isEmpty()
Returns a boolean value indicating if the queue is empty or if any number
of entities is currently enqueued in it.
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the entities enqueued.
|
E |
last()
Returns the last Entity queued in this queue or
null in
case the queue is empty. |
E |
last(Condition<E> c)
Returns the last Entity queued in this queue that fulfills the given
condition.
|
E |
pred(E e)
Returns the entity enqueued directly before the given Entity in the
queue.
|
E |
pred(E e,
Condition<E> c)
Returns the entity enqueued before the given Entity in the queue that
also fulfills the condition given.
|
void |
remove(Entity e)
Removes the given Entity from the Queue.
|
boolean |
remove(int index)
Removes the entity queued at the given position.
|
void |
removeAll()
Removes all entities from the Queue.
|
E |
removeFirst()
Removes the first entity from the queue and provides a reference to
this entity.
|
E |
removeFirst(Condition<E> c)
Removes the first entity from the queue that fulfills the given
condition.
|
E |
removeLast()
Removes the last entity from the queue and provides a reference to
this entity.
|
E |
removeLast(Condition<E> c)
Removes the last entity from the queue that fulfills to the given
condition, determined by traversing the queue from last to first until
an entity fulfilling the condition is found.
|
void |
reset()
Resets all statistical counters to their default values.
|
void |
setQueueStrategy(int sortOrder)
Sets the sort order of this Queue to a new value and makes this
Queue use another
QueueList with the specified
queueing discipline. |
void |
setSeed(long newSeed)
Sets the seed of the underlying queue list's pseudo random number generator.
|
int |
size()
Returns the current length of the Queue.
|
E |
succ(E e)
Returns the entity enqueued directly after the given Entity in the queue.
|
E |
succ(E e,
Condition<E> c)
Returns the entity enqueued after the given Entity in the queue that also
fulfills the condition given.
|
addObserver, averageLength, averageWaitTime, deleteObserver, getQueueLimit, length, maxLength, maxLengthAt, maxWaitTime, maxWaitTimeAt, minLength, minLengthAt, notifyObservers, setQueueImpWarning, stdDevLength, stdDevWaitTime, zeroWaitsgetCorrespondingSchedulable, getDescription, getObservations, getReporter, incrementObservations, incrementObservations, reportIsOn, reportOff, reportOn, resetAt, setCorrespondingSchedulable, setDescription, setReportercurrent, currentEntity, currentEntityAll, currentEvent, currentModel, currentSimProcess, debugIsOn, debugOff, debugOn, getModel, isExperimentCompatible, isModelCompatible, presentTime, sendDebugNote, sendMessage, sendTraceNote, sendWarning, skipTraceNote, skipTraceNote, traceIsOn, traceOff, traceOngetName, getQuotedName, toStringpublic Queue(Model owner, java.lang.String name, int sortOrder, int qCapacity, boolean showInReport, boolean showInTrace)
Queues can be sorted as follows:
QueueBased.FIFO sorts entities by their priority,
highest priority first. Entities with the same priority are
enqueued based on "first in, first out".QueueBased.LIFO also sorts entities by their priority,
highest priority first. However, entities with the same priority are
enqueued based on "last in, first out".QueueBased.Random assigns a random position to each
entity entering the queue, disregarding priority.
The usage of the generic version Queue<Type> where
Type is derived from Entity is recommended
for type safety. Using the raw type Queue yields a queue
in which any Entity can be enqueued, typically requiring
type casting on accessing entities enqueued.
owner - Model : The model this queue is associated toname - java.lang.String : The queue's namesortOrder - int : determines the sort order of the underlying queue
implementation. Choose a constant from QueueBased:
QueueBased.FIFO, QueueBased.LIFO or
QueueBased.Random.qCapacity - int : The capacity of the Queue, that is how many entities can
be enqueued. Zero (0) can be used as shortcut for
for a capacity of Integer.MAX_VALUE = 2,147,483,647,
which should approximate an infinite queue sufficiently well
for most purposes.showInReport - boolean : Flag if queue should produce a reportshowInTrace - boolean : Flag for queue to produce trace messagespublic Queue(Model owner, java.lang.String name, boolean showInReport, boolean showInTrace)
The usage of the generic version Queue<Type> where
Type is derived from Entity is recommended
for type safety. Using the raw type Queue yields a queue
in which any Entity can be enqueued, typically requiring
type casting on accessing entities enqueued.
owner - Model : The model this queue is associated toname - java.lang.String : The queue's nameshowInReport - boolean : Flag if queue should produce a reportshowInTrace - boolean : Flag for queue to produce trace messagespublic Reporter createDefaultReporter()
public E first()
null in
case the queue is empty.null if the queue is emptypublic E first(Condition<E> c)
true when the condition is applied to it is
returned by this method. If no Entity fulfills the given condition or the
queue is empty, null will be returned.c - Condition : The condition that the entity returned must fulfillnullpublic boolean contains(E e)
true if the given Entity is
contained in the queue; false otherwise.e - E : The Entity we are looking for
in the queue.True if the given
Entity is contained in the queue;
false otherwise.public int size()
public int get(E e)
Entity.int.
Returns -1 if no such position exists.public E get(int index)
Entity queued at the named position.
The first position is 0, the last one size()-1.Entity at the position of
int or null if no such position exists.public java.lang.String getQueueStrategy()
public long getRefused()
public boolean insert(E e)
false will be
returned. The Entity will be stored in the queue until method
remove(Entity e) is called with this specific Entity.
Entities inside the queue are ordered according to their priority. Higher
priorities are sorted in front of lower priorities. Entities with same
priority are orderer according to the specified strategy. The first
Entity inside the queue will always be the one with the highest priority.e - E : The Entity to be added to the queue.true if insertion was successful,
false otherwise (i.e. capacity limit is reached).public boolean insertAfter(E e, E after)
false will be returned. Make sure that the entity given as
reference is already queued inside the queue, else the entity will not be
enqueued and false will be returned. The Entity will be
stored in the queue until method remove(Entity e) is
called with this specific Entity.e - E : The Entity to be added to the queueafter - E : The Entity after which the entity e is to be insertedtrue if insertion was successful,
false otherwise (i.e. capacity limit is reached).public boolean insertBefore(E e, E before)
false will be returned. Make sure that the
Entity given as reference is already queued inside the queue, else the
Entity will not be queued and false will be returned. The
Entity will be stored in the queue until method
remove(Entity e) is called with this specific Entity.e - E : The Entity to be added to the queuebefore - E : The Entity before which the entity e is to be
insertedtrue if insertion was successful,
false otherwise (i.e. capacity limit is reached).public boolean isEmpty()
true if the Queue is empty,
false otherwisepublic E last()
null in
case the queue is empty.null
if the queue is emptypublic E last(Condition<E> c)
true when the condition is applied to it is
returned. If no Entity fulfills the given condition or the queue is
empty, null will be returned.c - Condition : The condition that the entity returned must fulfillnullpublic E pred(E e)
null
is returned.e - E : An Entity in the queuenull.public E pred(E e, Condition<E> c)
null is returned. If no other Entity
before the given one fulfills the condition, null is
returned, too.e - E : An Entity in the queuec - Condition : The condition that the preceeding Entity has to
fulfillnull.public void remove(Entity e)
e - Entity : The Entity to be removedpublic void removeAll()
public E removeFirst()
null is returned.null in case the queue was emptypublic E removeFirst(Condition<E> c)
null is returned.c - Condition : The condition that the entity returned must fulfillNull in case no entity
fulfills the condition.public E removeLast()
null is returned.null in case the queue was emptypublic E removeLast(Condition<E> c)
null is returned.c - Condition : The condition that the entity returned must fulfillNull in case no entity
fulfills the condition.public boolean remove(int index)
true if an Entity
exists at the given position or false> if otherwise.public void reset()
reset in class QueueBasedpublic void setQueueStrategy(int sortOrder)
QueueList with the specified
queueing discipline. Please choose a constant from
QueueBased (QueueBased.FIFO,
QueueBased.FIFO or QueueBased.Random)
The sort order of a Queue can only be changed if the queue is empty.sortOrder - int : determines the sort order of the underlying
QueueList implementation (QueueBased.FIFO,
QueueBased.FIFO or QueueBased.Random)public E succ(E e)
null is
returned.e - E : An Entity in the queuenull.public E succ(E e, Condition<E> c)
null is returned. If no other Entity after the given one
fulfills the condition, null is returned, too.e - E : An Entity in the queuec - Condition : The condition that the succeeding Entity has to
fulfillnull.public QueueList<E> getQueueList()
public void setSeed(long newSeed)
newSeed - long : new seed of the underlying queue list's pseudo
random number generator