Class KeyBuilder

java.lang.Object
com.tchristofferson.configupdater.KeyBuilder
All Implemented Interfaces:
Cloneable

public class KeyBuilder extends Object implements Cloneable
  • Constructor Summary

    Constructors
    Constructor
    Description
    KeyBuilder(org.bukkit.configuration.file.FileConfiguration config, char separator)
    Constructs a new KeyBuilder instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the contents of the builder.
    protected KeyBuilder
    Creates a clone of this KeyBuilder instance.
    Gets the last key in the builder.
    boolean
    Checks if the key path represented by this instance is a configuration section in the FileConfiguration.
    boolean
    Checks if the key path represented by this instance is a non-empty configuration section in the FileConfiguration.
    boolean
    Checks if the builder is empty.
    boolean
    isSubKey(String subKey)
    Checks if the specified subKey is a sub-key of the key path represented by this instance.
    boolean
    isSubKeyOf(String parentKey)
    Checks if the full key path represented by this instance is a sub-key of the specified parent key.
    void
    parseLine(String line, boolean checkIfExists)
    Parses the line to check if it represents a valid YAML path.
    void
    Removes the last key from the builder.
    Returns the current key path as a string.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • KeyBuilder

      public KeyBuilder(org.bukkit.configuration.file.FileConfiguration config, char separator)
      Constructs a new KeyBuilder instance.
      Parameters:
      config - the FileConfiguration to work with.
      separator - the character used as the separator between key parts. The default separator is a dot ('.').
  • Method Details

    • parseLine

      public void parseLine(String line, boolean checkIfExists)
      Parses the line to check if it represents a valid YAML path. If the config does not contain the path, it removes the last part of the line until it finds a valid path or becomes empty.
      Parameters:
      line - the line to check if it belongs to the current path set in the builder.
      checkIfExists - set to true to check if the path is valid in the config.
    • getLastKey

      public String getLastKey()
      Gets the last key in the builder.
      Returns:
      the last key, or an empty string if the builder is empty.
    • isEmpty

      public boolean isEmpty()
      Checks if the builder is empty.
      Returns:
      true if the builder is empty; otherwise, false.
    • clear

      public void clear()
      Clears the contents of the builder.
    • isSubKeyOf

      public boolean isSubKeyOf(String parentKey)
      Checks if the full key path represented by this instance is a sub-key of the specified parent key.
      Parameters:
      parentKey - the parent key to check against.
      Returns:
      true if the full key path is a sub-key of the parentKey; otherwise, false.
    • isSubKey

      public boolean isSubKey(String subKey)
      Checks if the specified subKey is a sub-key of the key path represented by this instance.
      Parameters:
      subKey - the sub-key to check.
      Returns:
      true if the subKey is a sub-key of the key path; otherwise, false.
    • isConfigSection

      public boolean isConfigSection()
      Checks if the key path represented by this instance is a configuration section in the FileConfiguration.
      Returns:
      true if the key path is a configuration section; otherwise, false.
    • isConfigSectionWithKeys

      public boolean isConfigSectionWithKeys()
      Checks if the key path represented by this instance is a non-empty configuration section in the FileConfiguration.
      Returns:
      true if the key path is a non-empty configuration section; otherwise, false.
    • removeLastKey

      public void removeLastKey()
      Removes the last key from the builder. For example, if the input is 'key1.key2', the result will be 'key1'.
    • toString

      public String toString()
      Returns the current key path as a string.
      Overrides:
      toString in class Object
      Returns:
      the current key path.
    • clone

      protected KeyBuilder clone()
      Creates a clone of this KeyBuilder instance.
      Overrides:
      clone in class Object
      Returns:
      a new KeyBuilder instance with the same contents as this instance.