E - the type of the elements in the containerC - the type of the container itselfP - the type of parent on which this ContainerReader sets the created containerChildReader<C,P>public class ContainerReader<E,C,P> extends java.lang.Object implements ChildReader<C,P>
ChildReader that creates a container, and reads multiple child objects from the input, adding them to the
container.| Modifier | Constructor | Description |
|---|---|---|
protected |
ContainerReader(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super P> itemReader,
java.util.function.IntFunction<? extends C> constructor,
AddFunction<? super E,? super C> addFunction) |
Creates a new
ContainerReader that may read the expected number of items from the parent object or a
context variable using the provided size getter function. |
| Modifier and Type | Method | Description |
|---|---|---|
static <E,C,P> ChildReader<C,P> |
of(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super P> itemReader,
java.util.function.IntFunction<? extends C> constructor,
AddFunction<? super E,? super C> addFunction) |
Creates a new
ContainerReader that may read the expected number of items from the parent object or a
context variable. |
static <E,P> ChildReader<E[],P> |
ofArray(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super P> itemReader,
java.util.function.IntFunction<E[]> arrayCreator) |
Creates a
ContainerReader that reads an array of items. |
static <E,C extends java.util.Collection<E>,P> |
ofCollection(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super P> itemReader,
java.util.function.IntFunction<C> constructor) |
Creates a
ContainerReader that reads a collection of items. |
static <E,P> ChildReader<java.util.List<E>,P> |
ofList(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize,
ChildReader<? extends E,? super P> itemReader) |
Creates a
ContainerReader that reads a list of items. |
C |
read(@NotNull Context context,
P parent) |
Reads an object from the given
Context, consuming as much input as necessary. |
protected ContainerReader(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super P> itemReader, java.util.function.IntFunction<? extends C> constructor, AddFunction<? super E,? super C> addFunction)
ContainerReader that may read the expected number of items from the parent object or a
context variable using the provided size getter function.getSize - a function to get the number of items to read, which is given the parent object and context as parameter.
Note that the given parent parameter may be null if this reader is called to create a root object.itemReader - a child reader used to read each itemconstructor - a constructor to create a new container, given the size as inputaddFunction - a function to add elements to the created containerpublic C read(@NotNull @NotNull Context context, @Nullable P parent) throws InputParsingException
ChildReaderContext, consuming as much input as necessary.read in interface ChildReader<E,C>context - the context to read lines fromparent - the parent object within which the object is being createdInputParsingException - if something went wrong when reading the inputpublic static <E,C,P> ChildReader<C,P> of(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super P> itemReader, java.util.function.IntFunction<? extends C> constructor, AddFunction<? super E,? super C> addFunction)
ContainerReader that may read the expected number of items from the parent object or a
context variable.E - the type of the elements in the containerC - the type of the container itselfP - the type of parent on which the created ContainerReader will set the created containersgetSize - a function to get the number of items to read, which is given the parent object and context as parameter.
Note that the given parent parameter may be null if this reader is called to create a root object.itemReader - a child reader used to read each itemconstructor - a constructor to create a new container, given the size as inputaddFunction - a function to add elements to the created containerContainerReaderpublic static <E,P> ChildReader<E[],P> ofArray(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super P> itemReader, java.util.function.IntFunction<E[]> arrayCreator)
ContainerReader that reads an array of items.E - the type of elements in the arrayP - the type of parent that the created array will be part ofgetSize - a function to get the number of items to read, which is given the parent object and context as parameter.
Note that the given parent parameter may be null if this reader is called to create a root object.itemReader - a reader to call as many times as the size returned by getSize. This is what actually consumes
input in the created reader.arrayCreator - a function to create a new array, given its sizeContainerReaderpublic static <E,P> ChildReader<java.util.List<E>,P> ofList(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super P> itemReader)
ContainerReader that reads a list of items.E - the type of elements in the listP - the type of parent that the created list will be part ofgetSize - a function to get the number of items to read, which is given the parent object and context as parameter.
Note that the given parent parameter may be null if this reader is called to create a root object.itemReader - a reader to call as many times as the size returned by getSize. This is what actually consumes
input in the created reader.ContainerReaderpublic static <E,C extends java.util.Collection<E>,P> ChildReader<C,P> ofCollection(java.util.function.BiFunction<? super P,Context,java.lang.Integer> getSize, ChildReader<? extends E,? super P> itemReader, java.util.function.IntFunction<C> constructor)
ContainerReader that reads a collection of items.E - the type of elements in the collectionC - the type of collections to createP - the type of parent that the created collection will be part ofgetSize - a function to get the number of items to read, which is given the parent object and context as parameter.
Note that the given parent parameter may be null if this reader is called to create a root object.itemReader - a reader to call as many times as the size returned by getSize. This is what actually consumes
input in the created reader.constructor - a function to create a new collection, given its sizeContainerReader