m865.datastructures
Class BalkingQueue

java.lang.Object
  extended bym865.datastructures.AbstractQueue
      extended bym865.datastructures.BalkingQueue
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection

public class BalkingQueue
extends AbstractQueue

This class implements a balking queue, which is an extension of an AbstractQueue that implements all the remove methods of the Collection interface. It uses the java.util.LinkedList to store the objects in the queue.

Version:
2.0 10/05/04
Author:
Pratap Murali, Hariharan Kandasamy, Kamal Lanka, Daniel D. Warner

Nested Class Summary
 class BalkingQueue.BalkingQueueIterator
          An iterator for a BalkingQueue.
 
Field Summary
protected  java.util.LinkedList list
          The objects in the queue are stored in this Linked List.
 
Fields inherited from class m865.datastructures.AbstractQueue
hash
 
Constructor Summary
  BalkingQueue()
          The default constructor.
  BalkingQueue(java.util.Collection c)
          Constructs a queue which is initialized with the objects in the specified collection
protected BalkingQueue(int hash, java.util.LinkedList list)
          Constructs a queue with a specified hash code and a clone of the specified LinkedList.
 
Method Summary
 void clear()
          Removes all the objects from this queue.
 java.lang.Object clone()
          The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.
 java.lang.Object dequeue()
          Removes and returns the object at the beginning of the queue.
 void enqueue(java.lang.Object obj)
          Appends an object to the end of the queue.
 boolean isEmpty()
          Determines whether the queue is empty.
 java.util.Iterator iterator()
          A factory method which returns an Iterator to the collection in this queue.
static void main(java.lang.String[] args)
          This main method tests the BalkingQueue class to insure that the elementary functions are correct.
 java.lang.Object peek()
          Returns the object at the beginning of the queue.
 boolean remove(java.lang.Object obj)
          Removes a single instance of the specified element from this collection, if it is present
 boolean removeAll(java.util.Collection c)
          Insures that each element of the specified collection is removed from the the balking queue.
 boolean retainAll(java.util.Collection c)
          Removes all the elements of the balking queue that are not contained in the specified collection.
 int size()
          Determines the size of this balking queue.
 java.lang.String toString()
          List the objects in this balking queue
 
Methods inherited from class m865.datastructures.AbstractQueue
add, addAll, contains, containsAll, downdateHashCode, equals, hashCode, toArray, toArray, updateHashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

list

protected java.util.LinkedList list
The objects in the queue are stored in this Linked List.

Constructor Detail

BalkingQueue

public BalkingQueue()
The default constructor.


BalkingQueue

public BalkingQueue(java.util.Collection c)
Constructs a queue which is initialized with the objects in the specified collection

Parameters:
c - the collection of objects to be initially enqueued onto this queue.

BalkingQueue

protected BalkingQueue(int hash,
                       java.util.LinkedList list)
Constructs a queue with a specified hash code and a clone of the specified LinkedList. This constuctor is only for use within the class and its subclasses.

Parameters:
hash - the hash code
list - the linked list containing the objects in the queue.
Method Detail

enqueue

public void enqueue(java.lang.Object obj)
Appends an object to the end of the queue.

Specified by:
enqueue in class AbstractQueue
Parameters:
obj - the object to be appended to the end of the queue.

dequeue

public java.lang.Object dequeue()
Removes and returns the object at the beginning of the queue. It throws a NoSuchElement exception if the queue is empty.

Specified by:
dequeue in class AbstractQueue
Returns:
the object at the beginning of the queue

peek

public java.lang.Object peek()
Returns the object at the beginning of the queue. The queue remains unchanged. It throws a NoSuchElement exception if the queue is empty.

Specified by:
peek in class AbstractQueue
Returns:
the object at the beginning of the queue

clear

public void clear()
Removes all the objects from this queue. This is one of the optional operations specified by the Collection Interface


clone

public java.lang.Object clone()
The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.

Returns:
a clone (a true and independent copy) of this queue.

isEmpty

public boolean isEmpty()
Determines whether the queue is empty.

Specified by:
isEmpty in interface java.util.Collection
Overrides:
isEmpty in class AbstractQueue
Returns:
true - if this collection contains no elements.

iterator

public java.util.Iterator iterator()
A factory method which returns an Iterator to the collection in this queue. This iterator will walk through the queue from the front to the back. It will throw a ConcurrentModificationException if the queue is altered during the iteration.

Returns:
a BalkingQueueIterator which will iterate through this queue from front to back

remove

public boolean remove(java.lang.Object obj)
Removes a single instance of the specified element from this collection, if it is present

Specified by:
remove in interface java.util.Collection
Overrides:
remove in class AbstractQueue
Parameters:
obj - the object to be removed.
Returns:
true if an instance of the object was found in the queue and false if the object was not in the queue.

removeAll

public boolean removeAll(java.util.Collection c)
Insures that each element of the specified collection is removed from the the balking queue.

Specified by:
removeAll in interface java.util.Collection
Overrides:
removeAll in class AbstractQueue
Parameters:
c - the specified collection
Returns:
true if the balking queue has been modified.

retainAll

public boolean retainAll(java.util.Collection c)
Removes all the elements of the balking queue that are not contained in the specified collection.

Specified by:
retainAll in interface java.util.Collection
Overrides:
retainAll in class AbstractQueue
Parameters:
c - the specified collection
Returns:
true if the balking queue has been modified.

size

public int size()
Determines the size of this balking queue.

Returns:
the number of objects in this queue.

toString

public java.lang.String toString()
List the objects in this balking queue

Overrides:
toString in class AbstractQueue
Returns:
a formatted string listing the objects in this queue

main

public static void main(java.lang.String[] args)
This main method tests the BalkingQueue class to insure that the elementary functions are correct.

Parameters:
args - optional command line arguments which will be ignored.