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 Detail

      • 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)
      • 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:
        getConvertedValue(int,Object,Class)
      • 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.