Interface KeyedValueGetter

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface KeyedValueGetter
A functional interface that provides methods to get a value of a specific type with a specific key.
The value is hold by the object that implements this interface.

The interface is functional because it has only one abstract method getAsString(String).
All other methods rely on this method to get the value as a string and then parse it to the desired type.
The getAsString(String) method must bei implemented correctly, or the other methods will not work as expected.

The interface provides the following methods to get the value as a specific type:
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    getAs(@NotNull String key, @NotNull ThrowableFunction<String,T,? extends Exception> parser)
    Returns the value which is hold by this object for the given key.
    The value is parsed as the result of the given parser.
    The parser must not be able to handle null values.
    In the case the parser is not able to parse the value, it should not return null, it should throw an exception.
    default boolean
    getAsBoolean(@NotNull String key)
    Returns the value which is hold by this object as a boolean for the given key.
    default byte
    getAsByte(@NotNull String key)
    Returns the value which is hold by this object as a byte for the given key.
    default double
    getAsDouble(@NotNull String key)
    Returns the value which is hold by this object as a double for the given key.
    default float
    getAsFloat(@NotNull String key)
    Returns the value which is hold by this object as a float for the given key.
    default int
    getAsInteger(@NotNull String key)
    Returns the value which is hold by this object as an integer for the given key.
    default long
    getAsLong(@NotNull String key)
    Returns the value which is hold by this object as a long for the given key.
    default @NotNull Number
    getAsNumber(@NotNull String key)
    Returns the value which is hold by this object as a number for the given key.
    default short
    getAsShort(@NotNull String key)
    Returns the value which is hold by this object as a short for the given key.
    @NotNull String
    getAsString(@NotNull String key)
    Returns the value which is hold by this object as a string for the given key.
  • Method Details

    • getAsString

      @NotNull @NotNull String getAsString(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a string for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a string
      Throws:
      NullPointerException - If the key is null
    • getAsBoolean

      default boolean getAsBoolean(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a boolean for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a boolean
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a boolean (e.g. not "true" or "false")
    • getAsNumber

      @NotNull default @NotNull Number getAsNumber(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a number for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a number
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a number
    • getAsByte

      default byte getAsByte(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a byte for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a byte
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a byte
    • getAsShort

      default short getAsShort(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a short for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a short
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a short
    • getAsInteger

      default int getAsInteger(@NotNull @NotNull String key)
      Returns the value which is hold by this object as an integer for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as an integer
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not an integer
    • getAsLong

      default long getAsLong(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a long for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a long
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a long
    • getAsFloat

      default float getAsFloat(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a float for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a float
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a float
    • getAsDouble

      default double getAsDouble(@NotNull @NotNull String key)
      Returns the value which is hold by this object as a double for the given key.
      Parameters:
      key - The key of the value
      Returns:
      The value as a double
      Throws:
      NullPointerException - If the key is null
      IllegalArgumentException - If the value is not a double
    • getAs

      @NotNull default <T> T getAs(@NotNull @NotNull String key, @NotNull @NotNull ThrowableFunction<String,T,? extends Exception> parser)
      Returns the value which is hold by this object for the given key.
      The value is parsed as the result of the given parser.
      The parser must not be able to handle null values.
      In the case the parser is not able to parse the value, it should not return null, it should throw an exception.
      Type Parameters:
      T - The type of the parsed value
      Parameters:
      key - The key of the value
      parser - The parser to parse the value
      Returns:
      The value as the result of the parser
      Throws:
      NullPointerException - If the key or the parser is null
      IndexOutOfBoundsException - If the index is out of bounds
      IllegalArgumentException - If the value could not be parsed