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
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionUses aHashMapas underlying map.StringValueMap(Map<T, String> values) Uses the specified map as underlying map implementation. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(T key) boolean@Nullable BooleangetBoolean(T key) @org.jetbrains.annotations.Nullable booleangetBoolean(T key, boolean fallback) <V> @Nullable StringValueMap.Convert<V> getConverter(Class<V> clazz) @Nullable Date@Nullable Date@Nullable BigDecimalgetDecimal(T key) @Nullable BigDecimalgetDecimal(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> VgetValueOrFallback(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.inthashCode()protected voidinitializeConverter(Class clazz) Initializes the converter map.keySet()Returns an immutable view of all keys.<V> voidregisterConverter(Class<V> clazz, StringValueMap.Convert<V> converter) booleanremoveValue(T key) booleansetBoolean(T key, boolean bool) booleanbooleansetDecimal(T key, BigDecimal value) booleanbooleanbooleanbooleanbooleanbooleanbooleanvoidSets the underlying map.toString()
-
Constructor Details
-
StringValueMap
Uses the specified map as underlying map implementation. -
StringValueMap
public StringValueMap()Uses aHashMapas underlying map.
-
-
Method Details
-
getConverter
-
registerConverter
-
getStringConvert
-
getBooleanConvert
-
getIntConvert
-
getLongConvert
-
getDoubleConvert
-
getFloatConvert
-
getDecimalConvert
-
getEnumConvert
-
getDateConvert
-
removeValue
- Specified by:
removeValuein interfaceWriteableMap<T extends Serializable>
-
setString
- Specified by:
setStringin interfaceWriteableMap<T extends Serializable>
-
setBoolean
- Specified by:
setBooleanin interfaceWriteableMap<T extends Serializable>
-
setInt
- Specified by:
setIntin interfaceWriteableMap<T extends Serializable>
-
setLong
- Specified by:
setLongin interfaceWriteableMap<T extends Serializable>
-
setDouble
- Specified by:
setDoublein interfaceWriteableMap<T extends Serializable>
-
setFloat
- Specified by:
setFloatin interfaceWriteableMap<T extends Serializable>
-
setDecimal
- Specified by:
setDecimalin interfaceWriteableMap<T extends Serializable>
-
setEnum
- Specified by:
setEnumin interfaceWriteableMap<T extends Serializable>
-
setDate
- Specified by:
setDatein 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:
setValuein interfaceWriteableMap<T extends Serializable>
-
getValue
- Specified by:
getValuein interfaceReadOnlyMap<T extends Serializable>
-
getValue
- Specified by:
getValuein 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:
getStringin interfaceReadOnlyMap<T extends Serializable>
-
getString
- Specified by:
getStringin interfaceReadOnlyMap<T extends Serializable>
-
getBoolean
- Specified by:
getBooleanin interfaceReadOnlyMap<T extends Serializable>
-
getBoolean
- Specified by:
getBooleanin interfaceReadOnlyMap<T extends Serializable>
-
getInt
- Specified by:
getIntin interfaceReadOnlyMap<T extends Serializable>
-
getInt
- Specified by:
getIntin interfaceReadOnlyMap<T extends Serializable>
-
getLong
- Specified by:
getLongin interfaceReadOnlyMap<T extends Serializable>
-
getLong
- Specified by:
getLongin interfaceReadOnlyMap<T extends Serializable>
-
getFloat
- Specified by:
getFloatin interfaceReadOnlyMap<T extends Serializable>
-
getFloat
- Specified by:
getFloatin interfaceReadOnlyMap<T extends Serializable>
-
getDouble
- Specified by:
getDoublein interfaceReadOnlyMap<T extends Serializable>
-
getDouble
- Specified by:
getDoublein interfaceReadOnlyMap<T extends Serializable>
-
getDecimal
- Specified by:
getDecimalin interfaceReadOnlyMap<T extends Serializable>
-
getDecimal
- Specified by:
getDecimalin interfaceReadOnlyMap<T extends Serializable>
-
getEnum
- Specified by:
getEnumin interfaceReadOnlyMap<T extends Serializable>
-
getEnum
- Specified by:
getEnumin interfaceReadOnlyMap<T extends Serializable>
-
getDate
- Specified by:
getDatein interfaceReadOnlyMap<T extends Serializable>
-
getDate
- Specified by:
getDatein interfaceReadOnlyMap<T extends Serializable>
-
keySet
Description copied from interface:ReadOnlyMapReturns an immutable view of all keys.- Specified by:
keySetin interfaceReadOnlyMap<T extends Serializable>
-
containsKey
- Specified by:
containsKeyin interfaceReadOnlyMap<T extends Serializable>
-
clear
public void clear()- Specified by:
clearin interfaceWriteableMap<T extends Serializable>
-
getValues
Gives direct access to the underlying map. -
setValues
Sets the underlying map. -
equals
-
hashCode
public int hashCode() -
toString
-