structure
Class AbstractQueue
java.lang.Object
|
+--structure.AbstractStructure
|
+--structure.AbstractLinear
|
+--structure.AbstractQueue
- All Implemented Interfaces:
- Linear, Queue, Structure
- Direct Known Subclasses:
- QueueArray, QueueList, QueueVector
- public abstract class AbstractQueue
- extends AbstractLinear
- implements Queue
An abstract structure implementing features common to all first-in, first-out
structures in this package.
Queues are typically used to process values in the order that they appear
and to store the state of buffered objects.
The structure package provides several implementations of the Queue interface,
each of which has its particular strengths and weaknesses.
Example usage:
To compute the sum of the unicode value of every character in the standard input
we could use the following:
public static void main(String[] arguments)
{
AbstractQueue
q = new QueueList()
;
int unicodeSum = 0;
if(arguments.length > 0){
for(int i=0; i < arguments.length; i++){
for(int j=0; j < arguments[i].length(); j++){
q.enqueue(new Character(arguments[i].charAt(j)))
;
}
}
}
while(!q.AbstractLinear.empty()
){
char c = ((Character)q.dequeue()
).charValue();
unicodeSum+=Character.getNumericValue(c);
}
System.out.println("Total Value: " + unicodeSum);
}
- See Also:
QueueArray
,
QueueVector
,
QueueList
Method Summary |
Object |
dequeue()
Remove a value form the head of the queue. |
void |
enqueue(Object item)
Add a value to the tail of the queue. |
Object |
getFirst()
Fetch the value at the head of the queue. |
Object |
peek()
Fetch the value at the head of the queue. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, notify, notifyAll, registerNatives, toString, wait, wait, wait |
AbstractQueue
public AbstractQueue()
enqueue
public void enqueue(Object item)
- Add a value to the tail of the queue.
- Specified by:
enqueue
in interface Queue
- Parameters:
value
- The value added.- Postcondition:
- the value is added to the tail of the structure
dequeue
public Object dequeue()
- Remove a value form the head of the queue.
- Specified by:
dequeue
in interface Queue
- Precondition:
- the queue is not empty
- Postcondition:
- the head of the queue is removed and returned
- Returns:
- The value actually removed.
getFirst
public Object getFirst()
- Fetch the value at the head of the queue.
- Specified by:
getFirst
in interface Queue
- Precondition:
- the queue is not empty
- Postcondition:
- the element at the head of the queue is returned
- Returns:
- Reference to the first value of the queue.
peek
public Object peek()
- Fetch the value at the head of the queue.
- Specified by:
peek
in interface Queue
- Precondition:
- the queue is not empty
- Postcondition:
- the element at the head of the queue is returned
- Returns:
- Reference to the first value of the queue.