Class DataSection
java.lang.Object
studio.magemonkey.codex.mccore.config.parse.DataSection
Represents a section of a config
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComment(String key, String comment) Adds a comment in front of the value with the keyvoidapplyDefaults(DataSection defaults) Applies defaults to this data sectionvoidcheckDefault(String key, Object defaultValue) Checks for a default value in the data.voidclear()Clears all data and comments from the data sectionvoidclearAllComments(boolean deep) Clears all commentsvoidclearComments(String key) Clears the comments for the given nodecreateSection(String key) Creates a new data section at the given keydefaultSection(String key) Checks for a data section at the given key.voiddump(BufferedWriter write) Dumps the data contents into the streamvoidDumps the data contents to a file to the given filevoidDumps the data contents to a file at the given pathentrySet()Retrieves the set of entries in this data sectionRetrieves a generic value at the given keyRetrieves a generic value at the given keybooleangetBoolean(String key) Retrieves a boolean value from the databooleangetBoolean(String key, boolean fallback) Retrieves a boolean value from the databyteRetrieves a byte value from the databyteRetrieves a byte value from the datacharRetrieves a character value from the data.charRetrieves a character value from the data.getComments(String key) Gets the comments for a data valuedoubleRetrieves a double value from the datadoubleRetrieves a double value from the datafloatRetrieves a float value from the datafloatRetrieves a float value from the dataintRetrieves an integer value from the dataintRetrieves an integer value from the dataRetrieves a string list value from the configRetrieves a string list value from the configgetSection(String key) Retrieves a data section from the given locationshortRetrieves a short value from the datashortRetrieves a short value from the dataRetrieves a string value from the dataRetrieves a string value from the databooleanChecks whether the data contains a value at the given keybooleanhasComment(String key) Checks whether the data has a comment for itbooleanChecks whether the data contains a list value at the given keybooleanChecks whether the value at the key is a numberbooleanChecks whether the value at the given key is a data sectionkeys()Retrieves the keys within the sectionRemoves a value at the given key along with its comments.voidSets a value to the configvoidsetComments(String key, List<String> comments) Sets the comments to have above the specified nodeintsize()toString()Returns the YAML string for the config datatoString(char quote) Returns the YAML string for the config datavoidtrim(DataSection defaults) Trims the data, only keeping what is also in the default sectionvalues()Retrieves the values contained in the keys for this section
-
Constructor Details
-
DataSection
public DataSection()
-
-
Method Details
-
clear
public void clear()Clears all data and comments from the data section -
keys
-
size
public int size()- Returns:
- number of key/value pairs
-
entrySet
-
values
Retrieves the values contained in the keys for this section- Returns:
- values contained in the keys for this section
-
addComment
-
hasComment
Checks whether the data has a comment for it- Parameters:
key- data key- Returns:
- true if the section has comments
-
getComments
-
setComments
-
clearComments
Clears the comments for the given node- Parameters:
key- key of the node to clear for
-
clearAllComments
public void clearAllComments(boolean deep) Clears all comments- Parameters:
deep- true if to clear comments in all child sections as well
-
set
-
checkDefault
-
createSection
Creates a new data section at the given key- Parameters:
key- key to create the section at- Returns:
- the created section
-
defaultSection
Checks for a data section at the given key. If it is not a section, a new one will be created and returned. Otherwise, the existing section will be returned.- Parameters:
key- key to check for a section at- Returns:
- current section at the key, new or existing
-
remove
-
isSection
Checks whether the value at the given key is a data section- Parameters:
key- key of the value- Returns:
- true if DataSection, false otherwise
-
has
Checks whether the data contains a value at the given key- Parameters:
key- key to check- Returns:
- true if contains a value, false otherwise
-
isList
Checks whether the data contains a list value at the given key- Parameters:
key- key to check for a list value at- Returns:
- true if a list value is set at the key, false otherwise
-
isNumber
Checks whether the value at the key is a number- Parameters:
key- key to check for a number value at- Returns:
- true if a number is at the key, false otherwise
-
getSection
Retrieves a data section from the given location- Parameters:
key- key of the section to retrieve- Returns:
- found section or null if not found
-
getChar
Retrieves a character value from the data. If more than one character is found, this will only return the first.- Parameters:
key- key of the value to retrieve- Returns:
- the character from the config or '\0' if not found
-
getString
-
getBoolean
Retrieves a boolean value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the boolean value from the config or false if not found
-
getByte
Retrieves a byte value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the byte value or 0 if not found or not a number
-
getShort
Retrieves a short value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the short value or 0 if not found or not a number
-
getInt
Retrieves an integer value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the integer value or 0 if not found or not a number
-
getFloat
Retrieves a float value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the float value or 0 if not found or not a number
-
getDouble
Retrieves a double value from the data- Parameters:
key- key of the value to retrieve- Returns:
- the double value or fallback if not found or not a number
-
getList
-
getChar
Retrieves a character value from the data. If more than one character is found, this will only return the first.- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the character from the config or fallback if not found
-
getString
-
getBoolean
Retrieves a boolean value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the boolean value from the config or fallback if not found
-
getByte
Retrieves a byte value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the byte value or fallback if not found or not a number
-
getShort
Retrieves a short value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the short value or fallback if not found or not a number
-
getInt
Retrieves an integer value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the integer value or fallback if not found or not a number
-
getFloat
Retrieves a float value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the float value or fallback if not found or not a number
-
getDouble
Retrieves a double value from the data- Parameters:
key- key of the value to retrievefallback- value to return if not found- Returns:
- the double value or fallback if not found or not a number
-
getList
-
get
-
get
-
applyDefaults
Applies defaults to this data section- Parameters:
defaults- defaults to apply
-
trim
Trims the data, only keeping what is also in the default section- Parameters:
defaults- default section to trim to
-
dump
Dumps the data contents to a file at the given path- Parameters:
path- path to the file
-
dump
Dumps the data contents to a file to the given file- Parameters:
file- file to dump to
-
dump
Dumps the data contents into the stream- Parameters:
write- stream to dump to- Throws:
IOException- thrown if an error occurs while writing
-
toString
-
toString
Returns the YAML string for the config data- Parameters:
quote- the character to wrap strings in- Returns:
- YAML data string
-