gnu.lists
Class GapVector

java.lang.Object
  extended by gnu.lists.AbstractSequence
      extended by gnu.lists.GapVector
All Implemented Interfaces:
Consumable, Sequence, java.lang.Iterable, java.util.Collection, java.util.List
Direct Known Subclasses:
LineOffsets, StableVector, SwtCharBuffer

public class GapVector
extends AbstractSequence
implements Sequence

An array with a gap in the middle, allowing efficient insert and delete. The actual storage is delegated to a SimpleVector, so the element type depends on the sub-class of SimpleVector used.


Field Summary
 SimpleVector base
           
 int gapEnd
           
 int gapStart
           
 
Fields inherited from interface gnu.lists.Sequence
ATTRIBUTE_VALUE, BOOLEAN_VALUE, CDATA_VALUE, CHAR_VALUE, COMMENT_VALUE, DOCUMENT_VALUE, DOUBLE_VALUE, EOF_VALUE, eofValue, FLOAT_VALUE, GROUP_VALUE, INT_S16_VALUE, INT_S32_VALUE, INT_S64_VALUE, INT_S8_VALUE, INT_U16_VALUE, INT_U32_VALUE, INT_U64_VALUE, INT_U8_VALUE, OBJECT_VALUE, PRIM_VALUE, PROCESSING_INSTRUCTION_VALUE, TEXT_BYTE_VALUE
 
Constructor Summary
GapVector(SimpleVector base)
           
 
Method Summary
 void add(int index, java.lang.Object o)
          See java.util.List.
protected  int addPos(int ipos, java.lang.Object value)
          Add a value at a specified Pos.
 void consumePosRange(int iposStart, int iposEnd, Consumer out)
           
 int createPos(int index, boolean isAfter)
          Generate a position at a given index.
 void fill(java.lang.Object value)
           
 void fillPosRange(int fromPos, int toPos, java.lang.Object value)
           
protected  void gapReserve(int size)
          Make sure gap is at least 'size' elements long.
protected  void gapReserve(int where, int size)
          Adjust gap to 'where', and make sure it is least `size' elements long.
 java.lang.Object get(int index)
          See java.util.List.
 int getNextKind(int ipos)
           
 boolean hasNext(int ipos)
           
protected  boolean isAfterPos(int ipos)
          Tests whether the position has the "isAfter" property.
protected  int nextIndex(int ipos)
          Get the offset from the beginning corresponding to a position cookie.
protected  void removePosRange(int ipos0, int ipos1)
          Remove a range where each end-point is a position in a container.
 java.lang.Object set(int index, java.lang.Object value)
           
protected  void shiftGap(int newGapStart)
           
 int size()
          See java.util.List.
 
Methods inherited from class gnu.lists.AbstractSequence
add, addAll, addAll, append, append, append, baseUriOfPos, clear, compare, compare, compare, consume, consumeNext, contains, containsAll, copyPos, createRelativePos, elements, endPos, equals, equals, fill, firstAttributePos, firstChildPos, fromEndIndex, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIterator, getIteratorAtPos, getLowBound, getNextTypeName, getNextTypeObject, getPosNext, getPosPrevious, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hashCode, hasPrevious, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, nextPos, parentPos, previousPos, rank, releasePos, remove, remove, removeAll, removePos, retainAll, set, setPosNext, setPosPrevious, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gnu.lists.Sequence
elements, isEmpty
 
Methods inherited from interface java.util.List
add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, subList, toArray, toArray
 
Methods inherited from interface gnu.lists.Consumable
consume
 

Field Detail

base

public SimpleVector base

gapStart

public int gapStart

gapEnd

public int gapEnd
Constructor Detail

GapVector

public GapVector(SimpleVector base)
Method Detail

size

public int size()
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
size in interface Sequence
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class AbstractSequence

hasNext

public boolean hasNext(int ipos)
Overrides:
hasNext in class AbstractSequence

getNextKind

public int getNextKind(int ipos)
Overrides:
getNextKind in class AbstractSequence

get

public java.lang.Object get(int index)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
get in interface Sequence
Specified by:
get in interface java.util.List
Specified by:
get in class AbstractSequence

set

public java.lang.Object set(int index,
                            java.lang.Object value)
Specified by:
set in interface java.util.List
Overrides:
set in class AbstractSequence

fill

public void fill(java.lang.Object value)
Specified by:
fill in interface Sequence
Overrides:
fill in class AbstractSequence

fillPosRange

public void fillPosRange(int fromPos,
                         int toPos,
                         java.lang.Object value)
Overrides:
fillPosRange in class AbstractSequence

shiftGap

protected void shiftGap(int newGapStart)

gapReserve

protected void gapReserve(int size)
Make sure gap is at least 'size' elements long.


gapReserve

protected void gapReserve(int where,
                          int size)
Adjust gap to 'where', and make sure it is least `size' elements long.


addPos

protected int addPos(int ipos,
                     java.lang.Object value)
Description copied from class: AbstractSequence
Add a value at a specified Pos.

Overrides:
addPos in class AbstractSequence
Returns:
the updated Pos, which is after the inserted value..

add

public void add(int index,
                java.lang.Object o)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
add in interface java.util.List
Overrides:
add in class AbstractSequence

removePosRange

protected void removePosRange(int ipos0,
                              int ipos1)
Description copied from class: AbstractSequence
Remove a range where each end-point is a position in a container.

Overrides:
removePosRange in class AbstractSequence
Parameters:
ipos0 - start of range, as a poistion
ipos1 - end of range

createPos

public int createPos(int index,
                     boolean isAfter)
Description copied from class: AbstractSequence
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.

Specified by:
createPos in class AbstractSequence
Parameters:
index - offset from beginning of desired position
isAfter - should the position have the isAfter property

isAfterPos

protected boolean isAfterPos(int ipos)
Description copied from class: AbstractSequence
Tests whether the position has the "isAfter" property. I.e. if something is inserted at the position, will the iterator end up being after the new data?

Overrides:
isAfterPos in class AbstractSequence

nextIndex

protected int nextIndex(int ipos)
Description copied from class: AbstractSequence
Get the offset from the beginning corresponding to a position cookie.

Overrides:
nextIndex in class AbstractSequence

consumePosRange

public void consumePosRange(int iposStart,
                            int iposEnd,
                            Consumer out)
Overrides:
consumePosRange in class AbstractSequence