Record Class ConfigKey<T>

java.lang.Object
java.lang.Record
de.eldoria.eldoutilities.config.ConfigKey<T>
Type Parameters:
T - type of file class
Record Components:
name - name of file
path - path of file with file ending. Path might be relative to Plugin.getDataFolder()
configClazz - class representing the file
initValue - the initial value when the file does not yet exist.

public record ConfigKey<T>(String name, Path path, Class<T> configClazz, Supplier<T> initValue) extends Record
A key for a config file. A config key is considered unique based on the underlying path.

Two config keys pointing at the same file, but one being absolute and the other not are not considered equal. However, this should be avoided since it can cause issues when reloading or saving.

  • Constructor Details

    • ConfigKey

      public ConfigKey(String name, Path path, Class<T> configClazz, Supplier<T> initValue)
      Creates an instance of a ConfigKey record class.
      Parameters:
      name - the value for the name record component
      path - the value for the path record component
      configClazz - the value for the configClazz record component
      initValue - the value for the initValue record component
  • Method Details

    • defaultConfig

      public static <V> ConfigKey<V> defaultConfig(Class<V> configClazz, Supplier<V> initValue)
      Create a key for the default config aka config.yml.
      Type Parameters:
      V - type of config class
      Parameters:
      configClazz - class representing the config.yml
      initValue - the initial value when the config does not yet exist.
      Returns:
      config key for config.yml
    • of

      public static <V> ConfigKey<V> of(String name, Path path, Class<V> configClazz, Supplier<V> initValue)
      Create a key for the default config aka config.yml.
      Type Parameters:
      V - type of config class
      Parameters:
      name - name of file
      path - path of file with file ending. Path might be relative to Plugin.getDataFolder()
      configClazz - class representing the config.yml
      initValue - the initial value when the config does not yet exist.
      Returns:
      config key for config.yml
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • path

      public Path path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component
    • configClazz

      public Class<T> configClazz()
      Returns the value of the configClazz record component.
      Returns:
      the value of the configClazz record component
    • initValue

      public Supplier<T> initValue()
      Returns the value of the initValue record component.
      Returns:
      the value of the initValue record component