Package com.helger.commons.traits
Interface IGetterByKeyTrait<KEYTYPE>
-
- Type Parameters:
KEYTYPE- The key type. E.g. String etc.
- All Known Subinterfaces:
IAttributeContainer<KEYTYPE,VALUETYPE>,IAttributeContainerAny<KEYTYPE>,IStringMap
- All Known Implementing Classes:
AttributeContainer,AttributeContainerAny,AttributeContainerAnyConcurrent,AttributeContainerConcurrent,StringMap
- 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 IGetterByKeyTrait<KEYTYPE>
A generic convert Object to anything with convenience API.- Author:
- Philip Helger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleancontainsNonNullValue(KEYTYPE aKey)default booleancontainsNullValue(KEYTYPE aKey)default BigDecimalgetAsBigDecimal(KEYTYPE aKey)default BigDecimalgetAsBigDecimal(KEYTYPE aKey, BigDecimal aDefault)default BigIntegergetAsBigInteger(KEYTYPE aKey)default BigIntegergetAsBigInteger(KEYTYPE aKey, BigInteger aDefault)default booleangetAsBoolean(KEYTYPE aKey)default booleangetAsBoolean(KEYTYPE aKey, boolean bDefault)default BooleangetAsBooleanObj(KEYTYPE aKey)default bytegetAsByte(KEYTYPE aKey)default bytegetAsByte(KEYTYPE aKey, byte nDefault)default byte[]getAsByteArray(KEYTYPE aKey)default BytegetAsByteObj(KEYTYPE aKey)default chargetAsChar(KEYTYPE aKey)default chargetAsChar(KEYTYPE aKey, char cDefault)default char[]getAsCharArray(KEYTYPE aKey)default char[]getAsCharArray(KEYTYPE aKey, char[] aDefault)default CharactergetAsCharObj(KEYTYPE aKey)default doublegetAsDouble(KEYTYPE aKey)default doublegetAsDouble(KEYTYPE aKey, double dDefault)default DoublegetAsDoubleObj(KEYTYPE aKey)default floatgetAsFloat(KEYTYPE aKey)default floatgetAsFloat(KEYTYPE aKey, float fDefault)default FloatgetAsFloatObj(KEYTYPE aKey)default intgetAsInt(KEYTYPE aKey)default intgetAsInt(KEYTYPE aKey, int nDefault)default IntegergetAsIntObj(KEYTYPE aKey)default LocalDategetAsLocalDate(KEYTYPE aKey)default LocalDategetAsLocalDate(KEYTYPE aKey, LocalDate aDefault)default LocalDategetAsLocalDate(KEYTYPE aKey, Locale aContentLocale)Get the value as a String, interpreted as aLocalDate.default LocalDateTimegetAsLocalDateTime(KEYTYPE aKey)default LocalDateTimegetAsLocalDateTime(KEYTYPE aKey, LocalDateTime aDefault)default LocalDateTimegetAsLocalDateTime(KEYTYPE aKey, Locale aContentLocale)Get the value as a String, interpreted as aLocalDateTime.default LocalTimegetAsLocalTime(KEYTYPE aKey)default LocalTimegetAsLocalTime(KEYTYPE aKey, LocalTime aDefault)default LocalTimegetAsLocalTime(KEYTYPE aKey, Locale aContentLocale)Get the value as a String, interpreted as aLocalTime.default longgetAsLong(KEYTYPE aKey)default longgetAsLong(KEYTYPE aKey, long nDefault)default LonggetAsLongObj(KEYTYPE aKey)default shortgetAsShort(KEYTYPE aKey)default shortgetAsShort(KEYTYPE aKey, short nDefault)default ShortgetAsShortObj(KEYTYPE aKey)default BlobgetAsSqlBlob(KEYTYPE aKey)default ClobgetAsSqlClob(KEYTYPE aKey)default DategetAsSqlDate(KEYTYPE aKey)default NClobgetAsSqlNClob(KEYTYPE aKey)default RowIdgetAsSqlRowId(KEYTYPE aKey)default TimegetAsSqlTime(KEYTYPE aKey)default TimestampgetAsSqlTimestamp(KEYTYPE aKey)default StringgetAsString(KEYTYPE aKey)default StringgetAsString(KEYTYPE aKey, String sDefault)default ICommonsList<String>getAsStringList(KEYTYPE aKey)Get a list of all attribute values with the same name.default ICommonsList<String>getAsStringList(KEYTYPE aKey, ICommonsList<String> aDefault)Get a list of all attribute values with the same name.default ICommonsOrderedSet<String>getAsStringSet(KEYTYPE aKey)Get a set of all attribute values with the same name.default ICommonsOrderedSet<String>getAsStringSet(KEYTYPE aKey, ICommonsOrderedSet<String> aDefault)Get a set of all attribute values with the same name.default <T> TgetCastedValue(KEYTYPE aKey)Get the contained value casted to the return type.default <T> TgetCastedValue(KEYTYPE aKey, Class<T> aClass)Get the contained value casted to the specified class.default <T> TgetCastedValue(KEYTYPE aKey, T aDefault)Get the contained value casted to the return type.default <T> TgetCastedValue(KEYTYPE aKey, T aDefault, Class<T> aClass)Get the contained value casted to the specified class.default <T> TgetConvertedValue(KEYTYPE aKey, Class<T> aClass)Get the contained value converted using TypeConverter to the passed class.default <T> TgetConvertedValue(KEYTYPE aKey, T aDefault, Class<T> aClass)Get the contained value converted using TypeConverter to the passed class.default <T> TgetSafeCastedValue(KEYTYPE aKey, Class<T> aClass)Get the contained value casted to the specified class, but only if the cast is possible.default <T> TgetSafeCastedValue(KEYTYPE aKey, T aDefault, Class<T> aClass)Get the contained value casted to the specified class, but only if the cast is possible.ObjectgetValue(KEYTYPE aKey)Get the value matching the provided key.default Class<?>getValueClass(KEYTYPE aKey)default booleanhasStringValue(KEYTYPE aKey, String sDesiredValue)Check if a attribute with the given name is present in the request and has the specified value.default booleanhasStringValue(KEYTYPE aKey, String sDesiredValue, boolean bDefault)Check if a attribute with the given name is present in the request and has the specified value.default voidonSafeCastError(KEYTYPE aKey, Class<?> aClass, Object aValue)Implement this method to handle cases ofgetSafeCastedValue(Object, Object, Class)that failed because invalid provided class.
-
-
-
Method Detail
-
getValue
@Nullable Object getValue(@Nullable KEYTYPE aKey)
Get the value matching the provided key.- Parameters:
aKey- The key to query. May benull.- Returns:
- The value matching the key. No
nullconstraints applicable.
-
getValueClass
@Nullable default Class<?> getValueClass(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
- The class of the value or
nullif no value is contained.
-
containsNonNullValue
default boolean containsNonNullValue(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
trueif the value is notnull. Same asgetValue()!=null.
-
containsNullValue
default boolean containsNullValue(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
trueif the value isnull. Same asgetValue()==null.
-
getCastedValue
@Nullable default <T> T getCastedValue(@Nullable KEYTYPE aKey)
Get the contained value casted to the return type.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.- 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(@Nullable KEYTYPE aKey, @Nullable T aDefault)
Get the contained value casted to the return type.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.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
@Nullable default <T> T getCastedValue(@Nullable KEYTYPE aKey, @Nonnull Class<T> aClass)
Get the contained value casted to the specified class.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.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(@Nullable KEYTYPE aKey, @Nullable T aDefault, @Nonnull Class<T> aClass)
Get the contained value casted to the specified class.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.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
@Nullable default <T> T getSafeCastedValue(@Nullable KEYTYPE aKey, @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:
aKey- The key to be accessed. May benull.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- See Also:
getSafeCastedValue(Object, Object, Class)
-
onSafeCastError
default void onSafeCastError(@Nullable KEYTYPE aKey, @Nonnull Class<?> aClass, @Nonnull Object aValue)
Implement this method to handle cases ofgetSafeCastedValue(Object, Object, Class)that failed because invalid provided class."Key '" + aKey + "' is present, but not as a " + aClass + " but as a " + aValue.getClass ()
- Parameters:
aKey- Key that was searchedaClass- 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(@Nullable KEYTYPE aKey, @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:
aKey- The key to be accessed. May benull.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- See Also:
getSafeCastedValue(Object, Class)
-
getConvertedValue
@Nullable default <T> T getConvertedValue(@Nullable KEYTYPE aKey, @Nonnull Class<T> aClass)
Get the contained value converted using TypeConverter to the passed class.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.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(@Nullable KEYTYPE aKey, @Nullable T aDefault, @Nonnull Class<T> aClass)
Get the contained value converted using TypeConverter to the passed class.- Type Parameters:
T- Destination type- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnullor if type conversion fails.aClass- The class to convert to. May not benull.- Returns:
- The object value casted to the passed class. May be
nullif the contained value isnull.
-
getAsString
@Nullable default String getAsString(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,String.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsString
@Nullable default String getAsString(@Nullable KEYTYPE aKey, @Nullable String sDefault)
- Parameters:
aKey- The key to be accessed. May benull.sDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,sDefault, String.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsCharArray
@Nullable default char[] getAsCharArray(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,char [].class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsCharArray
@Nullable default char[] getAsCharArray(@Nullable KEYTYPE aKey, @Nullable char[] aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey, aDefault, char[].class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsBigDecimal
@Nullable default BigDecimal getAsBigDecimal(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,BigDecimal.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsBigDecimal
@Nullable default BigDecimal getAsBigDecimal(@Nullable KEYTYPE aKey, @Nullable BigDecimal aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,aDefault,BigDecimal.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsBigInteger
@Nullable default BigInteger getAsBigInteger(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,BigInteger.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsBigInteger
@Nullable default BigInteger getAsBigInteger(@Nullable KEYTYPE aKey, @Nullable BigInteger aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,aDefault,BigInteger.class)- See Also:
getConvertedValue(Object,Object, Class)
-
getAsLocalDate
@Nullable default LocalDate getAsLocalDate(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,LocalDate.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalDate
@Nullable default LocalDate getAsLocalDate(@Nullable KEYTYPE aKey, @Nullable LocalDate aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,aDefault,LocalDate.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalTime
@Nullable default LocalTime getAsLocalTime(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,LocalTime.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalTime
@Nullable default LocalTime getAsLocalTime(@Nullable KEYTYPE aKey, @Nullable LocalTime aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,aDefault,LocalTime.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalDateTime
@Nullable default LocalDateTime getAsLocalDateTime(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,LocalDateTime.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalDateTime
@Nullable default LocalDateTime getAsLocalDateTime(@Nullable KEYTYPE aKey, @Nullable LocalDateTime aDefault)
- Parameters:
aKey- The key to be accessed. May benull.aDefault- The value to be returned if the retrieved value isnull.- Returns:
getConvertedValue (aKey,aDefault,LocalDateTime.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsByteArray
@Nullable default byte[] getAsByteArray(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,byte[].class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsBooleanObj
@Nullable default Boolean getAsBooleanObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Boolean.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsByteObj
@Nullable default Byte getAsByteObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Byte.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsCharObj
@Nullable default Character getAsCharObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Character.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsDoubleObj
@Nullable default Double getAsDoubleObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Double.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsFloatObj
@Nullable default Float getAsFloatObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Float.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsIntObj
@Nullable default Integer getAsIntObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Integer.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLongObj
@Nullable default Long getAsLongObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Long.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsShortObj
@Nullable default Short getAsShortObj(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Short.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlBlob
@Nullable default Blob getAsSqlBlob(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Blob.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlClob
@Nullable default Clob getAsSqlClob(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Clob.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlDate
@Nullable default Date getAsSqlDate(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Date.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlNClob
@Nullable default NClob getAsSqlNClob(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,NClob.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlRowId
@Nullable default RowId getAsSqlRowId(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,RowId.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlTime
@Nullable default Time getAsSqlTime(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Time.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsSqlTimestamp
@Nullable default Timestamp getAsSqlTimestamp(@Nullable KEYTYPE aKey)
- Parameters:
aKey- The key to be accessed. May benull.- Returns:
getConvertedValue (aKey,null,Timestamp.class)- See Also:
getConvertedValue(Object,Object,Class)
-
getAsLocalDate
@Nullable default LocalDate getAsLocalDate(@Nullable KEYTYPE aKey, @Nonnull Locale aContentLocale)
Get the value as a String, interpreted as aLocalDate.- Parameters:
aKey- The key to check. May benull.aContentLocale- Locale to use for conversion.- Returns:
nullif either the conversion to String or the parsing of the String failed.
-
getAsLocalTime
@Nullable default LocalTime getAsLocalTime(@Nullable KEYTYPE aKey, @Nonnull Locale aContentLocale)
Get the value as a String, interpreted as aLocalTime.- Parameters:
aKey- The key to check. May benull.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(@Nullable KEYTYPE aKey, @Nonnull Locale aContentLocale)
Get the value as a String, interpreted as aLocalDateTime.- Parameters:
aKey- The key to check. May benull.aContentLocale- Locale to use for conversion.- Returns:
nullif either the conversion to String or the parsing of the String failed.
-
getAsStringList
@Nullable default ICommonsList<String> getAsStringList(@Nullable KEYTYPE aKey)
Get a list of all attribute values with the same name.- Parameters:
aKey- The key to check. May benull.- Returns:
nullif no such attribute value exists
-
getAsStringList
@Nullable default ICommonsList<String> getAsStringList(@Nullable KEYTYPE aKey, @Nullable ICommonsList<String> aDefault)
Get a list of all attribute values with the same name.- Parameters:
aKey- The key to check. May benull.aDefault- The default value to be returned, if no such attribute is present.- Returns:
aDefaultif no such attribute value exists
-
getAsStringSet
@Nullable default ICommonsOrderedSet<String> getAsStringSet(@Nullable KEYTYPE aKey)
Get a set of all attribute values with the same name.- Parameters:
aKey- The key to check. May benull.- Returns:
nullif no such attribute value exists
-
getAsStringSet
@Nullable default ICommonsOrderedSet<String> getAsStringSet(@Nullable KEYTYPE aKey, @Nullable ICommonsOrderedSet<String> aDefault)
Get a set of all attribute values with the same name.- Parameters:
aKey- The key to check. May benull.aDefault- The default value to be returned, if no such attribute is present.- Returns:
aDefaultif no such attribute value exists
-
hasStringValue
default boolean hasStringValue(@Nullable KEYTYPE aKey, @Nullable String sDesiredValue)
Check if a attribute with the given name is present in the request and has the specified value.- Parameters:
aKey- The key to check. May benull.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(@Nullable KEYTYPE aKey, @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:
aKey- The key to check. May benull.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.
-
-