anthill.util
Class Queue

java.lang.Object
  |
  +--anthill.util.Queue

public final class Queue
extends Object

The Queue class implements a queue with last-in, first-out semantics. The queue is implemented as a linked list of buckets, each of them contains a fixed number of objects. Appended objects are inserted in the last bucket (if full, a new bucket is allocated), while removed buckets are extracted from the first bucket.

Version:
$Revision: 1.4 $
Author:
Alberto Montresor

Constructor Summary
Queue()
          Allocates a queue with default bucket size
Queue(int size)
          Allocates a queue with bucket size equal to size <\code>.
 
Method Summary
 void add(Object object)
          Appends object <\code> at the end of the queue.
 void clear()
          Removes all the elements from the queue.
 Object get()
          Returns the first element of the queue.
 boolean isEmpty()
          Returns true if the queue is empty.
static void main(String[] args)
           
 void merge(Queue addend)
          Add the elements of the addend queue at the end of this queue.
 Object remove()
          Removes the first element of the queue.
 int size()
          Returns the number of elements contained in this queue
 Object[] toArray()
          Copies the element of the queue in an array of objects, in the queue order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue(int size)
Allocates a queue with bucket size equal to size <\code>.

Parameters:
size - the size of internal buckets.

Queue

public Queue()
Allocates a queue with default bucket size

Method Detail

add

public void add(Object object)
Appends object <\code> at the end of the queue.

Parameters:
object - the object to be inserted

isEmpty

public boolean isEmpty()
Returns true if the queue is empty.

Returns:
true if the queue is empty

size

public int size()
Returns the number of elements contained in this queue


get

public Object get()
Returns the first element of the queue.

Returns:
the first element of the queue; null if the queue is empty.

remove

public Object remove()
Removes the first element of the queue.

Returns:
the first element of the queue; null if the queue is empty.

merge

public void merge(Queue addend)
Add the elements of the addend queue at the end of this queue.

Parameters:
addend - the queue to be added

clear

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


toArray

public Object[] toArray()
Copies the element of the queue in an array of objects, in the queue order.


main

public static void main(String[] args)