java.lang.Object
de.Keyle.MyPet.api.util.configuration.settings.Setting

public class Setting extends Object
One token parsed out of a Settings string. Either a keyed entry (e.g. "min=20" — key "min", value "20") or a positional entry (e.g. "50%" — key "50%", value absent).

Prefer the typed accessors (getInt(), getDouble(), getBoolean()). asString() is kept as an escape hatch for values that carry custom syntax the typed accessors don't model (e.g. a % suffix).

  • Constructor Details

    • Setting

      public Setting(String key)
      Creates a positional entry, one with no = in it.
      Parameters:
      key - the whole token
    • Setting

      public Setting(String key, String value)
      Creates a keyed entry parsed from k=v.
      Parameters:
      key - the left-hand side
      value - the right-hand side
  • Method Details

    • getKey

      public String getKey()
      Original-case key. For a keyed entry this is the LHS of k=v; for a positional entry this is the whole token.
      Returns:
      the key, in its original casing
    • asString

      public String asString()
      Raw string content of this entry. For a keyed entry returns the value; for a positional entry returns the key. Use this when the typed accessors don't fit (custom syntax, suffix detection, etc.).
      Returns:
      the entry's string content
    • getInt

      public OptionalInt getInt()
      Parses asString() as an int.
      Returns:
      the parsed value, or empty if it does not parse
    • getDouble

      public OptionalDouble getDouble()
      Parses asString() as a double.
      Returns:
      the parsed value, or empty if it does not parse
    • getBoolean

      public Optional<Boolean> getBoolean()
      Parses asString() as a boolean. Accepts only "true" and "false", case-insensitively.
      Returns:
      the parsed value, or empty for anything else