Class ExpandableArrayBuffer
java.lang.Object
ExpandableArrayBuffer
- All Implemented Interfaces:
ExpandableBuffer
An expandable circular buffer implemented with an array.
- Author:
- Kevin Lillis
-
Field Summary
Fields inherited from interface ExpandableBuffer
DEFAULT_CAPACITY -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a buffer with the default capacity.ExpandableArrayBuffer(int initialCapacity) Constructs a buffer with the given capacity. -
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.
-
Constructor Details
-
ExpandableArrayBuffer
public ExpandableArrayBuffer()Constructs a buffer with the default capacity. -
ExpandableArrayBuffer
public ExpandableArrayBuffer(int initialCapacity) Constructs a buffer with the given capacity.- Parameters:
initialCapacity- The initial capacity of this buffer.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:ExpandableBufferReturns true if this buffer contains no elements, returns false otherwise.- Specified by:
isEmptyin interfaceExpandableBuffer- Returns:
- true if this buffer contains no elements, returns false otherwise.
-
isFull
public boolean isFull()Description copied from interface:ExpandableBufferReturns true if this buffer is full, returns false otherwise.- Specified by:
isFullin interfaceExpandableBuffer- Returns:
- true if this buffer is full, returns false otherwise.
-
add
Description copied from interface:ExpandableBufferAdds the specified string to the rear of this buffer.- Specified by:
addin interfaceExpandableBuffer- Parameters:
str- string to be added to this buffer
-
addFront
Description copied from interface:ExpandableBufferAdds the specified string to the front of this buffer.- Specified by:
addFrontin interfaceExpandableBuffer- Parameters:
str- string to be added to this buffer
-
addRear
Description copied from interface:ExpandableBufferAdds the specified string to the rear of this buffer.- Specified by:
addRearin interfaceExpandableBuffer- Parameters:
str- string to be added to this buffer
-
front
Description copied from interface:ExpandableBufferReturns but does not remove the string at the front of this buffer.- Specified by:
frontin interfaceExpandableBuffer- Returns:
- the string at the front of this buffer.
-
rear
Description copied from interface:ExpandableBufferReturns but does not remove the string at the rear of this buffer.- Specified by:
rearin interfaceExpandableBuffer- Returns:
- the string at the rear of this buffer.
-
remove
Description copied from interface:ExpandableBufferRemoves and returns the string at the front of this buffer.- Specified by:
removein interfaceExpandableBuffer- Returns:
- the string at the front of this buffer
-
removeFront
Description copied from interface:ExpandableBufferRemoves and returns the string at the front of this buffer.- Specified by:
removeFrontin interfaceExpandableBuffer- Returns:
- the string at the front of this buffer
-
removeRear
Description copied from interface:ExpandableBufferRemoves and returns the string at the rear of this buffer.- Specified by:
removeRearin interfaceExpandableBuffer- Returns:
- the string at the rear of this buffer
-
doubleCapacity
public void doubleCapacity()Description copied from interface:ExpandableBufferDoubles the capacity of this buffer.- Specified by:
doubleCapacityin interfaceExpandableBuffer
-
size
public int size()Description copied from interface:ExpandableBufferReturns the number of elements in this buffer.- Specified by:
sizein interfaceExpandableBuffer- Returns:
- the number of elements in this buffer
-
free
public int free()Description copied from interface:ExpandableBufferReturns the number of elements that can be added to this buffer before before it becomes full.- Specified by:
freein interfaceExpandableBuffer- Returns:
- the number of elements that can be added to this buffer before it becomes full
-
capacity
public int capacity()Description copied from interface:ExpandableBufferThe total number of elements that this buffer can hold without needing to be resized.- Specified by:
capacityin interfaceExpandableBuffer- Returns:
- the number of elements that this buffer can hold without needing to be resized
-
clear
public void clear()Description copied from interface:ExpandableBufferRemoves all elements from this buffer. If the buffer is empty, nothing is done.- Specified by:
clearin interfaceExpandableBuffer
-
toString
Description copied from interface:ExpandableBufferReturns 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".- Specified by:
toStringin interfaceExpandableBuffer- Overrides:
toStringin classObject- Returns:
- a string representation of this buffer
-