stockportfolio
Class ObjectDQueue

java.lang.Object
  extended bystockportfolio.ObjectDQueue
All Implemented Interfaces:
IDQueue, IQueue
Direct Known Subclasses:
StockQueue

public class ObjectDQueue
extends java.lang.Object
implements IDQueue

An enhanced queue. Can addToFront, and get the elements by idenx.


Constructor Summary
ObjectDQueue()
           
 
Method Summary
 boolean addToFront(java.lang.Object newValue)
          Add (push) an element to the front of the queue; thus, the next dequeue operation would return this value, assuming there were no other intervening addToFront operations.
 java.lang.Object dequeue()
          Remove an object from the queue.
 boolean enqueue(java.lang.Object newValue)
          Push a new object on the queue.
 java.lang.Object front()
          Look at the front of the queue.
 java.lang.Object getObject(int index)
          Get an object from the queue.
 boolean isEmpty()
          Tell whether the queue is empty.
 boolean isFull()
          Tell whether the queue is full.
 int size()
          Tells how many objects are currently in the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectDQueue

public ObjectDQueue()
Method Detail

addToFront

public boolean addToFront(java.lang.Object newValue)
Description copied from interface: IDQueue
Add (push) an element to the front of the queue; thus, the next dequeue operation would return this value, assuming there were no other intervening addToFront operations.

Specified by:
addToFront in interface IDQueue
Parameters:
newValue - a non-null object
Returns:
true iff the object was successfully added to the queue.

getObject

public java.lang.Object getObject(int index)
Description copied from interface: IDQueue
Get an object from the queue. The object is not dequeued and the stack is unchanged.

Specified by:
getObject in interface IDQueue
Parameters:
index - an index number, with 0 being the oldest object (i.e., the one at the front of the queue), 1 being next oldest, etc.
Returns:
the object corresponding to blocknum

dequeue

public java.lang.Object dequeue()
Description copied from interface: IQueue
Remove an object from the queue.

Specified by:
dequeue in interface IQueue
Returns:
a reference to the front of the queue, or null if the queue is empty. The size of the queue has decreased by 1. Note that the reference is to the actual enqueued object, not to a clone.

enqueue

public boolean enqueue(java.lang.Object newValue)
Description copied from interface: IQueue
Push a new object on the queue.

Specified by:
enqueue in interface IQueue
Parameters:
newValue - a non-null object
Returns:
true iff the operation succeeded. In this case, the newValue is now the top of the queue and the previous top is just below it; the size of the queue has increased by 1.

front

public java.lang.Object front()
Description copied from interface: IQueue
Look at the front of the queue. The queue itself is unchanged.

Specified by:
front in interface IQueue
Returns:
the front of the queue, or null if the queue is empty. Note that the reference is to the actual enqueued object, not to a clone.

isEmpty

public boolean isEmpty()
Description copied from interface: IQueue
Tell whether the queue is empty.

Specified by:
isEmpty in interface IQueue
Returns:
true iff the queue is empty (has size 0).

isFull

public boolean isFull()
Description copied from interface: IQueue
Tell whether the queue is full.

Specified by:
isFull in interface IQueue
Returns:
true iff the queue is full, i.e., whether it is possible to another another object to it.

size

public int size()
Description copied from interface: IQueue
Tells how many objects are currently in the queue.

Specified by:
size in interface IQueue
Returns:
the number of objects in the queue, always >= 0