|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectFlexOr.container.Queue
FlexOr.container.PriorityQueue
public class PriorityQueue
PriorityQueue extends Queue since it is a queue if all priorities are equal. A heap is used as the storage model as using a Sequence would make add O(size) in time or remove O(size) in time. The default add stores objects with a user specified DefaultPriority at PriorityQueue creation time. A new add method is provided to add objects with different priorities.
Using a PriorityQueue as a Queue is relatively inefficient as both add and remove are O(log(size)) in time instead of O(1).
SLList
,
Sequence
,
Container
Constructor Summary | |
---|---|
PriorityQueue(int capacity)
Default constructor. |
|
PriorityQueue(int capacity,
boolean highNumberhighPriority,
int defaultPriority)
Set all PriorityQueue parameters. |
Method Summary | |
---|---|
void |
add(java.lang.Object obj)
Add obj with DefaultPriority. |
void |
add(java.lang.Object obj,
int priority)
Add obj with a specific priority. |
java.lang.Object |
clone()
Return a shallow copy of the queue. |
boolean |
contains(java.lang.Object obj)
Determines whether a datum is in the tree irrespective of priority. |
java.util.Enumeration<java.lang.Object> |
elements()
Returns an enumerator over the contents of the queue. |
java.lang.Object |
remove()
Return the first element in the queue. |
Methods inherited from class FlexOr.container.Queue |
---|
addWait, equals, isEmpty, isFull, removeAll, removeWait, size, toString |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PriorityQueue(int capacity)
capacity
- The maximum number of elements that can be stored.
TooSmallException
- when capacity is < 2.public PriorityQueue(int capacity, boolean highNumberhighPriority, int defaultPriority)
capacity
- The maximum number of elements that can be stored.highNumberhighPriority
- Determine whether larger integers mean higher or
lower priority. Set to True if you want larger integers to be higher priority.
Set to false if you want smaller integers to be higher priority.defaultPriority
- Determine priority level for default add.
TooSmallException
- when capacity is < 2.Method Detail |
---|
public boolean contains(java.lang.Object obj)
Requires: True Ensures: contains(obj) => result = true   not contains(obj) => result = false
contains
in interface Container
contains
in class Queue
public java.util.Enumeration<java.lang.Object> elements()
elements
in interface Container
elements
in class Queue
NoSuchElementException
- when nextElement is called with an empty
enumeration sequence.public void add(java.lang.Object obj)
obj
with DefaultPriority.
Requires: size < Capacity Ensures: subsequence(DefaultPriority) = subsequence(DefaultPriority) ^ obj
add
in interface Container
add
in class Queue
ContainerFullException
- when container already contains Capacity
elements.public void add(java.lang.Object obj, int priority)
obj
with a specific priority.
Requires: size < Capacity Ensures: subsequence(priority) = subsequence(priority) ^ obj
ContainerFullException
- when container already contains Capacity
elements.public java.lang.Object remove()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
remove
in interface Container
remove
in class Queue
ContainerEmptyException
- when container is empty.
elements.public java.lang.Object clone()
Requires: True Ensures: result = copy of queue
clone
in interface Container
clone
in class Queue
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |