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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The initial capacity of a buffer created with the default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the specified string to the rear of this buffer.
    void
    Adds the specified string to the front of this buffer.
    void
    Adds the specified string to the rear of this buffer.
    int
    The total number of elements that this buffer can hold without needing to be resized.
    void
    Removes all elements from this buffer.
    void
    Doubles the capacity of this buffer.
    int
    Returns the number of elements that can be added to this buffer before before it becomes full.
    Returns but does not remove the string at the front of this buffer.
    boolean
    Returns true if this buffer contains no elements, returns false otherwise.
    boolean
    Returns true if this buffer is full, returns false otherwise.
    Returns but does not remove the string at the rear of this buffer.
    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.
    int
    Returns the number of elements in this buffer.
    Returns a string representation of this buffer.
  • Field Details

    • DEFAULT_CAPACITY

      static final int DEFAULT_CAPACITY
      The initial capacity of a buffer created with the default constructor.
      See Also:
  • Method Details

    • add

      void add(String s)
      Adds the specified string to the rear of this buffer.
      Parameters:
      s - string to be added to this buffer
    • addRear

      void addRear(String s)
      Adds the specified string to the rear of this buffer.
      Parameters:
      s - string to be added to this buffer
    • addFront

      void addFront(String s)
      Adds the specified string to the front of this buffer.
      Parameters:
      s - string to be added to this buffer
    • remove

      String remove() throws EmptyBufferException
      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

      String removeRear() throws EmptyBufferException
      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

      String removeFront() throws EmptyBufferException
      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".
      Overrides:
      toString in class Object
      Returns:
      a string representation of this buffer