edu.princeton.toy.lang
Class TWordBuffer

java.lang.Object
  extended by edu.princeton.toy.lang.TWordBuffer
All Implemented Interfaces:
Cloneable

public class TWordBuffer
extends Object
implements Cloneable

TWordBuffer is essentially a vector for TWords. The main need for a TWordBuffer is that java.util.Vector allows null values to be added, whereas the Visual X-TOY really needs a vector class which does not permit null values. This class is thread-safe.


Constructor Summary
TWordBuffer()
          Constructs a new buffer with an initial capacity of 50.
TWordBuffer(int capacity)
          Constructs a new buffer with the given initial capacity.
 
Method Summary
 void add(TWord word)
          Adds the specified TWord to the end of the buffer.
 void add(TWord[] array)
          Adds the contents of one TWordBuffer to the end of this buffer.
 void add(TWord[] array, int offset, int length)
          Adds the contents of one TWordBuffer to the end of this buffer.
 void add(TWordBuffer buffer)
          Adds the contents of one TWordBuffer to the end of this buffer.
 void clear()
          Sets the size of the buffer to 0.
 Object clone()
          Returns a clone of this TWordBuffer (the array objects will be reallocated and copied.
 boolean equals(Object obj)
          Returns wheter or not two buffers contain the same data.
 int getSize()
          Returns the number of lines we have so far.
 TWord getWord(int index)
          Returns the TWord at the given index.
 TWord pop()
          Returns the TWord at the beginning of the buffer after removing it from the buffer.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TWordBuffer

public TWordBuffer()
Constructs a new buffer with an initial capacity of 50.


TWordBuffer

public TWordBuffer(int capacity)
Constructs a new buffer with the given initial capacity.

Method Detail

clone

public Object clone()
Returns a clone of this TWordBuffer (the array objects will be reallocated and copied.

Overrides:
clone in class Object
Returns:
Another instance of TWordBuffer with the same fields as this TWordBuffer.

clear

public void clear()
Sets the size of the buffer to 0.


add

public void add(TWordBuffer buffer)
Adds the contents of one TWordBuffer to the end of this buffer.

Parameters:
word - The TWordBuffer whose contents are to be added. A NullPointerException will be thrown if this is null.

add

public void add(TWord[] array)
Adds the contents of one TWordBuffer to the end of this buffer.

Parameters:
array - The array of TWords to add to this buffer. A NullPointerException will be thrown if this is null.

add

public void add(TWord[] array,
                int offset,
                int length)
Adds the contents of one TWordBuffer to the end of this buffer.

Parameters:
array - The array of TWords to add to this buffer. A NullPointerException will be thrown if this is null.
offset - The offset at which to begin copying. An invalid value will result in an ArrayIndexOutOfBoundsException.
length - The number of words to copy. An invalid value will result in an ArrayIndexOutOfBoundsException.

add

public void add(TWord word)
Adds the specified TWord to the end of the buffer.

Parameters:
word - The TWord to be added. A NullPointerException will be thrown if this is null.

pop

public TWord pop()
Returns the TWord at the beginning of the buffer after removing it from the buffer.

Parameters:
return - The TWord which was at the beginning of the buffer.

getWord

public TWord getWord(int index)
Returns the TWord at the given index.

Parameters:
index - The index of the desired word.
Returns:
The TWord at a given index;

getSize

public int getSize()
Returns the number of lines we have so far.

Returns:
the number of lines we have so far

equals

public boolean equals(Object obj)
Returns wheter or not two buffers contain the same data.

Overrides:
equals in class Object
Parameters:
obj - The Object to compare this buffer to.
Returns:
True iff obj is a TWordBuffer and contains the same data as this.