Class FormatNode.FormatNodeBuilder

java.lang.Object
com.github.tadukoo.parsing.fileformat.FormatNode.FormatNodeBuilder
Enclosing class:
FormatNode

public static class FormatNode.FormatNodeBuilder extends Object
Builder for constructing a FormatNode object.

MUST specify the following:
  • logger
  • text OR
    • name
    • titleRegex OR titleFormat
    • dataRegex OR dataFormat
    • level
Defaults are: Notes:
  • Specifying text means you can't specify anything else other than logger (which is required). You will get an IllegalArgumentException if you try.
    Specifying text will fill in the name, titleRegex, dataRegex, level, parentNames, childNames, prevSiblingNames, and nextSiblingNames based on the parsed text.
  • Specifying titleFormat will convert it into a titleRegex
  • Specifying dataFormat will convert it into a dataRegex
Since:
Alpha v.0.1
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Field Details

    • logger

      private com.github.tadukoo.util.logger.EasyLogger logger
      The EasyLogger to use for logging initialization messages
    • text

      private String text
      Text to use in parsing into a FormatNode
    • name

      private String name
      The name of the Node for identification purposes
    • titleRegex

      private String titleRegex
      The regex used to ensure the title is of the correct format
    • titleFormat

      private String titleFormat
      The TFormatting to convert into a regex for the title
    • dataRegex

      private String dataRegex
      The regex used to ensure the data is of the correct format
    • dataFormat

      private String dataFormat
      The TFormatting to convert into a regex for the data
    • level

      private int level
      The required level of the Node
    • parentNames

      private List<String> parentNames
      Names of allowed parent Nodes
    • childNames

      private List<String> childNames
      Names of allowed child Nodes
    • prevSiblingNames

      private List<String> prevSiblingNames
      Names of allowed previous sibling Nodes
    • nextSiblingNames

      private List<String> nextSiblingNames
      Names of allowed next sibling Nodes
  • Constructor Details

    • FormatNodeBuilder

      private FormatNodeBuilder()
      Not allowed to make FormatNodeBuilder outside of FormatNode
  • Method Details

    • logger

      public FormatNode.FormatNodeBuilder logger(com.github.tadukoo.util.logger.EasyLogger logger)
      Set the EasyLogger to use for logging initialization messages.
      Parameters:
      logger - The EasyLogger to use for logging messages
      Returns:
      The FormatNodeBuilder, to continue in building
    • text

      If you specify text, you should only specify the Logger in addition to this. Specifying anything else will cause an IllegalArgumentException, as the text is supposed to be the full formatting as a Tadukoo File Format format.
      Parameters:
      text - The text to parse as a Tadukoo File Format format
      Returns:
      The FormatNodeBuilder, to continue in building
    • name

      Sets the name to use for the FormatNode.
      Parameters:
      name - The name of the FormatNode
      Returns:
      The FormatNodeBuilder, to continue in building
    • titleRegex

      public FormatNode.FormatNodeBuilder titleRegex(String titleRegex)
      Sets the regex to use for the title of the Node.
      Parameters:
      titleRegex - The regex to use for the title of the Node
      Returns:
      The FormatNodeBuilder, to continue in building
    • titleFormat

      public FormatNode.FormatNodeBuilder titleFormat(String titleFormat)
      Sets the TFormatting to use for the title of the Node. This will be converted to a regex when building.
      Parameters:
      titleFormat - The TFormatting to use for the title of the Node
      Returns:
      The FormatNodeBuilder, to continue in building
    • dataRegex

      public FormatNode.FormatNodeBuilder dataRegex(String dataRegex)
      Sets the regex to use for the data of the Node.
      Parameters:
      dataRegex - The regex to use for the data of the Node
      Returns:
      The FormatNodeBuilder, to continue in building
    • dataFormat

      public FormatNode.FormatNodeBuilder dataFormat(String dataFormat)
      Sets the TFormatting to use for the data of the Node. This will be converted to a regex when building.
      Parameters:
      dataFormat - The TFormatting to use for the data of the Node
      Returns:
      The FormatNodeBuilder, to continue in building
    • level

      public FormatNode.FormatNodeBuilder level(int level)
      Sets the level of the Node.
      Parameters:
      level - The required level of the Node
      Returns:
      The FormatNodeBuilder, to continue in building
    • parentNamesCheck

      private void parentNamesCheck()
      Initializes the parentNames list to an empty ArrayList if it's null
    • parentNames

      public FormatNode.FormatNodeBuilder parentNames(List<String> parentNames)
      Sets the allowed names for parent Nodes.
      Parameters:
      parentNames - Names allowed for parent Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • parentName

      public FormatNode.FormatNodeBuilder parentName(String parentName)
      Adds the given string to the list of allowed names for parent Nodes.
      Parameters:
      parentName - The name to add to the list of allowed parent Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • nullParentName

      public FormatNode.FormatNodeBuilder nullParentName()
      Adds null to the allowed names for parent Nodes.
      Returns:
      The FormatNodeBuilder, to continue in building
    • childNamesCheck

      private void childNamesCheck()
      Initializes the childNames list to an empty ArrayList if it's null
    • childNames

      public FormatNode.FormatNodeBuilder childNames(List<String> childNames)
      Sets the allowed names for child Nodes.
      Parameters:
      childNames - Names allowed for child Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • childName

      public FormatNode.FormatNodeBuilder childName(String childName)
      Adds the given string to the list of allowed names for child Nodes.
      Parameters:
      childName - The name to add to the list of allowed child Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • nullChildName

      public FormatNode.FormatNodeBuilder nullChildName()
      Adds null to the allowed names for child Nodes.
      Returns:
      The FormatNodeBuilder, to continue in building
    • prevSiblingNamesCheck

      private void prevSiblingNamesCheck()
      Initializes the prevSiblingNames list to an empty ArrayList if it's null
    • prevSiblingNames

      public FormatNode.FormatNodeBuilder prevSiblingNames(List<String> prevSiblingNames)
      Sets the allowed names for previous sibling Nodes.
      Parameters:
      prevSiblingNames - Names allowed for previous sibling Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • prevSiblingName

      public FormatNode.FormatNodeBuilder prevSiblingName(String prevSiblingName)
      Adds the given string to the list of allowed names for previous sibling Nodes.
      Parameters:
      prevSiblingName - The name to add to the list of allowed previous sibling Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • nullPrevSiblingName

      public FormatNode.FormatNodeBuilder nullPrevSiblingName()
      Adds null to the allowed names for previous sibling Nodes.
      Returns:
      The FormatNodeBuilder, to continue in building
    • nextSiblingNamesCheck

      private void nextSiblingNamesCheck()
      Initializes the nextSiblingNames list to an empty ArrayList if it's null
    • nextSiblingNames

      public FormatNode.FormatNodeBuilder nextSiblingNames(List<String> nextSiblingNames)
      Sets the allowed names for next sibling Nodes.
      Parameters:
      nextSiblingNames - Names allowed for next sibling Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • nextSiblingName

      public FormatNode.FormatNodeBuilder nextSiblingName(String nextSiblingName)
      Adds the given string to the list of allowed names for next sibling Nodes.
      Parameters:
      nextSiblingName - The name to add to the list of allowed next sibling Nodes
      Returns:
      The FormatNodeBuilder, to continue in building
    • nullNextSiblingName

      public FormatNode.FormatNodeBuilder nullNextSiblingName()
      Adds null to the allowed names for next sibling Nodes.
      Returns:
      The FormatNodeBuilder, to continue in building
    • checkForErrors

      private void checkForErrors()
      Checks the builder for any errors in the data. Throws an IllegalArgumentException with any issues.
    • convertText

      private void convertText()
      Converts the text string into Nodes to be parsed into a FormatNode
    • makeNullAllowed

      private List<String> makeNullAllowed()
      Creates a List of strings that only contains the FormatNode.NULL_NODE string, to allow a null parent/child/sibling reference.
      Returns:
      A List with the NULL_NODE string in it
    • build

      public FormatNode build()
      Builds a new FormatNode with the specified parameters after checking for any errors.
      Returns:
      The newly built FormatNode