Package dev.polv.taleapi.config
Interface ConfigNode
- All Known Implementing Classes:
JacksonConfigNode
public interface ConfigNode
A node in a configuration tree that provides dynamic access to values.
ConfigNode allows traversing and reading configuration data without defining a specific class structure. It supports nested objects, arrays, and all common primitive types.
Example Usage
ConfigNode config = loader.load(new File("config.json"));
// Get simple values
String name = config.getString("serverName");
int port = config.getInt("port", 8080); // with default
// Navigate nested objects
ConfigNode database = config.getSection("database");
String host = database.getString("host");
// Or use dot notation
String host = config.getString("database.host");
// Work with lists
List<String> mods = config.getStringList("enabledMods");
// Check existence
if (config.has("optionalFeature")) {
// ...
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> TConverts this node to a typed object.get(int index) Gets a child node by array index.Gets a child node by key.<T> TConverts a child node to a typed object.booleangetBoolean(String key) Gets a boolean value by key.booleangetBoolean(String key, boolean defaultValue) Gets a boolean value by key, with a default.doubleGets a double value by key.doubleGets a double value by key, with a default.intGets an integer value by key.intGets an integer value by key, with a default.getIntList(String key) Gets a list of integers by key.Gets a list of child nodes by key.longGets a long value by key.longGets a long value by key, with a default.getOptionalBoolean(String key) Gets an optional boolean value by key.getOptionalDouble(String key) Gets an optional double value by key.getOptionalInt(String key) Gets an optional integer value by key.getOptionalLong(String key) Gets an optional long value by key.getOptionalString(String key) Gets an optional string value by key.default ConfigNodegetSection(String key) Gets a nested object section by key.Gets a string value by key.Gets a string value by key, with a default.getStringList(String key) Gets a list of strings by key.booleanChecks if a key exists in this object node.booleanisArray()Checks if this node represents a JSON array.booleanisNull()Checks if this node is null or missing.booleanisObject()Checks if this node represents a JSON object (key-value pairs).booleanisValue()Checks if this node represents a primitive value (string, number, boolean).keys()Returns all keys in this object node.rawValue()Gets this node's value as a raw Object.intsize()Returns the number of elements in this node.toJson()Returns the JSON string representation of this node.Returns the pretty-printed JSON string representation of this node.
-
Method Details
-
isObject
boolean isObject()Checks if this node represents a JSON object (key-value pairs).- Returns:
- true if this node is an object
-
isArray
boolean isArray()Checks if this node represents a JSON array.- Returns:
- true if this node is an array
-
isValue
boolean isValue()Checks if this node represents a primitive value (string, number, boolean).- Returns:
- true if this node is a value
-
isNull
boolean isNull()Checks if this node is null or missing.- Returns:
- true if this node is null
-
has
Checks if a key exists in this object node.Supports dot notation for nested paths:
"database.host"- Parameters:
key- the key or path to check- Returns:
- true if the key exists
-
keys
Returns all keys in this object node.- Returns:
- set of keys, or empty set if not an object
-
size
int size()Returns the number of elements in this node.For objects, returns the number of keys. For arrays, returns the number of elements. For values, returns 1.
- Returns:
- the size of this node
-
get
Gets a child node by key.Supports dot notation for nested paths:
"database.host"- Parameters:
key- the key or path- Returns:
- the child node, or a null node if not found
-
get
Gets a child node by array index.- Parameters:
index- the array index- Returns:
- the child node, or a null node if out of bounds
-
getSection
Gets a nested object section by key.Equivalent to
get(String)but more readable for object access.- Parameters:
key- the key or path- Returns:
- the section node, or a null node if not found
-
getString
Gets a string value by key.- Parameters:
key- the key or path- Returns:
- the string value
- Throws:
ConfigException- if the key doesn't exist or isn't a string
-
getString
Gets a string value by key, with a default.- Parameters:
key- the key or pathdefaultValue- the default value if key doesn't exist- Returns:
- the string value or default
-
getOptionalString
Gets an optional string value by key.- Parameters:
key- the key or path- Returns:
- an Optional containing the value, or empty if not found
-
getInt
Gets an integer value by key.- Parameters:
key- the key or path- Returns:
- the integer value
- Throws:
ConfigException- if the key doesn't exist or isn't a number
-
getInt
Gets an integer value by key, with a default.- Parameters:
key- the key or pathdefaultValue- the default value if key doesn't exist- Returns:
- the integer value or default
-
getOptionalInt
Gets an optional integer value by key.- Parameters:
key- the key or path- Returns:
- an Optional containing the value, or empty if not found
-
getLong
Gets a long value by key.- Parameters:
key- the key or path- Returns:
- the long value
- Throws:
ConfigException- if the key doesn't exist or isn't a number
-
getLong
Gets a long value by key, with a default.- Parameters:
key- the key or pathdefaultValue- the default value if key doesn't exist- Returns:
- the long value or default
-
getOptionalLong
Gets an optional long value by key.- Parameters:
key- the key or path- Returns:
- an Optional containing the value, or empty if not found
-
getDouble
Gets a double value by key.- Parameters:
key- the key or path- Returns:
- the double value
- Throws:
ConfigException- if the key doesn't exist or isn't a number
-
getDouble
Gets a double value by key, with a default.- Parameters:
key- the key or pathdefaultValue- the default value if key doesn't exist- Returns:
- the double value or default
-
getOptionalDouble
Gets an optional double value by key.- Parameters:
key- the key or path- Returns:
- an Optional containing the value, or empty if not found
-
getBoolean
Gets a boolean value by key.- Parameters:
key- the key or path- Returns:
- the boolean value
- Throws:
ConfigException- if the key doesn't exist or isn't a boolean
-
getBoolean
Gets a boolean value by key, with a default.- Parameters:
key- the key or pathdefaultValue- the default value if key doesn't exist- Returns:
- the boolean value or default
-
getOptionalBoolean
Gets an optional boolean value by key.- Parameters:
key- the key or path- Returns:
- an Optional containing the value, or empty if not found
-
getList
Gets a list of child nodes by key.- Parameters:
key- the key or path- Returns:
- list of ConfigNode elements
-
getStringList
Gets a list of strings by key.- Parameters:
key- the key or path- Returns:
- list of strings
-
getIntList
Gets a list of integers by key.- Parameters:
key- the key or path- Returns:
- list of integers
-
as
Converts this node to a typed object.- Type Parameters:
T- the type- Parameters:
type- the class to convert to- Returns:
- the converted object
- Throws:
ConfigException- if conversion fails
-
get
Converts a child node to a typed object.- Type Parameters:
T- the type- Parameters:
key- the key or pathtype- the class to convert to- Returns:
- the converted object
- Throws:
ConfigException- if key doesn't exist or conversion fails
-
rawValue
Object rawValue()Gets this node's value as a raw Object.Returns:
- String, Number, Boolean for primitives
- List for arrays
- Map for objects
- null for null nodes
- Returns:
- the raw value
-
toJson
String toJson()Returns the JSON string representation of this node.- Returns:
- JSON string
-
toPrettyJson
String toPrettyJson()Returns the pretty-printed JSON string representation of this node.- Returns:
- pretty-printed JSON string
-