Class AbstractObjParser
java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.obj.AbstractObjParser
- Direct Known Subclasses:
PolygonObjParser
Abstract base class for OBJ parsing functionality.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The current (most recently parsed) keyword.private final SimpleTextParser
Text parser instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractObjParser
(SimpleTextParser parser) Construct a new instance for parsing OBJ content from the given text parser. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Discard remaining content on the current data line, taking line continuation characters into account.protected SimpleTextParser
Discard whitespace on the current data line, taking line continuation characters into account.Get the current keyword, meaning the keyword most recently parsed via thenextKeyword()
method.protected SimpleTextParser
Get the text parser for the instance.protected abstract void
handleKeyword
(String keyword) Method called when a keyword is encountered in the parsed OBJ content.protected boolean
Discard whitespace on the current data line and return true if any more characters remain on the line.protected double
Get the next whitespace-delimited double on the current data line.boolean
Advance the parser to the next keyword, returning true if a keyword has been found and false if the end of the content has been reached.Read the remaining content on the current data line, taking line continuation characters into account.double[]
Read whitespace-delimited double values from the current data line.private boolean
Read a keyword consisting of alphanumeric characters from the current parser position and set it as the current token.Read a whitespace-delimited 3D vector from the current data line.
-
Field Details
-
parser
Text parser instance. -
currentKeyword
The current (most recently parsed) keyword.
-
-
Constructor Details
-
AbstractObjParser
Construct a new instance for parsing OBJ content from the given text parser.- Parameters:
parser
- text parser to read content from
-
-
Method Details
-
getCurrentKeyword
Get the current keyword, meaning the keyword most recently parsed via thenextKeyword()
method. Null is returned if parsing has not started or the end of the content has been reached.- Returns:
- the current keyword or null if parsing has not started or the end of the content has been reached
-
nextKeyword
public boolean nextKeyword()Advance the parser to the next keyword, returning true if a keyword has been found and false if the end of the content has been reached. Keywords consist of alphanumeric strings placed at the beginning of lines. Comments and blank lines are ignored.- Returns:
- true if a keyword has been found and false if the end of content has been reached
- Throws:
IllegalStateException
- if invalid content is foundUncheckedIOException
- if an I/O error occurs
-
readDataLine
Read the remaining content on the current data line, taking line continuation characters into account.- Returns:
- remaining content on the current data line or null if the end of the content has been reached
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardDataLine
public void discardDataLine()Discard remaining content on the current data line, taking line continuation characters into account.- Throws:
UncheckedIOException
- if an I/O error occurs
-
readVector
Read a whitespace-delimited 3D vector from the current data line.- Returns:
- vector vector read from the current line
- Throws:
IllegalStateException
- if parsing failsUncheckedIOException
- if an I/O error occurs
-
readDoubles
public double[] readDoubles()Read whitespace-delimited double values from the current data line.- Returns:
- double values read from the current line
- Throws:
IllegalStateException
- if double values are not able to be parsedUncheckedIOException
- if an I/O error occurs
-
getTextParser
Get the text parser for the instance.- Returns:
- text parser for the instance
-
handleKeyword
Method called when a keyword is encountered in the parsed OBJ content. Subclasses should use this method to validate the keyword and/or update any internal state.- Parameters:
keyword
- keyword encountered in the OBJ content- Throws:
IllegalStateException
- if the given keyword is invalidUncheckedIOException
- if an I/O error occurs
-
discardDataLineWhitespace
Discard whitespace on the current data line, taking line continuation characters into account.- Returns:
- text parser instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
nextDataLineContent
protected boolean nextDataLineContent()Discard whitespace on the current data line and return true if any more characters remain on the line.- Returns:
- true if more non-whitespace characters remain on the current data line
- Throws:
UncheckedIOException
- if an I/O error occurs
-
nextDouble
protected double nextDouble()Get the next whitespace-delimited double on the current data line.- Returns:
- the next whitespace-delimited double on the current line
- Throws:
IllegalStateException
- if a double value is not able to be parsedUncheckedIOException
- if an I/O error occurs
-
readKeyword
private boolean readKeyword()Read a keyword consisting of alphanumeric characters from the current parser position and set it as the current token. Returns true if a non-empty keyword was found.- Returns:
- true if a non-empty keyword was found.
- Throws:
UncheckedIOException
- if an I/O error occurs
-