Class AbstractObjParser

java.lang.Object
org.apache.commons.geometry.io.euclidean.threed.obj.AbstractObjParser
Direct Known Subclasses:
PolygonObjParser

public abstract class AbstractObjParser extends Object
Abstract base class for OBJ parsing functionality.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
    The current (most recently parsed) keyword.
    private final SimpleTextParser
    Text parser instance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Construct a new instance for parsing OBJ content from the given text parser.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Discard remaining content on the current data line, taking line continuation characters into account.
    Discard whitespace on the current data line, taking line continuation characters into account.
    Get the current keyword, meaning the keyword most recently parsed via the nextKeyword() method.
    Get the text parser for the instance.
    protected abstract void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • parser

      private final SimpleTextParser parser
      Text parser instance.
    • currentKeyword

      private String currentKeyword
      The current (most recently parsed) keyword.
  • Constructor Details

    • AbstractObjParser

      protected AbstractObjParser(SimpleTextParser parser)
      Construct a new instance for parsing OBJ content from the given text parser.
      Parameters:
      parser - text parser to read content from
  • Method Details

    • getCurrentKeyword

      public String getCurrentKeyword()
      Get the current keyword, meaning the keyword most recently parsed via the nextKeyword() 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 found
      UncheckedIOException - if an I/O error occurs
    • readDataLine

      public String 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

      public Vector3D readVector()
      Read a whitespace-delimited 3D vector from the current data line.
      Returns:
      vector vector read from the current line
      Throws:
      IllegalStateException - if parsing fails
      UncheckedIOException - 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 parsed
      UncheckedIOException - if an I/O error occurs
    • getTextParser

      protected SimpleTextParser getTextParser()
      Get the text parser for the instance.
      Returns:
      text parser for the instance
    • handleKeyword

      protected abstract void handleKeyword(String keyword)
      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 invalid
      UncheckedIOException - if an I/O error occurs
    • discardDataLineWhitespace

      protected SimpleTextParser 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 parsed
      UncheckedIOException - 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