Search this API

y.util
Class BoundedQueue

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

public class BoundedQueue
extends java.lang.Object

This class represents an efficient queue of bounded size.

 

Constructor Summary
BoundedQueue(java.util.Collection collection, int capacity)
          Creates a new instance of BoundedQueue copying the values in the given collection to the queue.
BoundedQueue(int capacity)
          Creates a new instance of BoundedQueue.
BoundedQueue(java.util.Iterator it, int capacity)
          Creates a new instance of BoundedQueue copying the values from the given iterator to the queue.
BoundedQueue(java.lang.Object[] array, int capacity)
          Creates a new instance of BoundedQueue copying the values in the given 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 given list to the queue.
 
Method Summary
 void append(java.lang.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.
 java.lang.Object dequeue()
          Returns the front element in this queue and removes it from the queue.
 void enqueue(java.lang.Object x)
          Appends x to the rear of this queue.
 boolean isEmpty()
          Returns true if this queue is empty.
 java.lang.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.
 java.lang.Object top()
          Returns the front element in this queue.
 java.lang.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(java.lang.Object[] array,
                    int capacity)
Creates a new instance of BoundedQueue copying the values in the given array to the queue.

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

BoundedQueue

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

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

BoundedQueue

public BoundedQueue(java.util.Iterator it,
                    int capacity)
Creates a new instance of BoundedQueue copying the values from the given iterator 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 given 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 java.lang.Object top()
Returns the front element in this queue.

Precondition:
!isEmpty()

dequeue

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

Precondition:
!isEmpty()

pop

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

Same as dequeue()

Precondition:
!isEmpty()

enqueue

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

Precondition:
size() < capacity()

append

public void append(java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

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