structure5
Interface Queue<E>

All Superinterfaces:
Iterable<E>, Linear<E>, Structure<E>
All Known Implementing Classes:
AbstractQueue, QueueArray, QueueList, QueueVector

public interface Queue<E>
extends Linear<E>

Interface describing a first-in, first-out structure. Values are added at the tail, and removed from the head. Queues are typically used to process values in the order that they appear and to store the state of a buffered object. 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)
 {
     Queue 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.empty()){
          char c = ((Character)q.dequeue()).charValue();
          unicodeSum+=Character.getNumericValue(c);
     }

     System.out.println("Total Value: " + unicodeSum);
 }
 

See Also:
structure.Stack, AbstractQueue, QueueArray, QueueVector, QueueList

Method Summary
 void add(E value)
          Add a value to the tail of the queue.
 E dequeue()
          Remove a value from the head of the queue.
 boolean empty()
          Returns true iff the queue is empty.
 void enqueue(E value)
          Add a value to the tail of the queue.
 E get()
          Fetch the value at the head of the queue.
 E getFirst()
          Fetch the value at the head of the queue.
 E peek()
          Fetch the value at the head of the queue.
 E remove()
          Remove a value form the head of the queue.
 int size()
          Returns the number of elements in the queue.
 
Methods inherited from interface structure5.Structure
clear, contains, elements, isEmpty, iterator, remove, values
 

Method Detail

add

void add(E value)
Add a value to the tail of the queue.

Specified by:
add in interface Linear<E>
Specified by:
add in interface Structure<E>
Parameters:
value - The value added.
See Also:
enqueue(E)

enqueue

void enqueue(E value)
Add a value to the tail of the queue.

Parameters:
value - The value to be added.

remove

E remove()
Remove a value form the head of the queue.

Specified by:
remove in interface Linear<E>
Returns:
The value actually removed.
See Also:
dequeue()

dequeue

E dequeue()
Remove a value from the head of the queue.

Returns:
The value removed from the queue.

getFirst

E getFirst()
Fetch the value at the head of the queue.

Returns:
Reference to the first value of the queue.

get

E get()
Fetch the value at the head of the queue.

Specified by:
get in interface Linear<E>
Returns:
Reference to the first value of the queue.

peek

E peek()
Fetch the value at the head of the queue.

Returns:
Reference to the first value of the queue.

empty

boolean empty()
Returns true iff the queue is empty. Provided for compatibility with java.util.Vector.empty.

Specified by:
empty in interface Linear<E>
Returns:
True iff the queue is empty.

size

int size()
Returns the number of elements in the queue.

Specified by:
size in interface Linear<E>
Specified by:
size in interface Structure<E>
Returns:
number of elements in queue.