Methods Summary |
---|
private 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 final int[] | getLabelsInOrder()Gets an array containing all of the labels used in this instance,
in order. The returned array is freshly-allocated and so may be
modified safely by the caller without impacting this instance.
int sz = size();
int[] result = new int[sz];
for (int i = 0; i < sz; i++) {
LabeledItem li = (LabeledItem) get0(i);
if (li == null) {
throw new NullPointerException("null at index " + i);
}
result[i] = li.getLabel();
}
Arrays.sort(result);
return result;
|
public final 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--)
/*empty*/ ;
int newSize = i + 1;
labelToIndex.shrink(newSize);
return newSize;
|
public final 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);
}
|
private void | rebuildLabelToIndex()Rebuilds the label-to-index mapping after a {@code shrinkToFit()}.
Note: This 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);
}
}
|
private 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();
|