Class Node
java.lang.Object
com.github.tadukoo.parsing.fileformat.Node
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).
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)
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate Node
The child Node to this oneprivate final String
The data for this Nodeprivate final int
The level of Node this is (basically how many times you can call .getParent in a row from here)private Node
The next sibling Node to this oneprivate Node
The parent Node to this oneprivate Node
The previous sibling Node to this oneprivate final String
The name for what this piece of data is -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Node.NodeBuilder
builder()
Converts this Node and all the children and siblings down the line to a textual version (as in the actual files).Grabs all the data of all the Nodes in the tree.Grabs all the titles of all the Nodes in the tree.getChild()
getData()
int
getLevel()
getTitle()
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.static Node
loadFromList
(List<String> lines) Loads Nodes (including children + siblings) from the given List of lines and returns the head Node.static Node
loadFromString
(String text) Loads Nodes (including children + siblings) from the given text.void
Sets the child Node to this one.void
setNextSibling
(Node sibling) Sets the next sibling Node to this one.void
Sets the parent Node to this one.void
setPrevSibling
(Node sibling) Sets the previous sibling Node to this one.toString()
Converts this Node (and only this Node) to a String.
-
Field Details
-
title
The name for what this piece of data is -
data
The data for this Node -
level
private final int levelThe 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
-
-
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 isdata
- The data for this Nodelevel
- 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 onechild
- The child Node to this oneprevSibling
- The previous sibling Node to this onenextSibling
- The next sibling Node to this one
-
-
Method Details
-
builder
- Returns:
- A new
Node.NodeBuilder
to use to build a newNode
-
loadFromFile
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
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
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
- Returns:
- The name for what this piece of data is
-
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
- Returns:
- The parent Node to this one
-
setParent
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 anIllegalArgumentException
.- Parameters:
parent
- The Node to set as the parent of this one
-
getChild
- Returns:
- The child Node to this one
-
setChild
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 anIllegalArgumentException
.- Parameters:
child
- The Node to set as the child of this one
-
getPrevSibling
- Returns:
- The previous sibling Node to this one
-
setPrevSibling
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 anIllegalArgumentException
.- Parameters:
sibling
- The Node to set as the previous sibling of this one
-
getNextSibling
- Returns:
- The next sibling Node to this one
-
setNextSibling
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 anIllegalArgumentException
.- Parameters:
sibling
- The Node to set as the next sibling of this one
-
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), usefullToString()
. -
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
Grabs all the titles of all the Nodes in the tree.- Returns:
- A List of all the titles in the Node tree
-
getAllDatas
Grabs all the data of all the Nodes in the tree.- Returns:
- A List of all the data in the Node tree
-