Class AbstractObjParser

  • Direct Known Subclasses:
    PolygonObjParser

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

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

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

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void discardDataLine()
      Discard remaining content on the current data line, taking line continuation characters into account.
      protected SimpleTextParser discardDataLineWhitespace()
      Discard whitespace on the current data line, taking line continuation characters into account.
      java.lang.String getCurrentKeyword()
      Get the current keyword, meaning the keyword most recently parsed via the nextKeyword() method.
      protected SimpleTextParser getTextParser()
      Get the text parser for the instance.
      protected abstract void handleKeyword​(java.lang.String keyword)
      Method called when a keyword is encountered in the parsed OBJ content.
      protected boolean nextDataLineContent()
      Discard whitespace on the current data line and return true if any more characters remain on the line.
      protected double nextDouble()
      Get the next whitespace-delimited double on the current data line.
      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.
      java.lang.String readDataLine()
      Read the remaining content on the current data line, taking line continuation characters into account.
      double[] readDoubles()
      Read whitespace-delimited double values from the current data line.
      private boolean readKeyword()
      Read a keyword consisting of alphanumeric characters from the current parser position and set it as the current token.
      Vector3D readVector()
      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 Detail

      • currentKeyword

        private java.lang.String currentKeyword
        The current (most recently parsed) keyword.
    • Constructor Detail

      • 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 Detail

      • getCurrentKeyword

        public java.lang.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:
        java.lang.IllegalStateException - if invalid content is found
        java.io.UncheckedIOException - if an I/O error occurs
      • readDataLine

        public java.lang.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:
        java.io.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:
        java.io.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:
        java.lang.IllegalStateException - if parsing fails
        java.io.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:
        java.lang.IllegalStateException - if double values are not able to be parsed
        java.io.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​(java.lang.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:
        java.lang.IllegalStateException - if the given keyword is invalid
        java.io.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:
        java.io.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:
        java.io.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:
        java.lang.IllegalStateException - if a double value is not able to be parsed
        java.io.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:
        java.io.UncheckedIOException - if an I/O error occurs