Class BufferImpl

  • All Implemented Interfaces:
    Buffer

    public class BufferImpl
    extends java.lang.Object
    implements Buffer
    A holder for a StringBuilder that also contains the current cursor position.
    Since:
    2.0
    Author:
    Marc Prud'hommeaux, Jason Dillon
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int atChar​(int i)  
      boolean backspace()
      Issue a backspace.
      int backspace​(int num)
      Issue num backspaces.
      boolean clear()  
      BufferImpl copy()  
      void copyFrom​(Buffer buf)  
      int currChar()  
      boolean currChar​(int ch)  
      int cursor()  
      boolean cursor​(int position)
      Move the cursor position to the specified absolute index.
      boolean delete()  
      int delete​(int num)  
      boolean down()  
      int length()  
      int move​(int num)
      Move the cursor where characters.
      boolean moveXY​(int dx, int dy)  
      int nextChar()  
      int prevChar()  
      java.lang.String substring​(int start)  
      java.lang.String substring​(int start, int end)  
      java.lang.String toString()  
      boolean up()  
      java.lang.String upToCursor()  
      void write​(int c)
      Write the specific character into the buffer, setting the cursor position ahead one.
      void write​(int c, boolean overTyping)
      Write the specific character into the buffer, setting the cursor position ahead one.
      void write​(java.lang.CharSequence str)
      Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
      void write​(java.lang.CharSequence str, boolean overTyping)  
      void zeroOut()
      Clear any internal buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BufferImpl

        public BufferImpl()
      • BufferImpl

        public BufferImpl​(int size)
    • Method Detail

      • cursor

        public int cursor()
        Specified by:
        cursor in interface Buffer
      • length

        public int length()
        Specified by:
        length in interface Buffer
      • currChar

        public boolean currChar​(int ch)
        Specified by:
        currChar in interface Buffer
      • currChar

        public int currChar()
        Specified by:
        currChar in interface Buffer
      • prevChar

        public int prevChar()
        Specified by:
        prevChar in interface Buffer
      • nextChar

        public int nextChar()
        Specified by:
        nextChar in interface Buffer
      • atChar

        public int atChar​(int i)
        Specified by:
        atChar in interface Buffer
      • write

        public void write​(int c)
        Write the specific character into the buffer, setting the cursor position ahead one.
        Specified by:
        write in interface Buffer
        Parameters:
        c - the character to insert
      • write

        public void write​(int c,
                          boolean overTyping)
        Write the specific character into the buffer, setting the cursor position ahead one. The text may overwrite or insert based on the current setting of overTyping.
        Specified by:
        write in interface Buffer
        Parameters:
        c - the character to insert
      • write

        public void write​(java.lang.CharSequence str)
        Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
        Specified by:
        write in interface Buffer
      • write

        public void write​(java.lang.CharSequence str,
                          boolean overTyping)
        Specified by:
        write in interface Buffer
      • clear

        public boolean clear()
        Specified by:
        clear in interface Buffer
      • substring

        public java.lang.String substring​(int start)
        Specified by:
        substring in interface Buffer
      • substring

        public java.lang.String substring​(int start,
                                          int end)
        Specified by:
        substring in interface Buffer
      • upToCursor

        public java.lang.String upToCursor()
        Specified by:
        upToCursor in interface Buffer
      • cursor

        public boolean cursor​(int position)
        Move the cursor position to the specified absolute index.
        Specified by:
        cursor in interface Buffer
      • move

        public int move​(int num)
        Move the cursor where characters.
        Specified by:
        move in interface Buffer
        Parameters:
        num - If less than 0, move abs(where) to the left, otherwise move where to the right.
        Returns:
        The number of spaces we moved
      • up

        public boolean up()
        Specified by:
        up in interface Buffer
      • down

        public boolean down()
        Specified by:
        down in interface Buffer
      • moveXY

        public boolean moveXY​(int dx,
                              int dy)
        Specified by:
        moveXY in interface Buffer
      • backspace

        public int backspace​(int num)
        Issue num backspaces.
        Specified by:
        backspace in interface Buffer
        Returns:
        the number of characters backed up
      • backspace

        public boolean backspace()
        Issue a backspace.
        Specified by:
        backspace in interface Buffer
        Returns:
        true if successful
      • delete

        public int delete​(int num)
        Specified by:
        delete in interface Buffer
      • delete

        public boolean delete()
        Specified by:
        delete in interface Buffer
      • toString

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

        public void zeroOut()
        Description copied from interface: Buffer
        Clear any internal buffer.
        Specified by:
        zeroOut in interface Buffer