Class ConfigNode

  • Direct Known Subclasses:
    Config

    public class ConfigNode
    extends java.lang.Object
    Represents a single node in a configuration file

    Based on https://github.com/AuroraLS3/Abstract-Plugin-Framework/blob/72e221d3571ef200727713d10d3684c51e9f469d/AbstractPluginFramework/api/src/main/java/com/djrapitops/plugin/config/ConfigNode.java

    • Field Detail

      • key

        protected final java.lang.String key
      • nodeOrder

        protected java.util.List<java.lang.String> nodeOrder
      • childNodes

        protected final java.util.Map<java.lang.String,​ConfigNode> childNodes
      • comment

        protected java.util.List<java.lang.String> comment
      • value

        protected java.lang.String value
    • Constructor Detail

      • ConfigNode

        public ConfigNode​(java.lang.String key,
                          ConfigNode parent,
                          java.lang.String value)
    • Method Detail

      • updateParent

        protected void updateParent​(ConfigNode newParent)
      • getNode

        public java.util.Optional<ConfigNode> getNode​(java.lang.String path)
      • contains

        public boolean contains​(java.lang.String path)
      • addNode

        public ConfigNode addNode​(java.lang.String path)
      • removeNode

        public boolean removeNode​(java.lang.String path)
        Remove a node at a certain path.
        Parameters:
        path - Path to the node that is up for removal.
        Returns:
        true if the node was present and is now removed. false if the path did not have a node.
      • remove

        public void remove()
      • addChild

        protected ConfigNode addChild​(ConfigNode child)
        Add a new child ConfigNode.
        Parameters:
        child - ConfigNode to add. If from another config tree, the parent is 'cut', which breaks the old tree traversal.
        Returns:
        Return the node given, now part of this tree.
      • removeChild

        protected void removeChild​(ConfigNode child)
      • moveChild

        public boolean moveChild​(java.lang.String oldPath,
                                 java.lang.String newPath)
        Moves a node from old path to new path.
        Parameters:
        oldPath - Old path of the node.
        newPath - New path of the node.
        Returns:
        true if the move was successful. false if the new node is not present
      • getKey

        public java.lang.String getKey​(boolean deep)
      • sort

        public void sort()
      • reorder

        public void reorder​(java.util.List<java.lang.String> newOrder)
      • save

        public void save()
                  throws java.io.IOException
        Find the root node and save.
        Throws:
        java.io.IOException - If the save can not be performed.
      • set

        public <T> void set​(java.lang.String path,
                            T value)
      • set

        public <T> void set​(T value)
      • getComment

        public java.util.List<java.lang.String> getComment()
      • setComment

        public void setComment​(java.util.List<java.lang.String> comment)
      • getStringList

        public java.util.List<java.lang.String> getStringList()
      • getInteger

        public java.lang.Integer getInteger()
      • getLong

        public java.lang.Long getLong()
      • getString

        public java.lang.String getString()
      • getBoolean

        public boolean getBoolean()
      • getStringList

        public java.util.List<java.lang.String> getStringList​(java.lang.String path)
      • getStringMap

        public java.util.Map<java.lang.String,​java.lang.String> getStringMap​(boolean fullKeys)
        Return values in a Map.
        Parameters:
        fullKeys - Should the key be full keys of the Config node.
        Returns:
        Map with Config key - ConfigNode#getString.
      • getInteger

        public java.lang.Integer getInteger​(java.lang.String path)
      • getLong

        public java.lang.Long getLong​(java.lang.String path)
      • getString

        public java.lang.String getString​(java.lang.String path)
      • getBoolean

        public boolean getBoolean​(java.lang.String path)
      • copyMissing

        public void copyMissing​(ConfigNode from)
      • copyAll

        public void copyAll​(ConfigNode from)
      • getNodeDepth

        protected int getNodeDepth()
      • isLeafNode

        public boolean isLeafNode()
      • getNodeOrder

        protected java.util.List<java.lang.String> getNodeOrder()
      • getChildren

        public java.util.Collection<ConfigNode> getChildren()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object