Class Buffer

  • All Implemented Interfaces:
    java.lang.CharSequence

    public class Buffer
    extends java.lang.Object
    implements java.lang.CharSequence
    Represents character buffer with fixed capacity. Implements CharSequence methods and in addition queue methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private char[] buffer  
      private int head  
      private int size  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Buffer​(char[] buffer, int head, int size)  
        Buffer​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)  
      void dequeue()  
      void enqueue​(char character)  
      void forceEnqueue​(char character)
      This is the same as: if (buffer.length() * == buffer.getCapacity()) buffer.dequeue(); buffer.enqueue(character);
      int getCapacity()  
      private boolean isEmpty()  
      private boolean isFull()  
      int length()  
      java.lang.CharSequence subSequence​(int start, int end)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.CharSequence

        chars, codePoints
    • Field Detail

      • buffer

        private char[] buffer
      • head

        private int head
      • size

        private int size
    • Constructor Detail

      • Buffer

        private Buffer​(char[] buffer,
                       int head,
                       int size)
      • Buffer

        public Buffer​(int capacity)
    • Method Detail

      • getCapacity

        public int getCapacity()
      • enqueue

        public void enqueue​(char character)
      • dequeue

        public void dequeue()
      • forceEnqueue

        public void forceEnqueue​(char character)
        This is the same as: if (buffer.length() * == buffer.getCapacity()) buffer.dequeue(); buffer.enqueue(character);
        Parameters:
        character -
      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
      • isEmpty

        private boolean isEmpty()
      • isFull

        private boolean isFull()