Class StringValueMap<T extends Serializable>
java.lang.Object
ch.tocco.nice2.toolbox.api.collection.StringValueMap<T>
- All Implemented Interfaces:
ReadOnlyMap<T>
,WriteableMap<T>
,Serializable
public class StringValueMap<T extends Serializable>
extends Object
implements WriteableMap<T>, Serializable
Implementation of WriteableMap
that uses strings as values. This class is
not thread safe by default. You may use a synchronized map implementation as
underlying map to make this thread safe.
All getters that return a number may throw NumberFormatException
when parsing
the string value, though this does not happen when only the interface methods are used
to put values in the map.
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionUses aHashMap
as underlying map.StringValueMap
(Map<T, String> values) Uses the specified map as underlying map implementation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(T key) boolean
@Nullable Boolean
getBoolean
(T key) @org.jetbrains.annotations.Nullable boolean
getBoolean
(T key, boolean fallback) <V> @Nullable StringValueMap.Convert
<V> getConverter
(Class<V> clazz) @Nullable Date
@Nullable Date
@Nullable BigDecimal
getDecimal
(T key) @Nullable BigDecimal
getDecimal
(T key, BigDecimal fallback) @Nullable Double
@org.jetbrains.annotations.Nullable double
<S extends Enum<S>>
S<S extends Enum<S>>
S<E extends Enum<E>>
StringValueMap.Convert<E> getEnumConvert
(Class<E> clazz) @Nullable Float
@org.jetbrains.annotations.Nullable float
@Nullable Integer
@org.jetbrains.annotations.Nullable int
@Nullable Long
@org.jetbrains.annotations.Nullable long
@Nullable String
<V> V
<V> V
<V> V
getValueOrFallback
(T key, StringValueMap.Convert<V> convert, V fallback) This is the main getter, which uses a converter to convert the string values to the requested type.Gives direct access to the underlying map.int
hashCode()
protected void
initializeConverter
(Class clazz) Initializes the converter map.keySet()
Returns an immutable view of all keys.<V> void
registerConverter
(Class<V> clazz, StringValueMap.Convert<V> converter) boolean
removeValue
(T key) boolean
setBoolean
(T key, boolean bool) boolean
boolean
setDecimal
(T key, BigDecimal value) boolean
boolean
boolean
boolean
boolean
boolean
boolean
void
Sets the underlying map.toString()
-
Constructor Details
-
StringValueMap
Uses the specified map as underlying map implementation. -
StringValueMap
public StringValueMap()Uses aHashMap
as underlying map.
-
-
Method Details
-
getConverter
-
registerConverter
-
getStringConvert
-
getBooleanConvert
-
getIntConvert
-
getLongConvert
-
getDoubleConvert
-
getFloatConvert
-
getDecimalConvert
-
getEnumConvert
-
getDateConvert
-
removeValue
- Specified by:
removeValue
in interfaceWriteableMap<T extends Serializable>
-
setString
- Specified by:
setString
in interfaceWriteableMap<T extends Serializable>
-
setBoolean
- Specified by:
setBoolean
in interfaceWriteableMap<T extends Serializable>
-
setInt
- Specified by:
setInt
in interfaceWriteableMap<T extends Serializable>
-
setLong
- Specified by:
setLong
in interfaceWriteableMap<T extends Serializable>
-
setDouble
- Specified by:
setDouble
in interfaceWriteableMap<T extends Serializable>
-
setFloat
- Specified by:
setFloat
in interfaceWriteableMap<T extends Serializable>
-
setDecimal
- Specified by:
setDecimal
in interfaceWriteableMap<T extends Serializable>
-
setEnum
- Specified by:
setEnum
in interfaceWriteableMap<T extends Serializable>
-
setDate
- Specified by:
setDate
in interfaceWriteableMap<T extends Serializable>
-
initializeConverter
Initializes the converter map. This is invoked if the first try to find a converter for the sepcified value class failed. Override this to add more converters. -
setValue
- Specified by:
setValue
in interfaceWriteableMap<T extends Serializable>
-
getValue
- Specified by:
getValue
in interfaceReadOnlyMap<T extends Serializable>
-
getValue
- Specified by:
getValue
in interfaceReadOnlyMap<T extends Serializable>
-
getValueOrFallback
@Nullable public <V> V getValueOrFallback(T key, StringValueMap.Convert<V> convert, @Nullable V fallback) This is the main getter, which uses a converter to convert the string values to the requested type.
It will first look up the underlying map for a value associated to the specified key. If this returns
null
, the specified fallback value is returned (which may also benull
). -
getString
- Specified by:
getString
in interfaceReadOnlyMap<T extends Serializable>
-
getString
- Specified by:
getString
in interfaceReadOnlyMap<T extends Serializable>
-
getBoolean
- Specified by:
getBoolean
in interfaceReadOnlyMap<T extends Serializable>
-
getBoolean
- Specified by:
getBoolean
in interfaceReadOnlyMap<T extends Serializable>
-
getInt
- Specified by:
getInt
in interfaceReadOnlyMap<T extends Serializable>
-
getInt
- Specified by:
getInt
in interfaceReadOnlyMap<T extends Serializable>
-
getLong
- Specified by:
getLong
in interfaceReadOnlyMap<T extends Serializable>
-
getLong
- Specified by:
getLong
in interfaceReadOnlyMap<T extends Serializable>
-
getFloat
- Specified by:
getFloat
in interfaceReadOnlyMap<T extends Serializable>
-
getFloat
- Specified by:
getFloat
in interfaceReadOnlyMap<T extends Serializable>
-
getDouble
- Specified by:
getDouble
in interfaceReadOnlyMap<T extends Serializable>
-
getDouble
- Specified by:
getDouble
in interfaceReadOnlyMap<T extends Serializable>
-
getDecimal
- Specified by:
getDecimal
in interfaceReadOnlyMap<T extends Serializable>
-
getDecimal
- Specified by:
getDecimal
in interfaceReadOnlyMap<T extends Serializable>
-
getEnum
- Specified by:
getEnum
in interfaceReadOnlyMap<T extends Serializable>
-
getEnum
- Specified by:
getEnum
in interfaceReadOnlyMap<T extends Serializable>
-
getDate
- Specified by:
getDate
in interfaceReadOnlyMap<T extends Serializable>
-
getDate
- Specified by:
getDate
in interfaceReadOnlyMap<T extends Serializable>
-
keySet
Description copied from interface:ReadOnlyMap
Returns an immutable view of all keys.- Specified by:
keySet
in interfaceReadOnlyMap<T extends Serializable>
-
containsKey
- Specified by:
containsKey
in interfaceReadOnlyMap<T extends Serializable>
-
clear
public void clear()- Specified by:
clear
in interfaceWriteableMap<T extends Serializable>
-
getValues
Gives direct access to the underlying map. -
setValues
Sets the underlying map. -
equals
-
hashCode
public int hashCode() -
toString
-