java.lang.Object
com.github.tadukoo.parsing.fileformat.Node

public class Node extends Object
A Node is a single line of text in a full file under the TadFileFormat. From it, you can navigate up or down the file through parent/child node relationships and through sibling relationships.
Note: Each Node can only have one parent, one child, and can only reference its previous and next sibling Nodes.

Example:
  Person:
    Name: Logan Ferree
    Job: Programmer
  Person 2:
    Name: Me
    Job: Unknown

In this example, Person and Person 2 are siblings, so Person's Node.getNextSibling() gives Person 2's Node and Person 2's Node.getPrevSibling() gives Person's Node.
Name is the child of the Person Nodes, so from either Person Node, using .getChild() will give the following Name Node.
To go from Person to Job, you'd have to do Person Node .getChild() .getNextSibling() (as Job is a sibling of Name).
Since:
Alpha v.0.1
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Field Details

    • title

      private final String title
      The name for what this piece of data is
    • data

      private final String data
      The data for this Node
    • level

      private final int level
      The level of Node this is (basically how many times you can call .getParent in a row from here)
    • parent

      private Node parent
      The parent Node to this one
    • child

      private Node child
      The child Node to this one
    • prevSibling

      private Node prevSibling
      The previous sibling Node to this one
    • nextSibling

      private Node nextSibling
      The next sibling Node to this one
  • Constructor Details

    • Node

      private Node(String title, String data, int level, Node parent, Node child, Node prevSibling, Node nextSibling)
      Create a Node using all of the information to be stored in it.
      Parameters:
      title - The name for what this piece of data is
      data - The data for this Node
      level - The level of node this is (basically how many times you can call .getParent() in a row from here)
      parent - The parent Node to this one
      child - The child Node to this one
      prevSibling - The previous sibling Node to this one
      nextSibling - The next sibling Node to this one
  • Method Details

    • builder

      public static Node.NodeBuilder builder()
      Returns:
      A new Node.NodeBuilder to use to build a new Node
    • loadFromFile

      public static Node loadFromFile(String filepath)
      Loads the given file and creates a Node (and any children and siblings down the line) from the contents of the file.
      Parameters:
      filepath - The path to the file
      Returns:
      The head Node created from the file
    • loadFromString

      public static Node loadFromString(String text)
      Loads Nodes (including children + siblings) from the given text. The text should be formatted so lines are separated using only the newline character (\n).
      Parameters:
      text - The text to convert into Nodes
      Returns:
      The head Node loaded from the given text
    • loadFromList

      public static Node loadFromList(List<String> lines)
      Loads Nodes (including children + siblings) from the given List of lines and returns the head Node.
      Parameters:
      lines - The lines of text to convert into Nodes
      Returns:
      The head Node resulting from the given text
    • getTitle

      public String getTitle()
      Returns:
      The name for what this piece of data is
    • getData

      public String getData()
      Returns:
      The data for this Node
    • getLevel

      public int getLevel()
      Returns:
      The level of Node this is (basically how many times you can call .getParent in a row from here)
    • getParent

      public Node getParent()
      Returns:
      The parent Node to this one
    • setParent

      public void setParent(Node parent)
      Sets the parent Node to this one. Checks if the level of the parent is less than the level of this Node, and if not, throws an IllegalArgumentException.
      Parameters:
      parent - The Node to set as the parent of this one
    • getChild

      public Node getChild()
      Returns:
      The child Node to this one
    • setChild

      public void setChild(Node child)
      Sets the child Node to this one. Checks if the level of the child is greater than the level of this Node, and if not, throws an IllegalArgumentException.
      Parameters:
      child - The Node to set as the child of this one
    • getPrevSibling

      public Node getPrevSibling()
      Returns:
      The previous sibling Node to this one
    • setPrevSibling

      public void setPrevSibling(Node sibling)
      Sets the previous sibling Node to this one. Checks if the level of the sibling is equal to the level of this Node, and if not, throws an IllegalArgumentException.
      Parameters:
      sibling - The Node to set as the previous sibling of this one
    • getNextSibling

      public Node getNextSibling()
      Returns:
      The next sibling Node to this one
    • setNextSibling

      public void setNextSibling(Node sibling)
      Sets the next sibling Node to this one. Checks if the level of the sibling is equal to the level of this Node, and if not, throws an IllegalArgumentException.
      Parameters:
      sibling - The Node to set as the next sibling of this one
    • toString

      public String toString()
      Converts this Node (and only this Node) to a String. To convert this Node and all the children and siblings down the line to a textual version (as in the actual files), use fullToString().
      Overrides:
      toString in class Object
      Returns:
      The String representation of solely this Node
    • fullToString

      public String fullToString()
      Converts this Node and all the children and siblings down the line to a textual version (as in the actual files).
      Returns:
      The String representation of this Node and all its children and siblings
    • getAllTitles

      public List<String> getAllTitles()
      Grabs all the titles of all the Nodes in the tree.
      Returns:
      A List of all the titles in the Node tree
    • getAllDatas

      public List<String> getAllDatas()
      Grabs all the data of all the Nodes in the tree.
      Returns:
      A List of all the data in the Node tree