Added support within StatListBuilder to retrieve previously put stat

This commit is contained in:
Collin Smith
2020-09-02 01:29:24 -07:00
parent 294bb1ea61
commit 28a219d5cd

View File

@ -3,10 +3,14 @@ package com.riiablo.attributes;
public final class StatListBuilder { public final class StatListBuilder {
final StatList stats; final StatList stats;
final int list; final int list;
final StatGetter tuple;
int index;
StatListBuilder(StatList stats, int list) { StatListBuilder(StatList stats, int list) {
this.stats = stats; this.stats = stats;
this.list = list; this.list = list;
this.tuple = new StatGetter(stats);
this.index = -1;
} }
/** /**
@ -21,27 +25,33 @@ public final class StatListBuilder {
return stats.get(list); return stats.get(list);
} }
/** @see StatList#get(int) */
public StatGetter last() {
if (index < 0) throw new IllegalStateException("cannot retrieve last stat when no stats have been added yet!");
return tuple.update(index);
}
/** @see StatList#put(int, short, int, int) */ /** @see StatList#put(int, short, int, int) */
public StatListBuilder put(short stat, int param, int value) { public StatListBuilder put(short stat, int param, int value) {
stats.put(list, stat, param, value); index = stats.put(list, stat, param, value);
return this; return this;
} }
/** @see StatList#put(int, short, int) */ /** @see StatList#put(int, short, int) */
public StatListBuilder put(short stat, int value) { public StatListBuilder put(short stat, int value) {
stats.put(list, stat, value); index = stats.put(list, stat, value);
return this; return this;
} }
/** @see StatList#put(int, short, long) */ /** @see StatList#put(int, short, long) */
public StatListBuilder put(short stat, long value) { public StatListBuilder put(short stat, long value) {
stats.put(list, stat, value); index = stats.put(list, stat, value);
return this; return this;
} }
/** @see StatList#put(int, short, float) */ /** @see StatList#put(int, short, float) */
public StatListBuilder put(short stat, float value) { public StatListBuilder put(short stat, float value) {
stats.put(list, stat, value); index = stats.put(list, stat, value);
return this; return this;
} }
} }