sdsu.util
Class CharQueue

java.lang.Object
  |
  +--sdsu.util.CharQueue

public final class CharQueue
extends java.lang.Object

This class implements a characater queue. Yes the JKD does contain a general queue. However that queue operates on objects. This queue just handles char elements. Use in IO operations where converting chars to objects will be too expensive.

Version:
1.0 21 August 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Field Summary
static int DEFAULT_QUEUE_SIZE
           
 
Constructor Summary
CharQueue()
           
CharQueue(int Size)
           
 
Method Summary
 int capacity()
          Returns the current number of locations for chars in queue
 void clear()
          Clears the queue so it has no more elements in it
 char dequeue()
          Removes front char from the queue and returns the char
 int dequeue(char[] charsRemoved)
          Fills charsRemoved with chars removed from the queue.
 int dequeue(char[] charsRemoved, int offset, int numCharsRequested)
          Places chars from queue in charsRemoved starting at charsRemoved[offset].
 char[] dequeueAll()
          Returns an array containing all chars in the queue.
 void enqueue(char charToAdd)
          Adds charToAdd to the end of the queue
 void enqueue(char[] charsToAdd)
          Adds all elements of charsToAdd to the end of the queue
 void enqueue(char[] charsToAdd, int offset, int numCharsToAdd)
          Adds numCharsToAdd elements of charsToAdd, starting with charsToAdd[offset] to the end of the queue
 void enqueue(java.lang.String charsToAdd)
          Adds charsToAdd to the end of the queue
 boolean isEmpty()
          Returns true if the queue is empty
 boolean isFull()
          Returns true if the queue is full
 char peek()
          Returns the front char from the queue without removing it
 int size()
          Returns the number of chars in the queue
 java.lang.String toString()
          Returns string representation of the queue
 int unusedCapacity()
          Returns the current number of unused locations in the queue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_QUEUE_SIZE

public static final int DEFAULT_QUEUE_SIZE
Constructor Detail

CharQueue

public CharQueue(int Size)

CharQueue

public CharQueue()
Method Detail

capacity

public int capacity()
Returns the current number of locations for chars in queue

isEmpty

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

isFull

public boolean isFull()
Returns true if the queue is full

size

public int size()
Returns the number of chars in the queue

toString

public java.lang.String toString()
Returns string representation of the queue
Overrides:
toString in class java.lang.Object

unusedCapacity

public int unusedCapacity()
Returns the current number of unused locations in the queue

dequeue

public char dequeue()
Removes front char from the queue and returns the char

dequeue

public int dequeue(char[] charsRemoved)
Fills charsRemoved with chars removed from the queue. If charsRemoved is larger than queue then charsRemoved is not completely filled
Returns:
actual number of chars put in charsRemoved

dequeue

public int dequeue(char[] charsRemoved,
                   int offset,
                   int numCharsRequested)
Places chars from queue in charsRemoved starting at charsRemoved[offset]. Will place numCharsRequested into charsRemoved if queue has enougth chars.
Returns:
actual number of chars put in charsRemoved

dequeueAll

public char[] dequeueAll()
Returns an array containing all chars in the queue. Afterwards queue is empty.

peek

public char peek()
Returns the front char from the queue without removing it

enqueue

public void enqueue(char charToAdd)
Adds charToAdd to the end of the queue

enqueue

public void enqueue(java.lang.String charsToAdd)
Adds charsToAdd to the end of the queue

enqueue

public void enqueue(char[] charsToAdd)
Adds all elements of charsToAdd to the end of the queue

enqueue

public void enqueue(char[] charsToAdd,
                    int offset,
                    int numCharsToAdd)
Adds numCharsToAdd elements of charsToAdd, starting with charsToAdd[offset] to the end of the queue

clear

public void clear()
Clears the queue so it has no more elements in it