Class ExpandableArrayBuffer

java.lang.Object
ExpandableArrayBuffer
All Implemented Interfaces:
ExpandableBuffer

public class ExpandableArrayBuffer extends Object implements ExpandableBuffer
An expandable circular buffer implemented with an array.
Author:
Kevin Lillis
  • Field Summary

    Fields inherited from interface ExpandableBuffer

    DEFAULT_CAPACITY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a buffer with the default capacity.
    ExpandableArrayBuffer(int initialCapacity)
    Constructs a buffer with the given capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String str)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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: ExpandableBuffer
      Returns true if this buffer contains no elements, returns false otherwise.
      Specified by:
      isEmpty in interface ExpandableBuffer
      Returns:
      true if this buffer contains no elements, returns false otherwise.
    • isFull

      public boolean isFull()
      Description copied from interface: ExpandableBuffer
      Returns true if this buffer is full, returns false otherwise.
      Specified by:
      isFull in interface ExpandableBuffer
      Returns:
      true if this buffer is full, returns false otherwise.
    • add

      public void add(String str)
      Description copied from interface: ExpandableBuffer
      Adds the specified string to the rear of this buffer.
      Specified by:
      add in interface ExpandableBuffer
      Parameters:
      str - string to be added to this buffer
    • addFront

      public void addFront(String str)
      Description copied from interface: ExpandableBuffer
      Adds the specified string to the front of this buffer.
      Specified by:
      addFront in interface ExpandableBuffer
      Parameters:
      str - string to be added to this buffer
    • addRear

      public void addRear(String str)
      Description copied from interface: ExpandableBuffer
      Adds the specified string to the rear of this buffer.
      Specified by:
      addRear in interface ExpandableBuffer
      Parameters:
      str - string to be added to this buffer
    • front

      public String front()
      Description copied from interface: ExpandableBuffer
      Returns but does not remove the string at the front of this buffer.
      Specified by:
      front in interface ExpandableBuffer
      Returns:
      the string at the front of this buffer.
    • rear

      public String rear()
      Description copied from interface: ExpandableBuffer
      Returns but does not remove the string at the rear of this buffer.
      Specified by:
      rear in interface ExpandableBuffer
      Returns:
      the string at the rear of this buffer.
    • remove

      public String remove()
      Description copied from interface: ExpandableBuffer
      Removes and returns the string at the front of this buffer.
      Specified by:
      remove in interface ExpandableBuffer
      Returns:
      the string at the front of this buffer
    • removeFront

      public String removeFront()
      Description copied from interface: ExpandableBuffer
      Removes and returns the string at the front of this buffer.
      Specified by:
      removeFront in interface ExpandableBuffer
      Returns:
      the string at the front of this buffer
    • removeRear

      public String removeRear()
      Description copied from interface: ExpandableBuffer
      Removes and returns the string at the rear of this buffer.
      Specified by:
      removeRear in interface ExpandableBuffer
      Returns:
      the string at the rear of this buffer
    • doubleCapacity

      public void doubleCapacity()
      Description copied from interface: ExpandableBuffer
      Doubles the capacity of this buffer.
      Specified by:
      doubleCapacity in interface ExpandableBuffer
    • size

      public int size()
      Description copied from interface: ExpandableBuffer
      Returns the number of elements in this buffer.
      Specified by:
      size in interface ExpandableBuffer
      Returns:
      the number of elements in this buffer
    • free

      public int free()
      Description copied from interface: ExpandableBuffer
      Returns the number of elements that can be added to this buffer before before it becomes full.
      Specified by:
      free in interface ExpandableBuffer
      Returns:
      the number of elements that can be added to this buffer before it becomes full
    • capacity

      public int capacity()
      Description copied from interface: ExpandableBuffer
      The total number of elements that this buffer can hold without needing to be resized.
      Specified by:
      capacity in interface ExpandableBuffer
      Returns:
      the number of elements that this buffer can hold without needing to be resized
    • clear

      public void clear()
      Description copied from interface: ExpandableBuffer
      Removes all elements from this buffer. If the buffer is empty, nothing is done.
      Specified by:
      clear in interface ExpandableBuffer
    • toString

      public String toString()
      Description copied from interface: ExpandableBuffer
      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".
      Specified by:
      toString in interface ExpandableBuffer
      Overrides:
      toString in class Object
      Returns:
      a string representation of this buffer