public class GapObjectArray extends Object implements ObjectArray, ObjectArray.CopyItems
ObjectArray
that
contains a gap which helps to speed up inserts/removals
close to the gap.
Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads inserts/removes items, the whole access must be synchronized externally.
Modifier and Type | Class and Description |
---|---|
static interface |
GapObjectArray.RemoveUpdater |
ObjectArray.CopyItems, ObjectArray.Modification
Constructor and Description |
---|
GapObjectArray() |
GapObjectArray(Object[] array,
int length)
Construct new gap array of objects.
|
Modifier and Type | Method and Description |
---|---|
void |
compact() |
void |
copyItems(int srcStartIndex,
int srcEndIndex,
Object[] dest,
int destIndex)
Copy the items in the given index range from the object array into destination array.
|
Object |
getItem(int index)
Get the item at the given index.
|
int |
getItemCount() |
void |
insertAll(int index,
Object[] items) |
void |
insertAll(int index,
Object[] items,
int off,
int len) |
void |
insertItem(int index,
Object item) |
protected void |
movedAboveGapUpdate(Object[] array,
int index,
int count) |
protected void |
movedBelowGapUpdate(Object[] array,
int index,
int count) |
void |
remove(int index,
int count) |
void |
remove(int index,
int count,
GapObjectArray.RemoveUpdater removeUpdater) |
void |
replace(int index,
int removeCount,
Object[] newItems) |
String |
toStringDetail() |
protected void |
unoptimizedRemove(int index,
int count,
GapObjectArray.RemoveUpdater removeUpdater) |
public GapObjectArray()
public GapObjectArray(Object[] array, int length)
array
- use this array as an initial array for processing.
The array will be modified by subsequent changes. If the array
contents should be preserved the array must be cloned first
before processing.length
- length of the valid part of the array that contains
the objects to be managed. The area must start at the index 0.public int getItemCount()
getItemCount
in interface ObjectArray
public Object getItem(int index)
ObjectArray
getItem
in interface ObjectArray
index
- >=0 and <ObjectArray.getItemCount()
index at which the item
should be obtained.public void copyItems(int srcStartIndex, int srcEndIndex, Object[] dest, int destIndex)
ObjectArray.CopyItems
copyItems
in interface ObjectArray.CopyItems
srcStartIndex
- index of the first item in the object array to get.srcEndIndex
- end index in the object array of the items to get.dest
- destination array of objects. The length of the array
must be at least destIndex + (srcEndIndex - srcStartIndex)
.destIndex
- first destination index at which the items are being stored.public void replace(int index, int removeCount, Object[] newItems)
public void insertItem(int index, Object item)
public void insertAll(int index, Object[] items)
public void insertAll(int index, Object[] items, int off, int len)
public void remove(int index, int count)
public void remove(int index, int count, GapObjectArray.RemoveUpdater removeUpdater)
protected void unoptimizedRemove(int index, int count, GapObjectArray.RemoveUpdater removeUpdater)
public void compact()
protected void movedAboveGapUpdate(Object[] array, int index, int count)
protected void movedBelowGapUpdate(Object[] array, int index, int count)
public String toStringDetail()