public class Context
extends java.lang.Object
| Constructor | Description |
|---|---|
Context(java.io.Reader reader,
Config config) |
Creates a new parsing context using the given
Reader to access the input. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
closeReader() |
Releases potential resources used by the reader.
|
java.lang.String |
getVariable(java.lang.String key) |
Gets the value of the given context variable.
|
int |
getVariableAsInt(java.lang.String key) |
Gets the value of the given context variable, converted into an int.
|
double |
readDouble() |
Scans the next token of the input as a double.
|
int |
readInt() |
Scans the next token of the input as an int.
|
@NotNull java.lang.String |
readIntoVariable(java.lang.String variableName) |
Scans the next token of the input as a string and stores the value into the given variable.
|
java.lang.String[] |
readLine() |
Reads and returns the next line of input as an array of string tokens.
|
@NotNull java.lang.String |
readString() |
Scans the next token of the input as a string.
|
void |
setVariable(java.lang.String key,
java.lang.String value) |
Sets the given variable to the given value.
|
void |
skip(int n) |
Skips the next n tokens of input.
|
InputParsingException |
wrapException(java.lang.String message,
java.lang.Exception cause) |
Wraps the given exception into an
InputParsingException. |
public Context(java.io.Reader reader,
Config config)
Reader to access the input.reader - the reader to use to read the inputconfig - the config defining how the parser should behavepublic void skip(int n)
throws InputParsingException
n - the number of tokens to skip (0 makes this method a noop)NoMoreLinesToReadException - if there is no more lines to readInputParsingException - if an error occurs while reading the input@NotNull
public @NotNull java.lang.String readString()
throws NoMoreLinesToReadException
NoMoreLinesToReadException - if there is no more lines to readInputParsingException - if an error occurs while reading the inputpublic int readInt()
throws InputParsingException
NoMoreLinesToReadException - if there is no more lines to readInputParsingException - if the input could not be parsed as an int, or if an IO error occurspublic double readDouble()
throws InputParsingException
NoMoreLinesToReadException - if there is no more lines to readInputParsingException - if the input could not be parsed as a double, or if an IO error occurspublic java.lang.String[] readLine()
throws InputParsingException
IncompleteLineReadException - if the previous line was not completely consumedNoMoreLinesToReadException - if there is no more lines to readInputParsingException - if an error occurs while reading the input@NotNull
public @NotNull java.lang.String readIntoVariable(java.lang.String variableName)
throws NoMoreLinesToReadException
variableName - the name of the variable to writeNoMoreLinesToReadException - if there is no more lines to readInputParsingException - if an error occurs while reading the inputpublic void closeReader()
IncompleteInputReadException - if there is still some input left to readpublic InputParsingException wrapException(java.lang.String message, java.lang.Exception cause)
InputParsingException.message - the message of the wrapped InputParsingExceptioncause - the exception to wrapInputParsingException with the given exception as causepublic java.lang.String getVariable(java.lang.String key)
throws UndefinedVariableException
key - the name of the context variable to accessUndefinedVariableException - if no variable is found with the given namepublic int getVariableAsInt(java.lang.String key)
throws InputParsingException
key - the name of the context variable to accessUndefinedVariableException - if no variable is found with the given nameInputParsingException - if the variable value cannot be converted to an intpublic void setVariable(java.lang.String key,
java.lang.String value)
key - the name of the context variable to create or updatevalue - the value to set the variable to