Class Scanner.Values

java.lang.Object
be.imgn.gaia.core.base.Scanner.Values
Enclosing class:
Scanner

public static final class Scanner.Values extends Object
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 Type
    Method
    Description
    char
    Reads the next value as a char.
    int
    Reads the next value as a code point.
    double
    Reads the next value as a double.
    <E extends Enum<E>>
    E
    nextEnum(Class<E> type)
    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.
    int
    Reads the next value as an int.
    int[]
    Reads the next value, a list whose elements have a single hole, as an array of ints.
    <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.
    long
    Reads the next value as a long.
    long[]
    Reads the next value, a list whose elements have a single hole, as an array of longs.
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • nextInt

      public int nextInt()
      Reads the next value as an int.
      Returns:
      the value
      Throws:
      ArithmeticException - if the value doesn't fit in an int
      NumberFormatException - if the value is not an integer, which a %d hole rules out
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is a list, or if the mapper has returned
    • nextLong

      public long nextLong()
      Reads the next value as a long.
      Returns:
      the value
      Throws:
      ArithmeticException - if the value doesn't fit in a long
      NumberFormatException - if the value is not an integer, which a %d hole rules out
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is a list, or if the mapper has returned
    • nextDouble

      public double nextDouble()
      Reads the next value as a double.
      Returns:
      the value
      Throws:
      NumberFormatException - if the value is not a number, which a %f or %d hole rules out
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is a list, or if the mapper has returned
    • nextString

      public String nextString()
      Reads the next value as text: what the hole matched, whatever its kind.
      Returns:
      the value
      Throws:
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is a list, or if the mapper has returned
    • nextChar

      public char nextChar()
      Reads the next value as a char.
      Returns:
      the value
      Throws:
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is not exactly one char, which a %c hole 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 left
      IllegalStateException - if the next value is not exactly one code point, which a %c hole rules out, or if it is a list, or if the mapper has returned
    • nextEnum

      public <E extends Enum<E>> E nextEnum(Class<E> type)
      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 values left, LEFT and L are all LEFT.

      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 of type, or several
      NoSuchElementException - if no value is left
      IllegalStateException - 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 of ints.
      Returns:
      the elements
      Throws:
      ArithmeticException - if an element doesn't fit in an int
      NoSuchElementException - if no value is left
      IllegalStateException - 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 of longs.
      Returns:
      the elements
      Throws:
      ArithmeticException - if an element doesn't fit in a long
      NoSuchElementException - if no value is left
      IllegalStateException - if the next value is not such a list, or if the mapper has returned
    • nextStrings

      public List<String> 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 left
      IllegalStateException - 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" with v -> 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 as v.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 left
      IllegalStateException - if the next value is not a list, or if the mapper has returned