|
||||||||||
| 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 Containerpublic java.util.Enumeration<java.lang.Object> elements()
elements in interface ContainerNoSuchElementException - when nextElement is called with an empty
enumeration sequence.public boolean isEmpty()
isEmpty in interface Containerpublic boolean isFull()
isFull in interface Containerpublic int size()
size in interface Containerpublic void add(java.lang.Object obj)
obj at the rear of the queue.
Requires: True Ensures: sequence = old sequence ^ obj
add in interface Containerpublic 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 Containerpublic java.lang.Object remove()
Requires: isEmpty = false Ensures: old sequence = obj ^ sequence
remove in interface Containerpublic 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 Containerclone in class java.lang.Objectpublic java.lang.String toString()
Requires: True Ensures: result = string representation of contents
toString in interface ContainertoString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
Requires: True
Ensures: result = true => contents are equal
result = false => contents are not equal
equals in interface Containerequals in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||