APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text

pack-priv abstract Class GapVector

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
javax.swing.text.GapContent, javax.swing.text.GapContent.MarkVector
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable

An implementation of a gapped buffer similar to that used by emacs. The underlying storage is a java array of some type, which is known only by the subclass of this class. The array has a gap somewhere. The gap is moved to the location of changes to take advantage of common behavior where most changes occur in the same location. Changes that occur at a gap boundary are generally cheap and moving the gap is generally cheaper than moving the array contents directly to accommodate the change.
Author
Timothy Prinzing
See Also
GapContent

Field Summary

Modifier and TypeField and Description
private Object
array

The array of items.

private int
g0

start of gap in the array

private int
g1

end of gap in the array

Constructor Summary

AccessConstructor and Description
public
GapVector()

Creates a new GapVector object.

public
GapVector(int
the initial size
initialLength
)

Creates a new GapVector object, with the initial size specified.

Method Summary

Modifier and TypeMethod and Description
protected abstract Object

Returns:

the java array of some type
allocateArray
(int
the length of the array
len
)

Allocate an array to store items of the type appropriate (which is determined by the subclass).

pack-priv void
close(int position, int nItems)

Delete nItems at position.

protected final Object

Returns:

the java array of some type
getArray
()

Access to the array.

protected abstract int

Returns:

the length of the array
getArrayLength
()

Get the length of the allocated array.

protected final int

Returns:

the end of the gap
getGapEnd
()

Access to the end of the gap.

protected final int

Returns:

the start of the gap
getGapStart
()

Access to the start of the gap.

pack-priv int

Returns:

the new size of the storage array
getNewArraySize
(int
the size which is necessary for new content
reqSize
)

Calculates a new size of the storage array depending on required capacity.

pack-priv int

Returns:

the location that the caller should fill in
open
(int position, int nItems)

Make space for the given number of items at the given location.

protected void
replace(int
the location to make the replacement. This is not the location in the underlying storage array, but the location in the contiguous space being modeled.
position
,
int
the number of items to remove
rmSize
,
Object
the new items to place in storage.
addItems
,
int
the number of items to add
addSize
)

Replace the given logical position in the storage with the given new items.

pack-priv void
resize(int nsize)

resize the underlying storage array to the given new size

protected void
shiftEnd(int
the new capacity
newSize
)

Make the gap bigger, moving any necessary data and updating the appropriate marks.

protected void
shiftGap(int
the new start of the gap
newGapStart
)

Move the start of the gap to a new location, without changing the size of the gap.

protected void
shiftGapEndUp(int
the new end of the gap
newGapEnd
)

Adjust the gap end upward.

protected void
shiftGapStartDown(int
the new start of the gap
newGapStart
)

Adjust the gap end downward.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
private Object array

The array of items. The type is determined by the subclass.

g0back to summary
private int g0

start of gap in the array

g1back to summary
private int g1

end of gap in the array

Constructor Detail

GapVectorback to summary
public GapVector()

Creates a new GapVector object. Initial size defaults to 10.

GapVectorback to summary
public GapVector(int initialLength)

Creates a new GapVector object, with the initial size specified.

Parameters
initialLength:int

the initial size

Method Detail

allocateArrayback to summary
protected abstract Object allocateArray(int len)

Allocate an array to store items of the type appropriate (which is determined by the subclass).

Parameters
len:int

the length of the array

Returns:Object

the java array of some type

closeback to summary
pack-priv void close(int position, int nItems)

Delete nItems at position. Squeezes any marks within the deleted area to position. This moves the gap to the best place by minimizing it's overall movement. The gap must intersect the target block.

getArrayback to summary
protected final Object getArray()

Access to the array. The actual type of the array is known only by the subclass.

Returns:Object

the java array of some type

getArrayLengthback to summary
protected abstract int getArrayLength()

Get the length of the allocated array.

Returns:int

the length of the array

getGapEndback to summary
protected final int getGapEnd()

Access to the end of the gap.

Returns:int

the end of the gap

getGapStartback to summary
protected final int getGapStart()

Access to the start of the gap.

Returns:int

the start of the gap

getNewArraySizeback to summary
pack-priv int getNewArraySize(int reqSize)

Calculates a new size of the storage array depending on required capacity.

Parameters
reqSize:int

the size which is necessary for new content

Returns:int

the new size of the storage array

openback to summary
pack-priv int open(int position, int nItems)

Make space for the given number of items at the given location.

Returns:int

the location that the caller should fill in

replaceback to summary
protected void replace(int position, int rmSize, Object addItems, int addSize)

Replace the given logical position in the storage with the given new items. This will move the gap to the area being changed if the gap is not currently located at the change location.

Parameters
position:int

the location to make the replacement. This is not the location in the underlying storage array, but the location in the contiguous space being modeled.

rmSize:int

the number of items to remove

addItems:Object

the new items to place in storage.

addSize:int

the number of items to add

resizeback to summary
pack-priv void resize(int nsize)

resize the underlying storage array to the given new size

shiftEndback to summary
protected void shiftEnd(int newSize)

Make the gap bigger, moving any necessary data and updating the appropriate marks.

Parameters
newSize:int

the new capacity

shiftGapback to summary
protected void shiftGap(int newGapStart)

Move the start of the gap to a new location, without changing the size of the gap. This moves the data in the array and updates the marks accordingly.

Parameters
newGapStart:int

the new start of the gap

shiftGapEndUpback to summary
protected void shiftGapEndUp(int newGapEnd)

Adjust the gap end upward. This doesn't move any data, but it does update any marks affected by the boundary change. All marks from the old gap end up to the new gap end are squeezed to the end of the gap (their location has been removed).

Parameters
newGapEnd:int

the new end of the gap

shiftGapStartDownback to summary
protected void shiftGapStartDown(int newGapStart)

Adjust the gap end downward. This doesn't move any data, but it does update any marks affected by the boundary change. All marks from the old gap start down to the new gap start are squeezed to the end of the gap (their location has been removed).

Parameters
newGapStart:int

the new start of the gap