Class ConfigNode
- java.lang.Object
-
- com.djrapitops.plan.settings.config.ConfigNode
-
- Direct Known Subclasses:
Config
public class ConfigNode extends java.lang.Object
Represents a single node in a configuration fileBased on https://github.com/AuroraLS3/Abstract-Plugin-Framework/blob/72e221d3571ef200727713d10d3684c51e9f469d/AbstractPluginFramework/api/src/main/java/com/djrapitops/plugin/config/ConfigNode.java
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,ConfigNode>
childNodes
protected java.util.List<java.lang.String>
comment
protected java.lang.String
key
protected java.util.List<java.lang.String>
nodeOrder
protected ConfigNode
parent
protected java.lang.String
value
-
Constructor Summary
Constructors Constructor Description ConfigNode(java.lang.String key, ConfigNode parent, java.lang.String value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConfigNode
addChild(ConfigNode child)
Add a new child ConfigNode.ConfigNode
addNode(java.lang.String path)
boolean
contains(java.lang.String path)
void
copyAll(ConfigNode from)
void
copyMissing(ConfigNode from)
boolean
equals(java.lang.Object o)
boolean
getBoolean()
boolean
getBoolean(java.lang.String path)
java.util.Collection<ConfigNode>
getChildren()
java.util.List<java.lang.String>
getComment()
java.lang.Integer
getInteger()
java.lang.Integer
getInteger(java.lang.String path)
java.lang.String
getKey(boolean deep)
java.lang.Long
getLong()
java.lang.Long
getLong(java.lang.String path)
java.util.Optional<ConfigNode>
getNode(java.lang.String path)
protected int
getNodeDepth()
protected java.util.List<java.lang.String>
getNodeOrder()
ConfigNode
getParent()
java.lang.String
getString()
java.lang.String
getString(java.lang.String path)
java.util.List<java.lang.String>
getStringList()
java.util.List<java.lang.String>
getStringList(java.lang.String path)
java.util.Map<java.lang.String,java.lang.String>
getStringMap(boolean fullKeys)
Return values in a Map.int
hashCode()
boolean
isLeafNode()
boolean
moveChild(java.lang.String oldPath, java.lang.String newPath)
Moves a node from old path to new path.void
remove()
protected void
removeChild(ConfigNode child)
boolean
removeNode(java.lang.String path)
Remove a node at a certain path.void
reorder(java.util.List<java.lang.String> newOrder)
void
save()
Find the root node and save.<T> void
set(java.lang.String path, T value)
<T> void
set(T value)
void
setComment(java.util.List<java.lang.String> comment)
void
sort()
java.lang.String
toString()
protected void
updateParent(ConfigNode newParent)
-
-
-
Field Detail
-
key
protected final java.lang.String key
-
parent
protected ConfigNode parent
-
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()
-
getParent
public ConfigNode getParent()
-
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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-