Methods Summary |
---|
protected void | addLabelIndex(int label, int index)Adds a label and index to the label-to-index mapping
int origSz = labelToIndex.size();
for (int i = 0; i <= (label - origSz); i++) {
labelToIndex.add(-1);
}
labelToIndex.set(label, index);
|
public int | getMaxLabel()Gets the maximum label (exclusive) of any block added to this instance.
int sz = labelToIndex.size();
// Gobble any deleted labels that may be at the end...
int i;
for (i = sz - 1; (i >= 0) && (labelToIndex.get(i) < 0); i--)
;
int newSize = i+1;
labelToIndex.shrink(newSize);
return newSize;
|
public int | indexOfLabel(int label)Gets the index of the first item in the list with the given
label, if any.
if (label >= labelToIndex.size()) {
return -1;
} else {
return labelToIndex.get(label);
}
|
protected void | rebuildLabelToIndex()Rebuilds the label-to-index mapping after a shrinkToFit().
Note: assumes that the labels that are in the list are the same
although the indicies may have changed.
int szItems = size();
for (int i = 0; i < szItems; i++) {
LabeledItem li = (LabeledItem)get0(i);
if (li != null) {
labelToIndex.set(li.getLabel(), i);
}
}
|
protected void | removeLabel(int oldLabel)Removes a label from the label-to-index mapping
labelToIndex.set(oldLabel, -1);
|
protected void | set(int n, LabeledItem item)Sets the element at the given index.
LabeledItem old = (LabeledItem) getOrNull0(n);
set0(n, item);
if (old != null) {
removeLabel(old.getLabel());
}
if (item != null) {
addLabelIndex(item.getLabel(), n);
}
|
public void | shrinkToFit()
super.shrinkToFit();
rebuildLabelToIndex();
|