Package jjparse.input
Class Input<T>
java.lang.Object
jjparse.input.Input<T>
- Type Parameters:
T- The covariant element type for thisInput. In most cases this type equalsCharacter.
- Direct Known Subclasses:
CharacterInput,StreamInput
An abstract representation of an
Note: This class is intended to be immutable and hence covariant in its type parameter.
Input for parsing. In most cases, this will be a CharacterInput, which
is an Input of Characters and can be considered a sequence of characters (just like a String).
Note: This class is intended to be immutable and hence covariant in its type parameter.
- Author:
- Björn Lötters
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Input<T> empty()Constructs an emptyInputof an arbitrary element type where"<empty>"is used as the name.abstract Thead()Returns the first element of thisInput.abstract booleanisEmpty()Checks whether thisInputis empty.final booleannonEmpty()Checks whether thisInputis not empty.of(String name, InputStream stream, Charset charset) of(String name, CharSequence sequence) static <T> Input<T> static <T> Input<T> static <T> Input<T> position()tail()Returns the rest of thisInput, excluding its first element.
-
Field Details
-
name
A human-readable name for thisInputwhich can be used for error reporting purposes.
-
-
Constructor Details
-
Method Details
-
isEmpty
public abstract boolean isEmpty()Checks whether thisInputis empty.- Returns:
trueif thisInputis empty.- See Also:
-
nonEmpty
public final boolean nonEmpty()Checks whether thisInputis not empty.- Returns:
trueif thisInputis not empty.- See Also:
-
head
- Returns:
- The first element of this
Input. - Throws:
NoSuchElementException- If thisInputis empty.- See Also:
-
tail
-
position
-
empty
Constructs an emptyInputof an arbitrary element type where"<empty>"is used as the name.- Type Parameters:
T- The element type.- Returns:
- An empty
Inputof an arbitrary element type.
-
of
-
of
-
of
-
of
public static Input<Character> of(String name, InputStream stream, Charset charset) throws IOException Constructs a newInputofCharacters on basis of the providedInputStreamandCharset. Take note that the providedInputStreamis completely read before theInputis created. For a lazy kind of input, consider one of the other variants of this method.- Parameters:
name- A human-readable name for theInput.stream- The underlying source for thisInput.charset- TheCharsetthat shall be used to decode theInputStream.- Returns:
- An
InputofCharacters that is based on the underlyingInputStream. - Throws:
IOException- If reading from theInputStreamfails.
-
of
- Parameters:
path- ThePathto the file that should be read as the source of this input. At the same time, this path is used as the name for theInput.charset- TheCharsetthat shall be used to decode the file denoted by the providedPath.- Returns:
- An
InputofCharacters that is based on the underlying file contents. - Throws:
IOException- If reading the file contents denoted by thePathfails.
-
of
-
of
- Parameters:
name- A human-readable name for theInput.sequence- The underlying source for thisInput.- Returns:
- An
InputofCharacters that is based on the underlyingCharSequence.
-