Interface TomlKey

All Superinterfaces:
Collection<String>, Comparable<TomlKey>, Iterable<String>

@NonExtendable public interface TomlKey extends Collection<String>, Comparable<TomlKey>
Represents a parsed TOML key by parts
See Also:
  • Method Details

    • parse

      @Contract("_ -> new") @NotNull static @NotNull TomlKey parse(@NotNull @NotNull CharSequence key) throws IllegalArgumentException
      Parses a string representation of a TOML key. Extraneous whitespace is NOT allowed.

      Example

      
       TomlKey.parse("'foo.bar'.\"\\U0001F60E\"")
            .toString(); // "foo.bar"."😎"
       
      Throws:
      IllegalArgumentException - Key is empty, has empty parts, has an illegally placed opening quotation mark/single quote, has a missing closing quotation mark/single quote, has an unescaped special character between opening and closing quotation marks, or has a single quote between opening and closing single quotes
    • join

      @NotNull static @NotNull TomlKey join(@NotNull @NotNull TomlKey first, @NotNull @NotNull TomlKey @NotNull ... additional)
      Returns a TOML key that represents a concatenation of the parts of each provided key. If only 1 key is provided (additional is empty), the first key (first) is always returned as-is. Otherwise, a new key is created.
    • literal

      @SafeVarargs @Experimental @Contract("_ -> new") @NotNull static <S extends CharSequence> @NotNull TomlKey literal(@NotNull @NotNull S @NotNull ... parts)
      Wraps a pre-parsed TOML key (by parts) into a TomlKey object. No parsing is performed.
      See Also:
    • size

      int size()
      Provides the number of parts in this key. A valid key is expected to have at least 1 part. The TomlKey that serializes to "" would have 1 part with a length of 0.
      Specified by:
      size in interface Collection<String>
    • get

      @NotNull default @NotNull String get(int index) throws IndexOutOfBoundsException
      Gets the Nth part of this key. Depending on the key implementation, this may be less efficient than stream()/Collection.iterator().
      Throws:
      IndexOutOfBoundsException
    • stream

      @NotNull @NotNull Stream<String> stream()
      Specified by:
      stream in interface Collection<String>
    • slice

      @Contract("_, _ -> new") @NotNull default @NotNull TomlKey slice(int fromIndex, int toIndex)
    • toString

      @NotNull @NotNull String toString()
      Serializes the key represented by this object into a TOML-compatible form, escaping as necessary. Escaping will always be done with basic (double quote) strings, literal (single quote) strings are never chosen.

      Example

      
       TomlKey.literal("lorem ipsum", "dolor", "\"sit amet\"")
            .toString() // "lorem ipsum".dolor."\"sit amet\""
       
      Overrides:
      toString in class Object
    • compareTo

      default int compareTo(@NotNull @NotNull TomlKey o)
      Specified by:
      compareTo in interface Comparable<TomlKey>