Class BattleFront<T extends java.lang.Comparable<T>>

java.lang.Object
  extended by BattleFront<T>
All Implemented Interfaces:
IQueue<T>

public class BattleFront<T extends java.lang.Comparable<T>>
extends java.lang.Object
implements IQueue<T>

The BattleFront is a generic priority queue that orders elements of type T based on their natural order comparison. It is required that T implements Comparable<T>.

Author:
Sean Strout

Field Summary
private  Node<T> head
          The head of the queue.
private  int size
          The current number of elements in the queue.
 
Constructor Summary
BattleFront()
          Constructor which initializes the head to null, and the current count to 0.
 
Method Summary
 T dequeue()
          Removes and returns the front element from the queue.
 boolean empty()
          Indicates if the queue is empty or not.
 void enqueue(T element)
          Adds an element to the queue based on the priority of the elements.
 boolean full()
          Indicates if the queue is full or not.
 int size()
          Indicates how many elements are in the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

head

private Node<T extends java.lang.Comparable<T>> head
The head of the queue.


size

private int size
The current number of elements in the queue.

Constructor Detail

BattleFront

public BattleFront()
Constructor which initializes the head to null, and the current count to 0.

Method Detail

enqueue

public void enqueue(T element)
Adds an element to the queue based on the priority of the elements. The elements are ordered in ascending priority, from lowest to highest. The priority is determined by using Comparable's compareTo() method. Because this method modifies the collection, and multiple threads can invoke it, it is protected with the synchronized keyword.

Specified by:
enqueue in interface IQueue<T extends java.lang.Comparable<T>>
Parameters:
element - The new element to insert into the queue

dequeue

public T dequeue()
                                          throws UnderflowException
Removes and returns the front element from the queue. Because this method modifies the collection, and multiple threads can invoke it, it is protected with the synchronized keyword.

Specified by:
dequeue in interface IQueue<T extends java.lang.Comparable<T>>
Returns:
The front element.
Throws:
UnderflowException - If the queue is empty it is created with the message "There is no one on the battlefront!"

size

public int size()
Indicates how many elements are in the queue

Specified by:
size in interface IQueue<T extends java.lang.Comparable<T>>
Returns:
The number of elements currently in the queue

empty

public boolean empty()
Indicates if the queue is empty or not.

Specified by:
empty in interface IQueue<T extends java.lang.Comparable<T>>
Returns:
True if the queue is empty, false otherwise.

full

public boolean full()
Indicates if the queue is full or not.

Specified by:
full in interface IQueue<T extends java.lang.Comparable<T>>
Returns:
The battlefront has no size restriction, so theoretically it can never be full.