Class DataSection

java.lang.Object
studio.magemonkey.codex.mccore.config.parse.DataSection

public class DataSection extends Object
Represents a section of a config
  • Constructor Details

    • DataSection

      public DataSection()
  • Method Details

    • clear

      public void clear()
      Clears all data and comments from the data section
    • keys

      public List<String> keys()
      Retrieves the keys within the section
      Returns:
      keys in the data section
    • size

      public int size()
      Returns:
      number of key/value pairs
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      Retrieves the set of entries in this data section
      Returns:
      entry set of the data section
    • values

      public Collection<Object> values()
      Retrieves the values contained in the keys for this section
      Returns:
      values contained in the keys for this section
    • addComment

      public void addComment(String key, String comment)
      Adds a comment in front of the value with the key
      Parameters:
      key - key of the value the comment is in front of
      comment - comment to add
    • hasComment

      public boolean hasComment(String key)
      Checks whether the data has a comment for it
      Parameters:
      key - data key
      Returns:
      true if the section has comments
    • getComments

      public List<String> getComments(String key)
      Gets the comments for a data value
      Parameters:
      key - data key
      Returns:
      list of comments
    • setComments

      public void setComments(String key, List<String> comments)
      Sets the comments to have above the specified node
      Parameters:
      comments - comments above a given node
    • clearComments

      public void clearComments(String key)
      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

      public void set(String key, Object value)
      Sets a value to the config
      Parameters:
      key - key to represent the value
      value - value to set
    • checkDefault

      public void checkDefault(String key, Object defaultValue)
      Checks for a default value in the data. If the value is not there, the provided default value will be applied.
      Parameters:
      key - key of the default value
      defaultValue - value to apply if no value is present
    • createSection

      public DataSection createSection(String key)
      Creates a new data section at the given key
      Parameters:
      key - key to create the section at
      Returns:
      the created section
    • defaultSection

      public DataSection defaultSection(String key)
      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

      public Object remove(String key)
      Removes a value at the given key along with its comments.
      Parameters:
      key - key to remove a value for
      Returns:
      the removed value or null of no value was present
    • isSection

      public boolean isSection(String key)
      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

      public boolean has(String key)
      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

      public boolean isList(String key)
      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

      public boolean isNumber(String key)
      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

      public DataSection getSection(String key)
      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

      public char getChar(String key)
      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

      public String getString(String key)
      Retrieves a string value from the data
      Parameters:
      key - key of the value to retrieve
      Returns:
      the string value from the config or null if not found
    • getBoolean

      public boolean getBoolean(String key)
      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

      public byte getByte(String key)
      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

      public short getShort(String key)
      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

      public int getInt(String key)
      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

      public float getFloat(String key)
      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

      public double getDouble(String key)
      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

      public List<String> getList(String key)
      Retrieves a string list value from the config
      Parameters:
      key - key of the value to retrieve
      Returns:
      the list value or an empty list if not found
    • getChar

      public char getChar(String key, char fallback)
      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
      fallback - value to return if not found
      Returns:
      the character from the config or fallback if not found
    • getString

      public String getString(String key, String fallback)
      Retrieves a string value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the string value from the config or fallback if not found
    • getBoolean

      public boolean getBoolean(String key, boolean fallback)
      Retrieves a boolean value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the boolean value from the config or fallback if not found
    • getByte

      public byte getByte(String key, byte fallback)
      Retrieves a byte value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the byte value or fallback if not found or not a number
    • getShort

      public short getShort(String key, short fallback)
      Retrieves a short value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the short value or fallback if not found or not a number
    • getInt

      public int getInt(String key, int fallback)
      Retrieves an integer value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the integer value or fallback if not found or not a number
    • getFloat

      public float getFloat(String key, float fallback)
      Retrieves a float value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the float value or fallback if not found or not a number
    • getDouble

      public double getDouble(String key, double fallback)
      Retrieves a double value from the data
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the double value or fallback if not found or not a number
    • getList

      public List<String> getList(String key, List<String> fallback)
      Retrieves a string list value from the config
      Parameters:
      key - key of the value to retrieve
      fallback - value to return if not found
      Returns:
      the list value or fallback if not found
    • get

      public Object get(String key)
      Retrieves a generic value at the given key
      Parameters:
      key - key to get the value for
      Returns:
      the value at the given key
    • get

      public Object get(String key, Object fallback)
      Retrieves a generic value at the given key
      Parameters:
      key - key to get the value for
      fallback - value to return if not found
      Returns:
      the value at the given key or fallback if not found
    • applyDefaults

      public void applyDefaults(DataSection defaults)
      Applies defaults to this data section
      Parameters:
      defaults - defaults to apply
    • trim

      public void trim(DataSection defaults)
      Trims the data, only keeping what is also in the default section
      Parameters:
      defaults - default section to trim to
    • dump

      public void dump(String path)
      Dumps the data contents to a file at the given path
      Parameters:
      path - path to the file
    • dump

      public void dump(File file)
      Dumps the data contents to a file to the given file
      Parameters:
      file - file to dump to
    • dump

      public void dump(BufferedWriter write) throws IOException
      Dumps the data contents into the stream
      Parameters:
      write - stream to dump to
      Throws:
      IOException - thrown if an error occurs while writing
    • toString

      public String toString()
      Returns the YAML string for the config data
      Overrides:
      toString in class Object
      Returns:
      YAML data string
    • toString

      public String toString(char quote)
      Returns the YAML string for the config data
      Parameters:
      quote - the character to wrap strings in
      Returns:
      YAML data string