Class Scanner.Values
java.lang.Object
be.imgn.gaia.core.base.Scanner.Values
- Enclosing class:
Scanner
The values of one match of a template, in the order of its holes. Each
next method reads one value and
moves on to the next one.
All the values must be read, in order: a hole whose value is not wanted is written with a star, as in
%*d. The values are only available during the call of the mapper they are given to.
- Since:
- 0.2.0
-
Method Summary
Modifier and TypeMethodDescriptioncharnextChar()Reads the next value as achar.intReads the next value as a code point.doubleReads the next value as adouble.<E extends Enum<E>>
EReads the next value as a constant of an enum: the one with that name, whatever the case, or else, for a value of one character, the only one whose name starts with it, whatever the case.intnextInt()Reads the next value as anint.int[]nextInts()Reads the next value, a list whose elements have a single hole, as an array ofints.nextList(Function<? super Scanner.Values, ? extends T> element) Reads the next value, a list, by turning the values of each of its elements into an object.longnextLong()Reads the next value as along.long[]Reads the next value, a list whose elements have a single hole, as an array oflongs.Reads the next value as text: what the hole matched, whatever its kind.Reads the next value, a list whose elements have a single hole, as a list of strings.
-
Method Details
-
nextInt
public int nextInt()Reads the next value as anint.- Returns:
- the value
- Throws:
ArithmeticException- if the value doesn't fit in anintNumberFormatException- if the value is not an integer, which a%dhole rules outNoSuchElementException- if no value is leftIllegalStateException- if the next value is a list, or if the mapper has returned
-
nextLong
public long nextLong()Reads the next value as along.- Returns:
- the value
- Throws:
ArithmeticException- if the value doesn't fit in alongNumberFormatException- if the value is not an integer, which a%dhole rules outNoSuchElementException- if no value is leftIllegalStateException- if the next value is a list, or if the mapper has returned
-
nextDouble
public double nextDouble()Reads the next value as adouble.- Returns:
- the value
- Throws:
NumberFormatException- if the value is not a number, which a%for%dhole rules outNoSuchElementException- if no value is leftIllegalStateException- if the next value is a list, or if the mapper has returned
-
nextString
Reads the next value as text: what the hole matched, whatever its kind.- Returns:
- the value
- Throws:
NoSuchElementException- if no value is leftIllegalStateException- if the next value is a list, or if the mapper has returned
-
nextChar
public char nextChar()Reads the next value as achar.- Returns:
- the value
- Throws:
NoSuchElementException- if no value is leftIllegalStateException- if the next value is not exactly onechar, which a%chole only rules out within the Basic Multilingual Plane, or if it is a list, or if the mapper has returned
-
nextCodePoint
public int nextCodePoint()Reads the next value as a code point.- Returns:
- the value
- Throws:
NoSuchElementException- if no value is leftIllegalStateException- if the next value is not exactly one code point, which a%chole rules out, or if it is a list, or if the mapper has returned
-
nextEnum
Reads the next value as a constant of an enum: the one with that name, whatever the case, or else, for a value of one character, the only one whose name starts with it, whatever the case.For example, with
enum Direction {LEFT, RIGHT}, the valuesleft,LEFTandLare allLEFT.- Type Parameters:
E- the type of the enum- Parameters:
type- the class of the enum- Returns:
- the constant
- Throws:
IllegalArgumentException- if the value designates no constant oftype, or severalNoSuchElementException- if no value is leftIllegalStateException- if the next value is a list, or if the mapper has returned
-
nextInts
public int[] nextInts()Reads the next value, a list whose elements have a single hole, as an array ofints.- Returns:
- the elements
- Throws:
ArithmeticException- if an element doesn't fit in anintNoSuchElementException- if no value is leftIllegalStateException- if the next value is not such a list, or if the mapper has returned
-
nextLongs
public long[] nextLongs()Reads the next value, a list whose elements have a single hole, as an array oflongs.- Returns:
- the elements
- Throws:
ArithmeticException- if an element doesn't fit in alongNoSuchElementException- if no value is leftIllegalStateException- if the next value is not such a list, or if the mapper has returned
-
nextStrings
Reads the next value, a list whose elements have a single hole, as a list of strings.- Returns:
- the elements, as an unmodifiable list
- Throws:
NoSuchElementException- if no value is leftIllegalStateException- if the next value is not such a list, or if the mapper has returned
-
nextList
public <T extends @Nullable Object> List<T> nextList(Function<? super Scanner.Values, ? extends T> element) Reads the next value, a list, by turning the values of each of its elements into an object. The function is given the values of one element, under the same rules as a mapper: it must read them all, in order.For example,
"Game %d: %[%d %w|, ]"reads"Game 1: 3 blue, 4 red"withv -> new Game(v.nextInt(), v.nextList(c -> new Cubes(c.nextInt(), c.nextString()))). A list of lists is read with a function that reads a list, such asv.nextList(Values::nextInts).- Type Parameters:
T- the type of the objects- Parameters:
element- the function that turns the values of one element into an object- Returns:
- the objects, in order, as an unmodifiable list
- Throws:
NoSuchElementException- if no value is leftIllegalStateException- if the next value is not a list, or if the mapper has returned
-