edu.princeton.toy.lang
public class TWordBuffer extends java.lang.Object implements java.lang.Cloneable
Constructor and Description |
---|
TWordBuffer()
Constructs a new buffer with an initial capacity of 50.
|
TWordBuffer(int capacity)
Constructs a new buffer with the given initial capacity.
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.Object |
clone()
Returns a clone of this TWordBuffer (the array objects will be reallocated and copied.
|
boolean |
equals(java.lang.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.
|
public TWordBuffer()
public TWordBuffer(int capacity)
public java.lang.Object clone()
clone
in class java.lang.Object
public void clear()
public void add(TWordBuffer buffer)
buffer
- The TWordBuffer whose contents are to be added. A NullPointerException will be
thrown if this is null.public void add(TWord[] array)
array
- The array of TWords to add to this buffer. A NullPointerException will be
thrown if this is null.public void add(TWord[] array, int offset, int length)
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.public void add(TWord word)
word
- The TWord to be added. A NullPointerException will be thrown if this is null.public TWord pop()
public TWord getWord(int index)
index
- The index of the desired word.public int getSize()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The Object to compare this buffer to.