Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.util   Previous This
Package
Next

 


Class Queue

public class Queue implements java.util.Enumeration, Cloneable
{
  // Constructors
  public Queue ();
  public Queue (int initialcapacity);
  public Queue (int initialcapacity, int growthfactor);

  // Methods
  public synchronized void addElement (Object newelt);
  public int capacity ();
  protected Object clone () throws CloneNotSupportedException;
  public synchronized Queue copy ();
  public synchronized Object elementFromHead (int idx);
  public synchronized Object elementFromTail (int idx);
  public synchronized boolean hasMoreElements ();
  public synchronized Object nextElement ();
  public synchronized Object pop ();
  public synchronized void removeAllElements ();
  public synchronized int setCapacity (int newcapacity);
  public synchronized int size ();
  public String toString ();
}

This class provides a queue, implemented in an array.

Constructors

Queue

public Queue ();

This class constructs a queue with an initial capacity of 32 elements. When the queue is full, its size doubles.

Queue

public Queue (int initialcapacity);

Constructs a queue with the given initial capacity. When the queue is full, the capacity doubles in size.

ParameterDescription
initialcapacity The size of the queue to construct (the number of elements it will hold).

Queue

public Queue (int initialcapacity, int growthfactor);

Constructs a queue with the given initial capacity and growth factor.

ParameterDescription
initialcapacity The initial size of the queue.
growthfactor The factor to grow by when the queue is full. If the growth factor is 1, the queue will drop elements at its head as needed.

Methods

addElement

public synchronized void addElement (Object newelt);

Adds an element to the tail of the queue.

Return Value:

No return value.

ParameterDescription
newelt The new element to add to the queue.

Remarks:

The queue will grow, as necessary, by the factor provided when the queue was constructed. Null is a valid element to add.

capacity

public int capacity ();

Obtains the maximum number of objects that the queue can contain without resizing.

Return Value:

Returns the maximum capacity (in objects) of the queue.

clone

protected Object clone () throws CloneNotSupportedException;

Creates a copy of the object.

Return Value:

Returns a copy of the Queue object.

Exceptions:

CloneNotSupportedException if the object cannot be copied.

copy

public synchronized Queue copy ();

Duplicates the queue.

Return Value:

Returns a copy of the Queue object.

elementFromHead

public synchronized Object elementFromHead (int idx);

Retrieves an element relative to the head of the queue.

Return Value:

Returns the requested object.

ParameterDescription
idx The offset from the first item in the queue.

elementFromTail

public synchronized Object elementFromTail (int idx);

Retrieves an element relative to the tail of the queue.

Return Value:

Returns the requested object.

ParameterDescription
idx The offset from the last item in the queue.

hasMoreElements

public synchronized boolean hasMoreElements ();

Determines if the queue is empty.

Return Value:

Returns true if there are more elements in the queue; otherwise, returns false.

nextElement

public synchronized Object nextElement ();

Removes an object from the head of the queue.

Return Value:

Returns true if the object was successfully removed; otherwise, returns false.

Exceptions:

NoSuchElementException if the queue is empty.

pop

public synchronized Object pop ();

Retrieves the element last added to the queue.

Return Value:

Returns the requested object.

removeAllElements

public synchronized void removeAllElements ();

Empties the queue.

Return Value:

No return value.

setCapacity

public synchronized int setCapacity (int newcapacity);

Changes the queue's capacity.

Return Value:

Returns the actual final capacity assigned to the queue.

ParameterDescription
newcapacity The new number of elements in the queue.

size

public synchronized int size ();

Obtains the number of elements in the queue.

Return Value:

Returns the size of the queue (in elements).

toString

public String toString ();

Retrieves a string representation of the Queue object.

Return Value:

Returns a string.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.