|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectFlexOr.container.Queue
public class Queue
Queue implements container which has the basic add and remove methods that a queue needs. Storage can be implemented by any Container type with the property that add and remove maintain the FIFO discipline -- this holds for any Sequence; and Heap and Binary Tree if the comparison is on a serial number. The choice of storage model is made at queue creation time.
Note that using Vector (not possible until Vector implements Sequence) gives O(n) performance for remove() as the entire contents of the Vector is shifted. Swapping ends would give poor performance for add(). For an array implementation of queue storage it is best to stay away from Vector and use a CircularArray -- element[0] follows element[size-1] creating a ring-like structure.
Sequence
,
Container
,
SLList
Constructor Summary | |
---|---|
Queue()
The default constructor selects a singly linked list as the storage container. |
|
Queue(Container container)
The constructor permits the user to specify the type of storage container. |
Method Summary | |
---|---|
void |
add(java.lang.Object obj)
Add obj at the rear of the queue. |
void |
addWait(java.lang.Object obj)
Add obj at the rear of the queue; wait if the queue is full. |
java.lang.Object |
clone()
Return a shallow copy of the queue. |
boolean |
contains(java.lang.Object obj)
Determines whether an element is in the queue. |
java.util.Enumeration<java.lang.Object> |
elements()
Returns an enumerator over the contents of the queue. |
boolean |
equals(java.lang.Object obj)
Check for equality of contents of two queues. |
boolean |
isEmpty()
Check if the queue is empty. |
boolean |
isFull()
Check if the queue is full. |
java.lang.Object |
remove()
Return the first element in the queue. |
void |
removeAll()
Empty the queue. |
java.lang.Object |
removeWait()
Return the first element in the queue; wait if the queue is empty. |
int |
size()
Returns the number of elements in the queue. |
java.lang.String |
toString()
Return a string representation of the contents. |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Queue()
public Queue(Container container)
The input container is cloned to minimize side effects of sharing.
Requires: container is empty Ensures: the queue uses the input storage type.
NotEmptyException
- thrown when expecting an empty container but getting
a non empty container.Method Detail |
---|
public boolean contains(java.lang.Object obj)
contains
in interface Container
public java.util.Enumeration<java.lang.Object> elements()
elements
in interface Container
NoSuchElementException
- when nextElement is called with an empty
enumeration sequence.public boolean isEmpty()
isEmpty
in interface Container
public boolean isFull()
isFull
in interface Container
public int size()
size
in interface Container
public void add(java.lang.Object obj)
obj
at the rear of the queue.
Requires: True Ensures: sequence = old sequence ^ obj
add
in interface Container
public void addWait(java.lang.Object obj)
obj
at the rear of the queue; wait if the queue is full.
Requires: True Ensures: sequence = old sequence ^ obj
public void removeAll()
Requires: True Ensures: sequence = null // the empty sequence.
removeAll
in interface Container
public java.lang.Object remove()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
remove
in interface Container
public java.lang.Object removeWait()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
public java.lang.Object clone()
Requires: True Ensures: result = copy of queue
clone
in interface Container
clone
in class java.lang.Object
public java.lang.String toString()
Requires: True Ensures: result = string representation of contents
toString
in interface Container
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
Requires: True Ensures: result = true => contents are equal result = false => contents are not equal
equals
in interface Container
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |