Class BaseNode

java.lang.Object
cn.nukkit.nbt.snbt.BaseNode
All Implemented Interfaces:
Node, Comparable<Node>
Direct Known Subclasses:
ByteArrayNBT, CompoundNBT, IntArrayNBT, KeyValuePair, ListNBT, Root, Value

public class BaseNode extends Object implements Node
The base concrete class for non-terminal Nodes
  • Constructor Details

    • BaseNode

      public BaseNode()
  • Method Details

    • getTokenSource

      public SNBTLexer getTokenSource()
      Specified by:
      getTokenSource in interface Node
      Returns:
      the #SNBTLexer from which this Node object originated. There is no guarantee that this doesn't return null. Most likely that would simply be because you constructed the Node yourself, i.e. it didn't really come about via the parsing/tokenizing machinery.
    • setTokenSource

      public void setTokenSource(SNBTLexer tokenSource)
      Specified by:
      setTokenSource in interface Node
    • setListClass

      public static void setListClass(Class<? extends List> listClass)
      Sets the List class that is used to store child nodes. By default, this is java.util.ArrayList. There is probably very little reason to ever use anything else, though you could use this method to replace this with LinkedList or your own java.util.List implementation even.
      Parameters:
      listClass - the #java.util.List implementation to use internally for the child nodes. By default #java.util.ArrayList is used.
    • isUnparsed

      public boolean isUnparsed()
      Specified by:
      isUnparsed in interface Node
      Returns:
      whether this Node was created by regular operations of the parsing machinery.
    • setUnparsed

      public void setUnparsed(boolean unparsed)
      Description copied from interface: Node
      Mark whether this Node is unparsed, i.e. not the result of normal parsing
      Specified by:
      setUnparsed in interface Node
      Parameters:
      unparsed - whether to set the Node as unparsed or parsed.
    • setParent

      public void setParent(Node n)
      Specified by:
      setParent in interface Node
      Parameters:
      n - The Node to set as the parent. Mostly used internally. The various addChild or appendChild sorts of methods should use this to set the node's parent.
    • getParent

      public Node getParent()
      Specified by:
      getParent in interface Node
      Returns:
      this node's parent Node
    • addChild

      public void addChild(Node n)
      Description copied from interface: Node
      appends a child node to this Node
      Specified by:
      addChild in interface Node
      Parameters:
      n - the Node to append
    • addChild

      public void addChild(int i, Node n)
      Description copied from interface: Node
      inserts a child Node at a specific index, displacing the nodes after the index by 1.
      Specified by:
      addChild in interface Node
      Parameters:
      i - the (zero-based) index at which to insert the node
      n - the Node to insert
    • getChild

      public Node getChild(int i)
      Specified by:
      getChild in interface Node
      Parameters:
      i - the index of the Node to return
      Returns:
      the Node at the specific offset
    • setChild

      public void setChild(int i, Node n)
      Description copied from interface: Node
      Replace the node at index i
      Specified by:
      setChild in interface Node
      Parameters:
      i - the index
      n - the node
    • removeChild

      public Node removeChild(int i)
      Description copied from interface: Node
      Remove the node at index i. Any Nodes after i are shifted to the left.
      Specified by:
      removeChild in interface Node
      Parameters:
      i - the index at which to remove
      Returns:
      the removed Node
    • clearChildren

      public void clearChildren()
      Description copied from interface: Node
      Remove all the child nodes
      Specified by:
      clearChildren in interface Node
    • getChildCount

      public int getChildCount()
      Specified by:
      getChildCount in interface Node
      Returns:
      the number of child nodes
    • children

      public List<Node> children()
      Specified by:
      children in interface Node
    • getBeginOffset

      public int getBeginOffset()
      Specified by:
      getBeginOffset in interface Node
      Returns:
      the offset in the input source where the token begins, expressed in code units.
    • setBeginOffset

      public void setBeginOffset(int beginOffset)
      Description copied from interface: Node
      Set the offset where the token begins, expressed in code units.
      Specified by:
      setBeginOffset in interface Node
    • getEndOffset

      public int getEndOffset()
      Specified by:
      getEndOffset in interface Node
      Returns:
      the offset in the input source where the token ends, expressed in code units. This is actually the offset where the very next token would begin.
    • setEndOffset

      public void setEndOffset(int endOffset)
      Description copied from interface: Node
      Set the offset where the token ends, actually the location where the very next token should begin.
      Specified by:
      setEndOffset in interface Node
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getNamedChild

      public Node getNamedChild(String name)
    • setNamedChild

      public void setNamedChild(String name, Node node)
    • getNamedChildList

      public List<Node> getNamedChildList(String name)
    • addToNamedChildList

      public void addToNamedChildList(String name, Node node)