gnu.lists

Class GapVector

Implemented Interfaces:
java.util.List, Consumable, Sequence
Known Direct 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, ELEMENT_VALUE, EOF_VALUE, FLOAT_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, eofValue

Constructor Summary

GapVector()
GapVector(SimpleVector base)

Method Summary

void
add(int index, Object o)
See java.util.List.
protected int
addPos(int ipos, 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(Object value)
void
fillPosRange(int fromPos, int toPos, 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.
Object
get(int index)
See java.util.List.
int
getNextKind(int ipos)
int
getSegment(int where, int len)
If needed, move the gap so the given segment is contiguous.
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.
Object
set(int index, Object value)
protected void
shiftGap(int newGapStart)
int
size()
See java.util.List.

Methods inherited from class gnu.lists.AbstractSequence

add, add, addAll, addAll, addPos, clear, compare, compare, compare, consume, consumeNext, consumePosRange, contains, containsAll, copyPos, createPos, createRelativePos, elements, endPos, equals, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIterator, getIteratorAtPos, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getPosNext, getPosPrevious, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasNext, hasPrevious, hashCode, indexOf, isAfterPos, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextIndex, nextMatching, nextPos, parentPos, previousPos, rank, releasePos, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setPosNext, setPosPrevious, size, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported, unsupportedException

Field Details

base

public SimpleVector base

gapEnd

public int gapEnd

gapStart

public int gapStart

Constructor Details

GapVector

protected GapVector()

GapVector

public GapVector(SimpleVector base)

Method Details

add

public void add(int index,
                Object o)
See java.util.List.
Overrides:
add in interface AbstractSequence

addPos

protected int addPos(int ipos,
                     Object value)
Add a value at a specified Pos.
Overrides:
addPos in interface AbstractSequence
Returns:
the updated Pos, which is after the inserted value..

consumePosRange

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

createPos

public int createPos(int index,
                     boolean isAfter)
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.
Overrides:
createPos in interface AbstractSequence
Parameters:
index - offset from beginning of desired position
isAfter - should the position have the isAfter property

fill

public void fill(Object value)
Specified by:
fill in interface Sequence
Overrides:
fill in interface AbstractSequence

fillPosRange

public void fillPosRange(int fromPos,
                         int toPos,
                         Object value)
Overrides:
fillPosRange in interface AbstractSequence

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.

get

public Object get(int index)
See java.util.List.
Specified by:
get in interface Sequence
Overrides:
get in interface AbstractSequence

getNextKind

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

getSegment

public int getSegment(int where,
                      int len)
If needed, move the gap so the given segment is contiguous.
Returns:
the offset in the base array containing the segment, or -1 if the parameters are bad.

hasNext

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

isAfterPos

protected boolean isAfterPos(int ipos)
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 interface AbstractSequence

nextIndex

protected int nextIndex(int ipos)
Get the offset from the beginning corresponding to a position cookie.
Overrides:
nextIndex in interface AbstractSequence

removePosRange

protected void removePosRange(int ipos0,
                              int ipos1)
Remove a range where each end-point is a position in a container.
Overrides:
removePosRange in interface AbstractSequence
Parameters:
ipos0 - start of range, as a poistion
ipos1 - end of range

set

public Object set(int index,
                  Object value)
Specified by:
set in interface Sequence
Overrides:
set in interface AbstractSequence

shiftGap

protected void shiftGap(int newGapStart)

size

public int size()
See java.util.List.
Specified by:
size in interface Sequence
Overrides:
size in interface AbstractSequence