Made the interactive D8 entropy reader more forgiving for a better UX
This commit is contained in:
parent
4fd4bb407b
commit
6c781accb0
|
@ -12,15 +12,31 @@ public class InteractiveDice8EntropyGenerator extends InteractiveEntropyGenerato
|
||||||
@Override
|
@Override
|
||||||
protected String readNextEventSetString() {
|
protected String readNextEventSetString() {
|
||||||
|
|
||||||
String eventSetString = "";
|
StringBuilder eventSetBuffer = new StringBuilder();
|
||||||
Pattern eventSetPattern = Pattern.compile(String.format("[1-8]{%d}", eventsPerEventSet));
|
int remainingEvents = eventsPerEventSet;
|
||||||
|
Pattern eventSetPattern = Pattern.compile("[1-8]+");
|
||||||
|
|
||||||
while (!eventSetPattern.matcher(eventSetString).matches()) {
|
while (remainingEvents > 0) {
|
||||||
System.out.print("Input 11 x 8-sided dice rolls [1-8]: ");
|
|
||||||
eventSetString = inputScanner.next();
|
System.out.printf("Input %d x 8-sided dice rolls [1-8]: ", remainingEvents);
|
||||||
|
|
||||||
|
String nextInput = inputScanner.next();
|
||||||
|
|
||||||
|
if (!eventSetPattern.matcher(nextInput).matches()) {
|
||||||
|
System.out.printf(
|
||||||
|
"Invalid input! Enter %d-digit sequence of digits from 1 to 8 (for example, 8765375812)" + System.lineSeparator(),
|
||||||
|
remainingEvents);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
eventSetBuffer.append(nextInput);
|
||||||
|
remainingEvents -= nextInput.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventSetString;
|
if (remainingEvents < 0)
|
||||||
|
System.out.printf("NOTE: Discarding the %d extra dice roll(s) entered" + System.lineSeparator(), -remainingEvents);
|
||||||
|
|
||||||
|
return eventSetBuffer.substring(0, eventsPerEventSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user