net.sf.vex.dom
Class GapContent

java.lang.Object
  |
  +--net.sf.vex.dom.GapContent
All Implemented Interfaces:
Content

public class GapContent
extends java.lang.Object
implements Content

Implementation of the Content interface that manages changes efficiently. Implements a buffer that keeps its free space (the "gap") at the location of the last change. Insertions at the start of the gap require no other chars to be moved so long as the insertion is smaller than the gap. Deletions that end of the gap are also very efficent. Furthermore, changes near the gap require relatively few characters to be moved.


Constructor Summary
GapContent(int initialCapacity)
          Class constructor.
 
Method Summary
 Position createPosition(int offset)
          Creates a new Position object at the given initial offset.
 int getLength()
          Return the length of the content.
 java.lang.String getString(int offset, int length)
          Gets a substring of the content.
 void insertString(int offset, java.lang.String s)
          Insert a string into the content.
 void remove(int offset, int length)
          Deletes the given range of characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GapContent

public GapContent(int initialCapacity)
Class constructor.

Parameters:
initialCapacity - initial capacity of the content.
Method Detail

createPosition

public Position createPosition(int offset)
Creates a new Position object at the given initial offset.

Specified by:
createPosition in interface Content
Parameters:
offset - initial offset of the position

insertString

public void insertString(int offset,
                         java.lang.String s)
Insert a string into the content.

Specified by:
insertString in interface Content
Parameters:
offset - Offset at which to insert the string.
s - String to insert.

remove

public void remove(int offset,
                   int length)
Deletes the given range of characters.

Specified by:
remove in interface Content
Parameters:
offset - Offset from which characters should be deleted.
length - Number of characters to delete.

getString

public java.lang.String getString(int offset,
                                  int length)
Gets a substring of the content.

Specified by:
getString in interface Content
Parameters:
offset - Offset at which the string begins.
length - Number of characters to return.

getLength

public int getLength()
Return the length of the content.

Specified by:
getLength in interface Content