T - the type of objects created by this LineReaderP - the type of parent that the read objects are part ofChildReader<T,P>public class LineReader<T,P> extends java.lang.Object implements ChildReader<T,P>
ObjectReader that reads a full line of input to create an object.| Modifier | Constructor | Description |
|---|---|---|
protected |
LineReader(java.util.function.BiFunction<? super java.lang.String[],P,T> lineConverter) |
Creates a new
LineReader. |
| Modifier and Type | Method | Description |
|---|---|---|
static <E> ObjectReader<E[]> |
ofArray(java.util.function.IntFunction<E[]> arrayCreator,
java.util.function.Function<? super java.lang.String,? extends E> itemConverter) |
Creates a new
ObjectReader that reads a full line as an array of objects. |
static <T,P> ChildReader<T,P> |
ofChild(java.util.function.BiFunction<? super java.lang.String[],P,T> converter) |
Creates a new
ChildReader that reads a full line and converts the result using the given converter. |
static <E,R> ObjectReader<R> |
ofCollection(java.util.function.Function<? super java.lang.String,? extends E> itemConverter,
java.util.stream.Collector<E,?,R> collector) |
Creates a new
ObjectReader that reads a full line of tokens and reduces these tokens using the provided
collector. |
static ObjectReader<double[]> |
ofDoubleArray() |
Creates a new
ObjectReader that reads a full line as an array of doubles. |
static ObjectReader<int[]> |
ofIntArray() |
Creates a new
ObjectReader that reads a full line as an array of integers. |
static <E> ObjectReader<java.util.List<E>> |
ofList(java.util.function.Function<? super java.lang.String,? extends E> itemConverter) |
Creates a new
ObjectReader that reads a full line as a list of objects. |
static ObjectReader<long[]> |
ofLongArray() |
Creates a new
ObjectReader that reads a full line as an array of long. |
static <T> ObjectReader<T> |
ofObject(java.util.function.Function<? super java.lang.String[],T> converter) |
Creates a new
ObjectReader that reads a full line and converts the result using the given converter. |
static ObjectReader<java.lang.String[]> |
ofStringArray() |
Creates a new
ObjectReader that reads a full line as an array of strings. |
T |
read(@NotNull Context context,
P parent) |
Reads an object from the given
Context, consuming as much input as necessary. |
protected LineReader(java.util.function.BiFunction<? super java.lang.String[],P,T> lineConverter)
LineReader.lineConverter - the function to convert the input line's tokens into an object@NotNull public T read(@NotNull @NotNull Context context, @Nullable P parent) throws InputParsingException
ChildReaderContext, consuming as much input as necessary.read in interface ChildReader<T,P>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 ObjectReader<java.lang.String[]> ofStringArray()
ObjectReader that reads a full line as an array of strings.ObjectReaderpublic static ObjectReader<int[]> ofIntArray()
ObjectReader that reads a full line as an array of integers.ObjectReaderpublic static ObjectReader<long[]> ofLongArray()
ObjectReader that reads a full line as an array of long.ObjectReaderpublic static ObjectReader<double[]> ofDoubleArray()
ObjectReader that reads a full line as an array of doubles.ObjectReaderpublic static <E> ObjectReader<E[]> ofArray(java.util.function.IntFunction<E[]> arrayCreator, java.util.function.Function<? super java.lang.String,? extends E> itemConverter)
ObjectReader that reads a full line as an array of objects.E - the type of elements in the arrayarrayCreator - a function to create a new array, given its sizeitemConverter - a function to convert a string token into an item of the arrayObjectReaderpublic static <E> ObjectReader<java.util.List<E>> ofList(java.util.function.Function<? super java.lang.String,? extends E> itemConverter)
ObjectReader that reads a full line as a list of objects.E - the type of elements in the listitemConverter - a function to convert a string token into an item of the listObjectReaderpublic static <E,R> ObjectReader<R> ofCollection(java.util.function.Function<? super java.lang.String,? extends E> itemConverter, java.util.stream.Collector<E,?,R> collector)
ObjectReader that reads a full line of tokens and reduces these tokens using the provided
collector.E - the type of elements in the listR - the type of the result of the reduction, for instance a collection typeitemConverter - a function to convert a string token into an item of the listcollector - a collector describing the reduction to performObjectReaderpublic static <T> ObjectReader<T> ofObject(java.util.function.Function<? super java.lang.String[],T> converter)
ObjectReader that reads a full line and converts the result using the given converter.T - the type of objects created by the returned ObjectReaderconverter - the function to convert the input line's tokens into an objectObjectReaderpublic static <T,P> ChildReader<T,P> ofChild(java.util.function.BiFunction<? super java.lang.String[],P,T> converter)
ChildReader that reads a full line and converts the result using the given converter. As
opposed to ofObject(Function), the converter is also passed a parent object within which the reader will
be called. This is why this method returns a ChildReader and not an ObjectReader.T - the type of objects created by the returned ObjectReaderP - the type of parent that the read objects are part ofconverter - the function to convert the input line's tokens into an object. The converter is also given the parent
object within which the reader will be called.ChildReader