Interface ExpandableBuffer
- All Known Implementing Classes:
ExpandableArrayBuffer
public interface ExpandableBuffer
A circular buffer of Strings implemented with an array. When an element is
added to a full buffer, the array is increased so that the capacity of the
buffer is doubled.
- Author:
- Kevin Lillis
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe initial capacity of a buffer created with the default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified string to the rear of this buffer.voidAdds the specified string to the front of this buffer.voidAdds the specified string to the rear of this buffer.intcapacity()The total number of elements that this buffer can hold without needing to be resized.voidclear()Removes all elements from this buffer.voidDoubles the capacity of this buffer.intfree()Returns the number of elements that can be added to this buffer before before it becomes full.front()Returns but does not remove the string at the front of this buffer.booleanisEmpty()Returns true if this buffer contains no elements, returns false otherwise.booleanisFull()Returns true if this buffer is full, returns false otherwise.rear()Returns but does not remove the string at the rear of this buffer.remove()Removes and returns the string at the front of this buffer.Removes and returns the string at the front of this buffer.Removes and returns the string at the rear of this buffer.intsize()Returns the number of elements in this buffer.toString()Returns a string representation of this buffer.
-
Field Details
-
DEFAULT_CAPACITY
static final int DEFAULT_CAPACITYThe initial capacity of a buffer created with the default constructor.- See Also:
-
-
Method Details
-
add
Adds the specified string to the rear of this buffer.- Parameters:
s- string to be added to this buffer
-
addRear
Adds the specified string to the rear of this buffer.- Parameters:
s- string to be added to this buffer
-
addFront
Adds the specified string to the front of this buffer.- Parameters:
s- string to be added to this buffer
-
remove
Removes and returns the string at the front of this buffer.- Returns:
- the string at the front of this buffer
- Throws:
EmptyBufferException- if the buffer is empty
-
removeRear
Removes and returns the string at the rear of this buffer.- Returns:
- the string at the rear of this buffer
- Throws:
EmptyBufferException- if the buffer is empty
-
removeFront
Removes and returns the string at the front of this buffer.- Returns:
- the string at the front of this buffer
- Throws:
EmptyBufferException- if the buffer is empty
-
front
Returns but does not remove the string at the front of this buffer.- Returns:
- the string at the front of this buffer.
- Throws:
EmptyBufferException- if the buffer is empty
-
rear
Returns but does not remove the string at the rear of this buffer.- Returns:
- the string at the rear of this buffer.
- Throws:
EmptyBufferException- if the buffer is empty
-
capacity
int capacity()The total number of elements that this buffer can hold without needing to be resized.- Returns:
- the number of elements that this buffer can hold without needing to be resized
-
size
int size()Returns the number of elements in this buffer.- Returns:
- the number of elements in this buffer
-
free
int free()Returns the number of elements that can be added to this buffer before before it becomes full.- Returns:
- the number of elements that can be added to this buffer before it becomes full
-
isEmpty
boolean isEmpty()Returns true if this buffer contains no elements, returns false otherwise.- Returns:
- true if this buffer contains no elements, returns false otherwise.
-
isFull
boolean isFull()Returns true if this buffer is full, returns false otherwise.- Returns:
- true if this buffer is full, returns false otherwise.
-
clear
void clear()Removes all elements from this buffer. If the buffer is empty, nothing is done. -
doubleCapacity
void doubleCapacity()Doubles the capacity of this buffer. -
toString
String toString()Returns a string representation of this buffer. The string representation consists of a list of this buffer's Strings in order from front to rear, enclosed in square brackets ("[]"). Adjacent Strings are separated by the characters ", " (comma and space). The letter "F" should appear to the left to indicate the front of the buffer and the letter "R" should appear to the right to indicate the rear of the buffer. Fore example, a buffer containing "A", "B", and "C" would be represented as "F[A, B, C]R".
-