Interface DefaultValueGetter

All Superinterfaces:
ValueGetter
All Known Implementing Classes:
Property, XmlAttribute, XmlValue
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 DefaultValueGetter extends ValueGetter
A functional interface that provides methods to get a value of a specific type.
This is an extension of the ValueGetter interface.

This interface provides safe methods to get the value as a specific type with a default value.
The default value will be returned if the value could not be parsed to the desired type.
The following methods are provided to get the value as a specific type with a default value:

  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    getAs(@NotNull ThrowableFunction<String,T,? extends Exception> parser, T defaultValue)
    Returns the value which is hold by this object 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.
    If the parser throws an exception, the default value will be returned.
    default boolean
    getAsBoolean(boolean defaultValue)
    Returns the value which is hold by this object as a boolean.
    If the value is not a boolean, the default value will be returned.
    default byte
    getAsByte(byte defaultValue)
    Returns the value which is hold by this object as a byte.
    If the value is not a byte, the default value will be returned.
    default double
    getAsDouble(double defaultValue)
    Returns the value which is hold by this object as a double.
    If the value is not a double, the default value will be returned.
    default float
    getAsFloat(float defaultValue)
    Returns the value which is hold by this object as a float.
    If the value is not a float, the default value will be returned.
    default int
    getAsInteger(int defaultValue)
    Returns the value which is hold by this object as an integer.
    If the value is not an integer, the default value will be returned.
    default long
    getAsLong(long defaultValue)
    Returns the value which is hold by this object as a long.
    If the value is not a long, the default value will be returned.
    default @NotNull Number
    getAsNumber(@NotNull Number defaultValue)
    Returns the value which is hold by this object as a number.
    If the value is not a number, the default value will be returned.
    default short
    getAsShort(short defaultValue)
    Returns the value which is hold by this object as a short.
    If the value is not a short, the default value will be returned.

    Methods inherited from interface net.luis.utils.util.getter.ValueGetter

    getAs, getAsBoolean, getAsByte, getAsDouble, getAsFloat, getAsInteger, getAsLong, getAsNumber, getAsShort, getAsString
  • Method Details

    • getAsBoolean

      default boolean getAsBoolean(boolean defaultValue)
      Returns the value which is hold by this object as a boolean.
      If the value is not a boolean, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a boolean or the default value
    • getAsNumber

      @NotNull default @NotNull Number getAsNumber(@NotNull @NotNull Number defaultValue)
      Returns the value which is hold by this object as a number.
      If the value is not a number, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a number or the default value
      Throws:
      NullPointerException - If the default value is null
    • getAsByte

      default byte getAsByte(byte defaultValue)
      Returns the value which is hold by this object as a byte.
      If the value is not a byte, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a byte or the default value
    • getAsShort

      default short getAsShort(short defaultValue)
      Returns the value which is hold by this object as a short.
      If the value is not a short, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a short or the default value
    • getAsInteger

      default int getAsInteger(int defaultValue)
      Returns the value which is hold by this object as an integer.
      If the value is not an integer, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as an integer or the default value
    • getAsLong

      default long getAsLong(long defaultValue)
      Returns the value which is hold by this object as a long.
      If the value is not a long, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a long or the default value
    • getAsFloat

      default float getAsFloat(float defaultValue)
      Returns the value which is hold by this object as a float.
      If the value is not a float, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a float or the default value
    • getAsDouble

      default double getAsDouble(double defaultValue)
      Returns the value which is hold by this object as a double.
      If the value is not a double, the default value will be returned.
      Parameters:
      defaultValue - The default value
      Returns:
      The value as a double or the default value
    • getAs

      @NotNull default <T> T getAs(@NotNull @NotNull ThrowableFunction<String,T,? extends Exception> parser, @NotNull T defaultValue)
      Returns the value which is hold by this object 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.
      If the parser throws an exception, the default value will be returned.
      Type Parameters:
      T - The type of the parsed value
      Parameters:
      parser - The parser to parse the value
      defaultValue - The default value
      Returns:
      The value as the result of the parser or the default value
      Throws:
      NullPointerException - If the parser or the default value is null