jsim.queue
Class Queue

java.lang.Object
  extended by jsim.queue.Queue
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List
Direct Known Subclasses:
FIFO_Queue, LIFO_Queue, PriorityQueue

public abstract class Queue
extends java.lang.Object
implements java.util.List

Class Queue is an abstract class which pure virtual functions must be implemented in subclasses.

Version:
1.0 96/07/10
Author:
Zhiwei Zhang, John Miller

Field Summary
protected  int capacity
          Maximum number of elements allowed
protected  Q_Node root
          Root (front) of queue
protected  int size
          Current number of elements
 
Constructor Summary
Queue()
           
 
Method Summary
 void add(int index, java.lang.Object element)
           
 boolean add(java.lang.Object item)
          Insert an element into the queue.
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
abstract  Q_Node addAt(java.lang.Object item)
          Insert an element into the queue and return holding node.
 void cancel(Q_Node node)
          Cancel (remove) node from the queue.
 void clear()
          Remove all elements from the queue.
 boolean contains(java.lang.Object o)
          Methods in List interface that are not implemented.
 boolean containsAll(java.util.Collection c)
           
 Q_Node first()
          Return the first element in the queue without removing it.
 java.lang.Object get(int index)
           
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
          Return whether the queue is empty (true for empty, false for nonempty).
 boolean isFull()
          Return whether the queue is full (true for full, false for not full).
 java.util.Iterator iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 Q_Node remove()
          Remove and return the first element in the queue.
 java.lang.Object remove(int index)
          Remove the node containing the minimum/first element from the queue.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
protected  void removeMin()
          Remove the node containing the minimum/first element from the queue.
 boolean retainAll(java.util.Collection c)
           
 java.lang.Object set(int index, java.lang.Object element)
           
 int size()
          Return the number of elements in the queue.
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Field Detail

root

protected Q_Node root
Root (front) of queue


size

protected int size
Current number of elements


capacity

protected int capacity
Maximum number of elements allowed

Constructor Detail

Queue

public Queue()
Method Detail

isEmpty

public boolean isEmpty()
Return whether the queue is empty (true for empty, false for nonempty).

Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Returns:
boolean whether queue is empty

isFull

public boolean isFull()
Return whether the queue is full (true for full, false for not full).

Returns:
boolean whether queue is full

size

public int size()
Return the number of elements in the queue.

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Returns:
int queue length

first

public Q_Node first()
             throws java.util.NoSuchElementException
Return the first element in the queue without removing it.

Returns:
Q_Node node containing first item
Throws:
java.util.NoSuchElementException - if the queue is empty.

cancel

public void cancel(Q_Node node)
Cancel (remove) node from the queue.

Parameters:
node - node to be cancelled

remove

public Q_Node remove()
              throws java.util.NoSuchElementException
Remove and return the first element in the queue. If first node has been cancelled (not present), continue to remove.

Returns:
Q_Node first node
Throws:
java.util.NoSuchElementException - if the queue is empty.

remove

public java.lang.Object remove(int index)
Remove the node containing the minimum/first element from the queue. Method for compliance with List interface.

Specified by:
remove in interface java.util.List
Parameters:
index - list position (must be 0)

removeMin

protected void removeMin()
Remove the node containing the minimum/first element from the queue.


clear

public void clear()
Remove all elements from the queue.

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List

add

public boolean add(java.lang.Object item)
Insert an element into the queue. Throws FullQueueException if * the size of the queue is out of capacity.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Parameters:
item - new item to be added
Returns:
boolean whether insertion suceeded

addAt

public abstract Q_Node addAt(java.lang.Object item)
                      throws FullQueueException
Insert an element into the queue and return holding node. Throws FullQueueException if * the size of the queue is out of capacity.

Parameters:
item - new item to be added
Returns:
Q_Node node holding the new item
Throws:
FullQueueException - if the queue is full.

contains

public boolean contains(java.lang.Object o)
Methods in List interface that are not implemented.

Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List