T - the type of object this ObjectReader createsChildReader<T,java.lang.Object>, java.util.function.Function<Context,T>Int2Constructor<T>, Int3Constructor<T>, Int4Constructor<T>, Int5Constructor<T>, Int6Constructor<T>, Int7Constructor<T>@FunctionalInterface public interface ObjectReader<T> extends ChildReader<T,java.lang.Object>, java.util.function.Function<Context,T>
Context, consuming as much input as necessary. An ObjectReader
creates an object that is either the root of the object tree, or is independent from the parent object within which
it's being constructed. This is anyway an extension of ChildReader, because it can be constructed in the
context of a parent object, but simply doesn't care about its parent.
| Modifier and Type | Method | Description |
|---|---|---|
default T |
apply(Context context) |
|
T |
read(@NotNull Context context) |
Reads an object from the given
Context, consuming as much input as necessary. |
default T |
read(@NotNull Context context,
@Nullable java.lang.Object parent) |
Reads an object from the given
Context, consuming as much input as necessary. |
default ObjectReader<T> |
then(java.util.function.Consumer<Context> consumer) |
Returns a new
ObjectReader that creates the same object as this reader, and then executes the given
function on the context. |
default ObjectReader<T> |
then(SectionReader<? super T> sectionReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then executes the given
SectionReader to update it. |
default <E> ObjectReader<T> |
thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter,
java.util.function.IntFunction<E[]> arrayCreator,
java.lang.String sizeVariable,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter,
java.util.function.IntFunction<E[]> arrayCreator,
java.util.function.BiFunction<? super T,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and set it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter,
java.util.function.IntFunction<E[]> arrayCreator,
java.util.function.Function<? super T,java.lang.Integer> getSize,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenArrayLine(java.util.function.BiConsumer<? super T,? super E[]> setter,
java.util.function.IntFunction<E[]> arrayCreator,
java.util.function.Function<? super java.lang.String,? extends E> itemConverter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next line, and sets it on the created object using the provided setter. |
default <C> ObjectReader<T> |
thenChild(java.util.function.BiConsumer<? super T,? super C> setter,
ChildReader<C,? super T> childReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates a child object
from the next few lines using the given reader, and sets it on the created parent object using the given setter. |
default ObjectReader<T> |
thenDouble(java.util.function.ObjDoubleConsumer<? super T> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one double from
the input to set a property of the created object. |
default ObjectReader<T> |
thenDoubleArrayLine(java.util.function.BiConsumer<? super T,double[]> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
doubles from the next line, and sets it on the created object using the provided setter. |
default ObjectReader<T> |
thenField(java.lang.String fieldName) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set the given field on the created object. |
default ObjectReader<T> |
thenFieldAndVar(java.lang.String fieldName,
java.lang.String variableName) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set the given field on the created object, and stores it in a variable as well. |
default ObjectReader<T> |
thenFields(java.lang.String... fieldNames) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads tokens from the
input to set the given fields on the created object. |
default ObjectReader<T> |
thenFieldsAndVars(java.lang.String... fieldAndVarNames) |
Returns a new
ObjectReader that creates the same object as this reader, and then maps each element of the
next line to a field of the created object or to a context variable, or both. |
default ObjectReader<T> |
thenInt(java.util.function.ObjIntConsumer<? super T> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one int from the
input to set a property of the created object. |
default ObjectReader<T> |
thenIntArrayLine(java.util.function.BiConsumer<? super T,int[]> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of ints
from the next line, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter,
java.lang.String sizeVariable,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter,
java.util.function.BiFunction<? super T,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter,
java.util.function.Function<? super T,java.lang.Integer> getSize,
ChildReader<? extends E,? super T> itemReader) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. |
default <E> ObjectReader<T> |
thenListLine(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter,
java.util.function.Function<java.lang.String,? extends E> itemConverter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next line, and sets it on the created object using the provided setter. |
default ObjectReader<T> |
thenLongArrayLine(java.util.function.BiConsumer<? super T,long[]> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
longs from the next line, and sets it on the created object using the provided setter. |
default <V> ObjectReader<T> |
thenObject(java.util.function.BiConsumer<? super T,? super V> setter,
java.util.function.Function<? super java.lang.String,V> converter) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set a property of the created object. |
default ObjectReader<T> |
thenSkip(int n) |
Returns a new
ObjectReader that creates the same object as this reader, and then consumes n tokens of the
input without setting anything. |
default ObjectReader<T> |
thenString(java.util.function.BiConsumer<? super T,? super java.lang.String> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one string from
the input to set a property of the created object. |
default ObjectReader<T> |
thenStringArrayLine(java.util.function.BiConsumer<? super T,java.lang.String[]> setter) |
Returns a new
ObjectReader that creates the same object as this reader, and then creates an array of
strings from the next line, and sets it on the created object using the provided setter. |
default ObjectReader<T> |
thenVar(java.lang.String variableName) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads one token from the
input and stores it into the given variable. |
default ObjectReader<T> |
thenVars(java.lang.String... variableNames) |
Returns a new
ObjectReader that creates the same object as this reader, and then reads tokens from the
input to store them into the given variables. |
@Nullable T read(@NotNull @NotNull Context context) throws InputParsingException
Context, consuming as much input as necessary.context - the context to read lines fromInputParsingException - if something went wrong when reading the input@Nullable default T read(@NotNull @NotNull Context context, @Nullable @Nullable java.lang.Object parent) throws InputParsingException
ChildReaderContext, consuming as much input as necessary.read in interface ChildReader<T,java.lang.Object>context - the context to read lines fromparent - the parent object within which the object is being createdInputParsingException - if something went wrong when reading the inputdefault T apply(Context context) throws InputParsingException
apply in interface java.util.function.Function<Context,T>InputParsingExceptiondefault ObjectReader<T> then(SectionReader<? super T> sectionReader)
ObjectReader that creates the same object as this reader, and then executes the given
SectionReader to update it.sectionReader - the SectionReader to execute after this ObjectReaderObjectReaderdefault ObjectReader<T> then(java.util.function.Consumer<Context> consumer)
ObjectReader that creates the same object as this reader, and then executes the given
function on the context. This can be useful when we simply want to set variables without caring about the created
object.consumer - the function to execute after this ObjectReaderObjectReaderdefault ObjectReader<T> thenSkip(int n)
ObjectReader that creates the same object as this reader, and then consumes n tokens of the
input without setting anything.n - the number of tokens to skipObjectReaderdefault ObjectReader<T> thenVar(java.lang.String variableName)
ObjectReader that creates the same object as this reader, and then reads one token from the
input and stores it into the given variable.variableName - the name of the variable to setObjectReaderdefault ObjectReader<T> thenVars(java.lang.String... variableNames)
ObjectReader that creates the same object as this reader, and then reads tokens from the
input to store them into the given variables. The number of variable names determines the number of tokens read
from the input.variableNames - the name of the variables to setObjectReaderdefault ObjectReader<T> thenField(java.lang.String fieldName)
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set the given field on the created object. The proper type conversion is done based on the type of the
field.
WARNING: This method is here to allow brevity but it is sensitive to refactoring as it uses a simple string for
the name of the field. Please prefer using setter-based methods like thenObject(BiConsumer, Function),
thenInt(ObjIntConsumer) or thenString(BiConsumer), which are checked at compile time.
fieldName - the name of the field to setObjectReaderdefault ObjectReader<T> thenFields(java.lang.String... fieldNames)
ObjectReader that creates the same object as this reader, and then reads tokens from the
input to set the given fields on the created object. The proper type conversion is done based on the type of the
fields. The number of field names determines the number of tokens read from the input.
WARNING: This method is here to allow brevity but it is sensitive to refactoring as it uses simple strings for
the name of the fields. Please prefer using setter-based methods like thenObject(BiConsumer, Function),
thenInt(ObjIntConsumer) or thenString(BiConsumer), which are checked at compile time.
fieldNames - the names of the fields to setObjectReaderdefault ObjectReader<T> thenFieldAndVar(java.lang.String fieldName, java.lang.String variableName)
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set the given field on the created object, and stores it in a variable as well. The proper type
conversion is done based on the type of the field.
WARNING: This method is here to allow brevity but it is sensitive to refactoring as it uses a simple string for
the name of the field. Please prefer using setter-based methods like thenObject(BiConsumer, Function),
thenInt(ObjIntConsumer) or thenString(BiConsumer), which are checked at compile time.
fieldName - the name of the field to setvariableName - the name of the variable to setObjectReaderdefault ObjectReader<T> thenFieldsAndVars(java.lang.String... fieldAndVarNames)
ObjectReader that creates the same object as this reader, and then maps each element of the
next line to a field of the created object or to a context variable, or both.
The field/variable names are given as strings that can each be one of:
Note that "" describe neither a field nor a variable, and thus the corresponding entry in the line will be ignored during parsing. Null descriptions and descriptions ending in '@' are forbidden.
fieldAndVarNames - an array of field/variable names, as described aboveObjectReaderdefault <V> ObjectReader<T> thenObject(java.util.function.BiConsumer<? super T,? super V> setter, java.util.function.Function<? super java.lang.String,V> converter)
ObjectReader that creates the same object as this reader, and then reads one token from the
input to set a property of the created object.V - the type of value that the given converter yieldssetter - the setter to use to set the value on the target objectconverter - a function to convert the string token read from the input into the value to setObjectReaderdefault ObjectReader<T> thenInt(java.util.function.ObjIntConsumer<? super T> setter)
ObjectReader that creates the same object as this reader, and then reads one int from the
input to set a property of the created object.setter - the setter to use to set the value on the target objectObjectReaderdefault ObjectReader<T> thenDouble(java.util.function.ObjDoubleConsumer<? super T> setter)
ObjectReader that creates the same object as this reader, and then reads one double from
the input to set a property of the created object.setter - the setter to use to set the value on the target objectObjectReaderdefault ObjectReader<T> thenString(java.util.function.BiConsumer<? super T,? super java.lang.String> setter)
ObjectReader that creates the same object as this reader, and then reads one string from
the input to set a property of the created object.setter - the setter to use to set the value on the target objectObjectReaderdefault ObjectReader<T> thenIntArrayLine(java.util.function.BiConsumer<? super T,int[]> setter)
ObjectReader that creates the same object as this reader, and then creates an array of ints
from the next line, and sets it on the created object using the provided setter.setter - the setter to call on the created object, with the created arrayObjectReaderdefault ObjectReader<T> thenLongArrayLine(java.util.function.BiConsumer<? super T,long[]> setter)
ObjectReader that creates the same object as this reader, and then creates an array of
longs from the next line, and sets it on the created object using the provided setter.setter - the setter to call on the created object, with the created arrayObjectReaderdefault ObjectReader<T> thenDoubleArrayLine(java.util.function.BiConsumer<? super T,double[]> setter)
ObjectReader that creates the same object as this reader, and then creates an array of
doubles from the next line, and sets it on the created object using the provided setter.setter - the setter to call on the created object, with the created arrayObjectReaderdefault ObjectReader<T> thenStringArrayLine(java.util.function.BiConsumer<? super T,java.lang.String[]> setter)
ObjectReader that creates the same object as this reader, and then creates an array of
strings from the next line, and sets it on the created object using the provided setter.setter - the setter to call on the created object, with the created arrayObjectReaderdefault <E> ObjectReader<T> thenArrayLine(java.util.function.BiConsumer<? super T,? super E[]> setter, java.util.function.IntFunction<E[]> arrayCreator, java.util.function.Function<? super java.lang.String,? extends E> itemConverter)
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next line, and sets it on the created object using the provided setter.E - the type of elements in the created arraysetter - the setter to call on the created object, with the created arrayarrayCreator - a function to create a new array, given the desired sizeitemConverter - a function to convert each string element of the line into an element of the arrayObjectReaderdefault <E> ObjectReader<T> thenListLine(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter, java.util.function.Function<java.lang.String,? extends E> itemConverter)
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next line, and sets it on the created object using the provided setter.E - the type of elements in the created listsetter - the setter to call on the created object, with the created listitemConverter - a function to convert each string element of the line into an element of the listObjectReaderdefault <E> ObjectReader<T> thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter, java.util.function.IntFunction<E[]> arrayCreator, java.lang.String sizeVariable, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and sets it on the created object using the provided setter. N will be read at
parsing time from the current value of the given context variable, which needs to be previously set. A variable
can be set, for instance, using thenVar(String) or thenVars(String...).E - the type of elements in the created arraysetter - the setter to call on the created object, with the created arrayarrayCreator - a function to create a new array, given the desired sizesizeVariable - a context variable that will contain the desired size of the arrayitemReader - a child reader used to read each itemObjectReaderdefault <E> ObjectReader<T> thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter, java.util.function.IntFunction<E[]> arrayCreator, java.util.function.Function<? super T,java.lang.Integer> getSize, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and sets it on the created object using the provided setter. N will be read at
parsing time by calling the provided getSize function.E - the type of elements in the created arraysetter - the setter to call on the created object, with the created arrayarrayCreator - a function to create a new array, given the desired sizegetSize - a function to get the size of the array to create. It takes the created object as parameter.itemReader - a child reader used to read each itemObjectReaderdefault <E> ObjectReader<T> thenArray(java.util.function.BiConsumer<? super T,? super E[]> setter, java.util.function.IntFunction<E[]> arrayCreator, java.util.function.BiFunction<? super T,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates an array of
objects from the next N lines, and set it on the created object using the provided setter. N will be computed at
parsing time by calling the provided getSize function.E - the type of elements in the created arraysetter - the setter to call on the created object, with the created arrayarrayCreator - a function to create a new array, given the desired sizegetSize - a function to get the size of the array to create. It takes the created object as parameter, as well as
the current ContextitemReader - a child reader used to read each itemObjectReaderdefault <E> ObjectReader<T> thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter, java.lang.String sizeVariable, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. N will be read at
parsing time from the current value of the given context variable, which needs to be previously set. A variable
can be set, for instance, using thenFieldsAndVars(String...).E - the type of elements in the created listsetter - the setter to call on the created object, with the created listsizeVariable - a context variable that will contain the number of elements to read and put in the listitemReader - a child reader used to read each itemObjectReaderdefault <E> ObjectReader<T> thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter, java.util.function.Function<? super T,java.lang.Integer> getSize, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. N will be read at
parsing time by calling the provided getSize function.E - the type of elements in the created listsetter - the setter to call on the created object, with the created listgetSize - a function to get the size of the array to create. It takes the created object as parameter.itemReader - a child reader used to read each itemObjectReaderdefault <E> ObjectReader<T> thenList(java.util.function.BiConsumer<? super T,? super java.util.List<E>> setter, java.util.function.BiFunction<? super T,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super T> itemReader)
ObjectReader that creates the same object as this reader, and then creates a list of
objects from the next N lines, and sets it on the created object using the provided setter. N will be computed at
parsing time by calling the provided getSize function.E - the type of elements in the created listsetter - the setter to call on the created object, with the created listgetSize - a function to get the size of the array to create. It takes the created object as parameter, as well as
the current ContextitemReader - a child reader used to read each itemObjectReaderdefault <C> ObjectReader<T> thenChild(java.util.function.BiConsumer<? super T,? super C> setter, ChildReader<C,? super T> childReader)
ObjectReader that creates the same object as this reader, and then creates a child object
from the next few lines using the given reader, and sets it on the created parent object using the given setter.
The childReader will read as much input as necessary.C - the type of the child object to createsetter - the setter to call on the parent created object, with the created child objectchildReader - a reader used to read the child objectObjectReader