Interface IGetterByIndexTrait

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 IGetterByIndexTrait
A generic convert Object to anything with convenience API.
Author:
Philip Helger
  • Method Details

    • getValue

      @Nullable Object getValue(@Nonnegative int nIndex)
      Get the value at the specified index.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      The value at the specified index. No null constraints applicable.
    • getValueClass

      @Nullable default Class<?> getValueClass(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      The class of the value or null if no value is contained.
    • hasValue

      default boolean hasValue(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      true if the value is not null. Same as getValue()!=null.
    • hasNoValue

      default boolean hasNoValue(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      true if the value is null. Same as getValue()==null.
    • getCastedValue

      @Nullable default <T> T getCastedValue(@Nonnegative int nIndex)
      Get the contained value casted to the return type.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • getCastedValue

      @Nullable default <T> T getCastedValue(@Nonnegative int nIndex, @Nullable T aDefault)
      Get the contained value casted to the return type.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • getCastedValue

      @Nullable default <T> T getCastedValue(@Nonnegative int nIndex, @Nonnull Class<T> aClass)
      Get the contained value casted to the specified class.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aClass - The class to cast to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • getCastedValue

      @Nullable default <T> T getCastedValue(@Nonnegative int nIndex, @Nullable T aDefault, @Nonnull Class<T> aClass)
      Get the contained value casted to the specified class.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      aClass - The class to cast to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • getSafeCastedValue

      @Nullable default <T> T getSafeCastedValue(@Nonnegative int nIndex, @Nonnull Class<T> aClass)
      Get the contained value casted to the specified class, but only if the cast is possible.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aClass - The class to cast to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • onSafeCastError

      default void onSafeCastError(@Nonnegative int nIndex, @Nonnull Class<?> aClass, @Nonnull Object aValue)
      Implement this method to handle cases of getSafeCastedValue(int, Object, Class) that failed because invalid provided class.
       "Index '" + nIndex + "' is present, but not as a " + aClass + " but as a " + aValue.getClass ()
       
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aClass - The class that was desired
      aValue - The value that was retrieved and cannot be casted to the class
      Since:
      9.0.1
    • getSafeCastedValue

      @Nullable default <T> T getSafeCastedValue(@Nonnegative int nIndex, @Nullable T aDefault, @Nonnull Class<T> aClass)
      Get the contained value casted to the specified class, but only if the cast is possible.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      aClass - The class to cast to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      ClassCastException - in case the value types are not convertible
    • getConvertedValue

      @Nullable default <T> T getConvertedValue(@Nonnegative int nIndex, @Nonnull Class<T> aClass)
      Get the contained value converted using TypeConverter to the passed class.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aClass - The class to convert to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      TypeConverterException - in case of an error
    • getConvertedValue

      @Nullable default <T> T getConvertedValue(@Nonnegative int nIndex, @Nullable T aDefault, @Nonnull Class<T> aClass)
      Get the contained value converted using TypeConverter to the passed class.
      Type Parameters:
      T - Destination type
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null or if type conversion fails.
      aClass - The class to convert to.
      Returns:
      The object value casted to the passed class. May be null if the contained value is null.
      Throws:
      TypeConverterException - in case of an error
    • getAsBoolean

      default boolean getAsBoolean(@Nonnegative int nIndex)
    • getAsBoolean

      default boolean getAsBoolean(@Nonnegative int nIndex, boolean bDefault)
    • getAsByte

      default byte getAsByte(@Nonnegative int nIndex)
    • getAsByte

      default byte getAsByte(@Nonnegative int nIndex, byte nDefault)
    • getAsChar

      default char getAsChar(@Nonnegative int nIndex)
    • getAsChar

      default char getAsChar(@Nonnegative int nIndex, char cDefault)
    • getAsDouble

      default double getAsDouble(@Nonnegative int nIndex)
    • getAsDouble

      default double getAsDouble(@Nonnegative int nIndex, double dDefault)
    • getAsFloat

      default float getAsFloat(@Nonnegative int nIndex)
    • getAsFloat

      default float getAsFloat(@Nonnegative int nIndex, float fDefault)
    • getAsInt

      default int getAsInt(@Nonnegative int nIndex)
    • getAsInt

      default int getAsInt(@Nonnegative int nIndex, int nDefault)
    • getAsLong

      default long getAsLong(@Nonnegative int nIndex)
    • getAsLong

      default long getAsLong(@Nonnegative int nIndex, long nDefault)
    • getAsShort

      default short getAsShort(@Nonnegative int nIndex)
    • getAsShort

      default short getAsShort(@Nonnegative int nIndex, short nDefault)
    • getAsString

      @Nullable default String getAsString(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,String.class)
      See Also:
    • getAsString

      @Nullable default String getAsString(@Nonnegative int nIndex, @Nullable String sDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      sDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,sDefault, String.class)
      See Also:
    • getAsCharArray

      @Nullable default char[] getAsCharArray(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,char[].class)
      See Also:
    • getAsCharArray

      @Nullable default char[] getAsCharArray(@Nonnegative int nIndex, @Nullable char[] aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault, char[].class)
      See Also:
    • getAsBigDecimal

      @Nullable default BigDecimal getAsBigDecimal(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,BigDecimal.class)
      See Also:
    • getAsBigDecimal

      @Nullable default BigDecimal getAsBigDecimal(@Nonnegative int nIndex, @Nullable BigDecimal aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault,BigDecimal.class)
      See Also:
    • getAsBigInteger

      @Nullable default BigInteger getAsBigInteger(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,BigInteger.class)
      See Also:
    • getAsBigInteger

      @Nullable default BigInteger getAsBigInteger(@Nonnegative int nIndex, @Nullable BigInteger aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault,BigInteger.class)
      See Also:
    • getAsLocalDate

      @Nullable default LocalDate getAsLocalDate(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,LocalDate.class)
      See Also:
    • getAsLocalDate

      @Nullable default LocalDate getAsLocalDate(@Nonnegative int nIndex, @Nullable LocalDate aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault,LocalDate.class)
      See Also:
    • getAsLocalTime

      @Nullable default LocalTime getAsLocalTime(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,LocalTime.class)
      See Also:
    • getAsLocalTime

      @Nullable default LocalTime getAsLocalTime(@Nonnegative int nIndex, @Nullable LocalTime aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault,LocalTime.class)
      See Also:
    • getAsLocalDateTime

      @Nullable default LocalDateTime getAsLocalDateTime(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,LocalDateTime.class)
      See Also:
    • getAsLocalDateTime

      @Nullable default LocalDateTime getAsLocalDateTime(@Nonnegative int nIndex, @Nullable LocalDateTime aDefault)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The value to be returned if the retrieved value is null .
      Returns:
      getConvertedValue (nIndex,aDefault,LocalDateTime.class)
      See Also:
    • getAsByteArray

      @Nullable default byte[] getAsByteArray(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,byte[].class)
      See Also:
    • getAsBooleanObj

      @Nullable default Boolean getAsBooleanObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Boolean.class)
      See Also:
    • getAsByteObj

      @Nullable default Byte getAsByteObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Byte.class)
      See Also:
    • getAsCharObj

      @Nullable default Character getAsCharObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Character.class)
      See Also:
    • getAsDoubleObj

      @Nullable default Double getAsDoubleObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Double.class)
      See Also:
    • getAsFloatObj

      @Nullable default Float getAsFloatObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Float.class)
      See Also:
    • getAsIntObj

      @Nullable default Integer getAsIntObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Integer.class)
      See Also:
    • getAsLongObj

      @Nullable default Long getAsLongObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Long.class)
      See Also:
    • getAsShortObj

      @Nullable default Short getAsShortObj(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Short.class)
      See Also:
    • getAsSqlBlob

      @Nullable default Blob getAsSqlBlob(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Blob.class)
      See Also:
    • getAsSqlClob

      @Nullable default Clob getAsSqlClob(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Clob.class)
      See Also:
    • getAsSqlDate

      @Nullable default Date getAsSqlDate(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Date.class)
      See Also:
    • getAsSqlNClob

      @Nullable default NClob getAsSqlNClob(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,NClob.class)
      See Also:
    • getAsSqlRowId

      @Nullable default RowId getAsSqlRowId(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,RowId.class)
      See Also:
    • getAsSqlTime

      @Nullable default Time getAsSqlTime(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Time.class)
      See Also:
    • getAsSqlTimestamp

      @Nullable default Timestamp getAsSqlTimestamp(@Nonnegative int nIndex)
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      getConvertedValue (nIndex,null,Timestamp.class)
      See Also:
    • getAsLocalDate

      @Nullable default LocalDate getAsLocalDate(@Nonnegative int nIndex, @Nonnull Locale aContentLocale)
      Get the value as a String, interpreted as a LocalDate.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aContentLocale - Locale to use for conversion.
      Returns:
      null if either the conversion to String or the parsing of the String failed.
    • getAsLocalTime

      @Nullable default LocalTime getAsLocalTime(@Nonnegative int nIndex, @Nonnull Locale aContentLocale)
      Get the value as a String, interpreted as a LocalTime.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aContentLocale - Locale to use for conversion.
      Returns:
      null if either the conversion to String or the parsing of the String failed.
    • getAsLocalDateTime

      @Nullable default LocalDateTime getAsLocalDateTime(@Nonnegative int nIndex, @Nonnull Locale aContentLocale)
      Get the value as a String, interpreted as a LocalDateTime.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aContentLocale - Locale to use for conversion.
      Returns:
      null if either the conversion to String or the parsing of the String failed.
    • getAsStringList

      @Nullable default ICommonsList<String> getAsStringList(@Nonnegative int nIndex)
      Get a list of all attribute values with the same name.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      null if no such attribute value exists
    • getAsStringList

      @Nullable default ICommonsList<String> getAsStringList(@Nonnegative int nIndex, @Nullable ICommonsList<String> aDefault)
      Get a list of all attribute values with the same name.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The default value to be returned, if no such attribute is present.
      Returns:
      aDefault if no such attribute value exists
    • getAsStringSet

      @Nullable default ICommonsOrderedSet<String> getAsStringSet(@Nonnegative int nIndex)
      Get a set of all attribute values with the same name.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      Returns:
      null if no such attribute value exists
    • getAsStringSet

      @Nullable default ICommonsOrderedSet<String> getAsStringSet(@Nonnegative int nIndex, @Nullable ICommonsOrderedSet<String> aDefault)
      Get a set of all attribute values with the same name.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      aDefault - The default value to be returned, if no such attribute is present.
      Returns:
      aDefault if no such attribute value exists
    • hasStringValue

      default boolean hasStringValue(@Nonnegative int nIndex, @Nullable String sDesiredValue)
      Check if a attribute with the given name is present in the request and has the specified value.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      sDesiredValue - The value to be matched
      Returns:
      true if an attribute with the given name is present and has the desired value
    • hasStringValue

      default boolean hasStringValue(@Nonnegative int nIndex, @Nullable String sDesiredValue, boolean bDefault)
      Check if a attribute with the given name is present in the request and has the specified value. If no such attribute is present, the passed default value is returned.
      Parameters:
      nIndex - The index to be accessed. Should be ≥ 0.
      sDesiredValue - The value to be matched
      bDefault - the default value to be returned, if the specified attribute is not present
      Returns:
      true if an attribute with the given name is present and has the desired value, false if the attribute is present but has a different value. If the attribute is not present, the default value is returned.