Package com.helger.commons.traits
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.
A generic convert Object to anything with convenience API.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptiondefault BigDecimalgetAsBigDecimal(int nIndex) default BigDecimalgetAsBigDecimal(int nIndex, BigDecimal aDefault) default BigIntegergetAsBigInteger(int nIndex) default BigIntegergetAsBigInteger(int nIndex, BigInteger aDefault) default booleangetAsBoolean(int nIndex) default booleangetAsBoolean(int nIndex, boolean bDefault) default BooleangetAsBooleanObj(int nIndex) default bytegetAsByte(int nIndex) default bytegetAsByte(int nIndex, byte nDefault) default byte[]getAsByteArray(int nIndex) default BytegetAsByteObj(int nIndex) default chargetAsChar(int nIndex) default chargetAsChar(int nIndex, char cDefault) default char[]getAsCharArray(int nIndex) default char[]getAsCharArray(int nIndex, char[] aDefault) default CharactergetAsCharObj(int nIndex) default doublegetAsDouble(int nIndex) default doublegetAsDouble(int nIndex, double dDefault) default DoublegetAsDoubleObj(int nIndex) default floatgetAsFloat(int nIndex) default floatgetAsFloat(int nIndex, float fDefault) default FloatgetAsFloatObj(int nIndex) default intgetAsInt(int nIndex) default intgetAsInt(int nIndex, int nDefault) default IntegergetAsIntObj(int nIndex) default LocalDategetAsLocalDate(int nIndex) default LocalDategetAsLocalDate(int nIndex, LocalDate aDefault) default LocalDategetAsLocalDate(int nIndex, Locale aContentLocale) Get the value as a String, interpreted as aLocalDate.default LocalDateTimegetAsLocalDateTime(int nIndex) default LocalDateTimegetAsLocalDateTime(int nIndex, LocalDateTime aDefault) default LocalDateTimegetAsLocalDateTime(int nIndex, Locale aContentLocale) Get the value as a String, interpreted as aLocalDateTime.default LocalTimegetAsLocalTime(int nIndex) default LocalTimegetAsLocalTime(int nIndex, LocalTime aDefault) default LocalTimegetAsLocalTime(int nIndex, Locale aContentLocale) Get the value as a String, interpreted as aLocalTime.default longgetAsLong(int nIndex) default longgetAsLong(int nIndex, long nDefault) default LonggetAsLongObj(int nIndex) default shortgetAsShort(int nIndex) default shortgetAsShort(int nIndex, short nDefault) default ShortgetAsShortObj(int nIndex) default BlobgetAsSqlBlob(int nIndex) default ClobgetAsSqlClob(int nIndex) default DategetAsSqlDate(int nIndex) default NClobgetAsSqlNClob(int nIndex) default RowIdgetAsSqlRowId(int nIndex) default TimegetAsSqlTime(int nIndex) default TimestampgetAsSqlTimestamp(int nIndex) default StringgetAsString(int nIndex) default StringgetAsString(int nIndex, String sDefault) default ICommonsList<String> getAsStringList(int nIndex) Get a list of all attribute values with the same name.default ICommonsList<String> getAsStringList(int nIndex, ICommonsList<String> aDefault) Get a list of all attribute values with the same name.default ICommonsOrderedSet<String> getAsStringSet(int nIndex) Get a set of all attribute values with the same name.default ICommonsOrderedSet<String> getAsStringSet(int nIndex, ICommonsOrderedSet<String> aDefault) Get a set of all attribute values with the same name.default <T> TgetCastedValue(int nIndex) Get the contained value casted to the return type.default <T> TgetCastedValue(int nIndex, Class<T> aClass) Get the contained value casted to the specified class.default <T> TgetCastedValue(int nIndex, T aDefault) Get the contained value casted to the return type.default <T> TgetCastedValue(int nIndex, T aDefault, Class<T> aClass) Get the contained value casted to the specified class.default <T> TgetConvertedValue(int nIndex, Class<T> aClass) Get the contained value converted using TypeConverter to the passed class.default <T> TgetConvertedValue(int nIndex, T aDefault, Class<T> aClass) Get the contained value converted using TypeConverter to the passed class.default <T> TgetSafeCastedValue(int nIndex, Class<T> aClass) Get the contained value casted to the specified class, but only if the cast is possible.default <T> TgetSafeCastedValue(int nIndex, T aDefault, Class<T> aClass) Get the contained value casted to the specified class, but only if the cast is possible.getValue(int nIndex) Get the value at the specified index.default Class<?> getValueClass(int nIndex) default booleanhasNoValue(int nIndex) default booleanhasStringValue(int nIndex, String sDesiredValue) Check if a attribute with the given name is present in the request and has the specified value.default booleanhasStringValue(int nIndex, String sDesiredValue, boolean bDefault) Check if a attribute with the given name is present in the request and has the specified value.default booleanhasValue(int nIndex) default voidonSafeCastError(int nIndex, Class<?> aClass, Object aValue) Implement this method to handle cases ofgetSafeCastedValue(int, Object, Class)that failed because invalid provided class.
-
Method Details
-
getValue
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
nullconstraints applicable.
-
getValueClass
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
- The class of the value or
nullif no value is contained.
-
hasValue
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
trueif the value is notnull. Same asgetValue()!=null.
-
hasNoValue
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
trueif the value isnull. Same asgetValue()==null.
-
getCastedValue
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
nullif the contained value isnull. - Throws:
ClassCastException- in case the value types are not convertible
-
getCastedValue
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 isnull.- Returns:
- The object value casted to the passed class. May be
nullif the contained value isnull. - Throws:
ClassCastException- in case the value types are not convertible
-
getCastedValue
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
nullif the contained value isnull. - 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 isnull.aClass- The class to cast to.- Returns:
- The object value casted to the passed class. May be
nullif the contained value isnull. - Throws:
ClassCastException- in case the value types are not convertible
-
getSafeCastedValue
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
nullif the contained value isnull. - 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 ofgetSafeCastedValue(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 desiredaValue- 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 isnull.aClass- The class to cast to.- Returns:
- The object value casted to the passed class. May be
nullif the contained value isnull. - Throws:
ClassCastException- in case the value types are not convertible
-
getConvertedValue
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
nullif the contained value isnull. - 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 isnullor if type conversion fails.aClass- The class to convert to.- Returns:
- The object value casted to the passed class. May be
nullif the contained value isnull. - Throws:
TypeConverterException- in case of an error
-
getAsBoolean
-
getAsBoolean
-
getAsByte
-
getAsByte
-
getAsChar
-
getAsChar
-
getAsDouble
-
getAsDouble
-
getAsFloat
-
getAsFloat
-
getAsInt
-
getAsInt
-
getAsLong
-
getAsLong
-
getAsShort
-
getAsShort
-
getAsString
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,String.class)- See Also:
-
getAsString
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.sDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (nIndex,sDefault, String.class)- See Also:
-
getAsCharArray
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,char[].class)- See Also:
-
getAsCharArray
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (nIndex,aDefault, char[].class)- See Also:
-
getAsBigDecimal
- 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 isnull.- Returns:
getConvertedValue (nIndex,aDefault,BigDecimal.class)- See Also:
-
getAsBigInteger
- 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 isnull.- Returns:
getConvertedValue (nIndex,aDefault,BigInteger.class)- See Also:
-
getAsLocalDate
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,LocalDate.class)- See Also:
-
getAsLocalDate
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (nIndex,aDefault,LocalDate.class)- See Also:
-
getAsLocalTime
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,LocalTime.class)- See Also:
-
getAsLocalTime
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (nIndex,aDefault,LocalTime.class)- See Also:
-
getAsLocalDateTime
- 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 isnull.- Returns:
getConvertedValue (nIndex,aDefault,LocalDateTime.class)- See Also:
-
getAsByteArray
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,byte[].class)- See Also:
-
getAsBooleanObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Boolean.class)- See Also:
-
getAsByteObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Byte.class)- See Also:
-
getAsCharObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Character.class)- See Also:
-
getAsDoubleObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Double.class)- See Also:
-
getAsFloatObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Float.class)- See Also:
-
getAsIntObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Integer.class)- See Also:
-
getAsLongObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Long.class)- See Also:
-
getAsShortObj
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Short.class)- See Also:
-
getAsSqlBlob
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Blob.class)- See Also:
-
getAsSqlClob
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Clob.class)- See Also:
-
getAsSqlDate
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Date.class)- See Also:
-
getAsSqlNClob
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,NClob.class)- See Also:
-
getAsSqlRowId
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,RowId.class)- See Also:
-
getAsSqlTime
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Time.class)- See Also:
-
getAsSqlTimestamp
- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
getConvertedValue (nIndex,null,Timestamp.class)- See Also:
-
getAsLocalDate
Get the value as a String, interpreted as aLocalDate.- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aContentLocale- Locale to use for conversion.- Returns:
nullif either the conversion to String or the parsing of the String failed.
-
getAsLocalTime
Get the value as a String, interpreted as aLocalTime.- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aContentLocale- Locale to use for conversion.- Returns:
nullif 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 aLocalDateTime.- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.aContentLocale- Locale to use for conversion.- Returns:
nullif either the conversion to String or the parsing of the String failed.
-
getAsStringList
Get a list of all attribute values with the same name.- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
nullif 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:
aDefaultif no such attribute value exists
-
getAsStringSet
Get a set of all attribute values with the same name.- Parameters:
nIndex- The index to be accessed. Should be ≥ 0.- Returns:
nullif 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:
aDefaultif no such attribute value exists
-
hasStringValue
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:
trueif 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 matchedbDefault- the default value to be returned, if the specified attribute is not present- Returns:
trueif an attribute with the given name is present and has the desired value,falseif the attribute is present but has a different value. If the attribute is not present, the default value is returned.
-