Search this API

y.util
Class BoundedQueue

java.lang.Object
  extended by y.util.BoundedQueue

public class BoundedQueue
extends Object

This class represents an efficient queue of bounded size.


Constructor Summary
BoundedQueue(Collection collection, int capacity)
          Creates a new instance of BoundedQueue copying the values in array to the queue.
BoundedQueue(int capacity)
          Creates a new instance of BoundedQueue.
BoundedQueue(Iterator it, int capacity)
          Creates a new instance of BoundedQueue copying the values in array to the queue.
BoundedQueue(Object[] array, int capacity)
          Creates a new instance of BoundedQueue copying the values in array to the queue.
BoundedQueue(YCursor cr, int capacity)
          Creates a new instance of BoundedQueue copying the values from the cursor to the queue
BoundedQueue(YList list, int capacity)
          Creates a new instance of BoundedQueue copying the values in the list to the queue
 
Method Summary
 void append(Object x)
          Appends x to the rear of this queue.
 int capacity()
          Returns the maximal number of elements that this queue can hold.
 void clear()
          Removes all elements from this queue.
 Object dequeue()
          Returns the front element in this queue and removes it from the queue.
 void enqueue(Object x)
          Appends x to the rear of this queue.
 boolean isEmpty()
          Returns true if this queue is empty.
 Object pop()
          Returns the front element in this queue and removes it from the queue.
 int size()
          Returns the number of elements in this queue.
 Object top()
          Returns the front element in this queue.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundedQueue

public BoundedQueue(int capacity)
Creates a new instance of BoundedQueue.

Parameters:
capacity - the maximum capacity of this queue.

BoundedQueue

public BoundedQueue(Object[] array,
                    int capacity)
Creates a new instance of BoundedQueue copying the values in array to the queue.

Parameters:
array - the array to be used as the queue
capacity - the maximum capacity of the queue

BoundedQueue

public BoundedQueue(Collection collection,
                    int capacity)
Creates a new instance of BoundedQueue copying the values in array to the queue.

Parameters:
collection - the elements which reside in the queue initially
capacity - the maximal capacity of the queue

BoundedQueue

public BoundedQueue(Iterator it,
                    int capacity)
Creates a new instance of BoundedQueue copying the values in array to the queue.

Parameters:
it - an iterator granting access to the initial elements of the queue.
capacity - the maximal capacity of the queue

BoundedQueue

public BoundedQueue(YList list,
                    int capacity)
Creates a new instance of BoundedQueue copying the values in the list to the queue

Parameters:
list - the elements which reside in the queue initially
capacity - the maximum capacity of the queue

BoundedQueue

public BoundedQueue(YCursor cr,
                    int capacity)
Creates a new instance of BoundedQueue copying the values from the cursor to the queue

Parameters:
cr - a cursor granting access to the initial elements of the queue.
capacity - the maximal capacity of the queue
Method Detail

top

public Object top()
Returns the front element in this queue.

Precondition:
!isEmpty()

dequeue

public Object dequeue()
Returns the front element in this queue and removes it from the queue.

Precondition:
!isEmpty()

pop

public Object pop()
Returns the front element in this queue and removes it from the queue.

Same as dequeue()

Precondition:
!isEmpty()

enqueue

public void enqueue(Object x)
Appends x to the rear of this queue.

Precondition:
size() < capacity()

append

public void append(Object x)
Appends x to the rear of this queue. Same as enqueue(Object).


clear

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


size

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


capacity

public int capacity()
Returns the maximal number of elements that this queue can hold.


isEmpty

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


toString

public String toString()
Overrides:
toString in class Object

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.