Java Reference
In-Depth Information
public int size() {
return size;
}
public E get(int index) {
int off = 0; // offset from start of collection
for (int i = 0; i < arrays.length; i++) {
if (index < off + arrays[i].length)
return arrays[i][index - off];
off += arrays[i].length;
}
throw new ArrayIndexOutOfBoundsException(index);
}
public E set(int index, E value) {
int off = 0; // offset from start of collection
for (int i = 0; i < arrays.length; i++) {
if (index < off + arrays[i].length) {
E ret = arrays[i][index - off];
arrays[i][index - off] = value;
return ret;
}
off += arrays[i].length;
}
throw new ArrayIndexOutOfBoundsException(index);
}
}
When an
ArrayBunchList
is created, all the constituent arrays are re-
membered internally in the
arrays
field, and the total size of the collec-
tion in
size
.
ArrayBunchList
implements
size
,
get
, and
set
, but not
add
or
remove
. This means that the class provides a modifiable list, but one
whose size cannot be changed. Any call that needs values from the un-
derlying arrays will go through
get
. Any action that modifies the value