Added support for retrieving first entry of a stat regardless of params

This commit is contained in:
Collin Smith 2020-09-02 16:18:59 -07:00
parent 03503a8f79
commit 251a691bd5
2 changed files with 18 additions and 0 deletions

View File

@ -365,6 +365,17 @@ public final class StatList {
return indexOf(list, stat, 0);
}
int firstIndexOf(int list, short stat) {
final int listStart = startingOffset(list);
final int listEnd = endingOffset(list);
final int index = Arrays.binarySearch(ids, listStart, listEnd, stat);
if (index >= 0) {
return firstIndexOf(stat, index, listStart);
} else {
return index;
}
}
private int firstIndexOf(final short stat, final int startIndex, final int listStart) {
int i = startIndex - 1;
final short[] ids = this.ids;

View File

@ -32,6 +32,13 @@ public final class StatListGetter {
return tuple.set(stats, index);
}
/** @see StatList#firstIndexOf(int, short) */
StatGetter first(short stat) {
final int index = stats.firstIndexOf(list, stat);
if (index < 0) return null;
return tuple.set(stats, index);
}
public void addAll(StatListGetter src) {
stats.addAll(list, src.stats, src.list);
}