Interface StringObjectMap<M extends StringObjectMap<M>>
- Type Parameters:
M
- the type extending this interface
- All Known Subinterfaces:
Document
,SearchDocument
- All Known Implementing Classes:
DefaultStringObjectMap
,EntityAsMap
,SearchDocumentAdapter
,Settings
Defines an interface for a Map<String, Object> with additional convenience methods. All iterators must preserve
original insertion order.
StringObjectMap does not allow null
keys. It allows null values.
Implementing classes can bei either mutable or immutable. In case a subclass is immutable, its methods may throw
UnsupportedOperationException
when calling modifying methods. *
- Since:
- 4.2
- Author:
- Peter-Josef Meisch
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault M
initializes this object from the given JSON String.default <T> T
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key.default Boolean
getBoolean
(String key) Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key.default boolean
getBooleanOrDefault
(String key, boolean defaultValue) Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key.default boolean
getBooleanOrDefault
(String key, BooleanSupplier defaultValue) Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key.default Integer
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key.default int
getIntOrDefault
(String key, int defaultValue) Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key.default int
getIntOrDefault
(String key, IntSupplier defaultValue) Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key.default Long
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key.default long
getLongOrDefault
(String key, long defaultValue) Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key.default long
getLongOrDefault
(String key, LongSupplier defaultValue) Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key.default String
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key.default String
getStringOrDefault
(String key, String defaultValue) Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key.default String
getStringOrDefault
(String key, Supplier<String> defaultValue) Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key.toJson()
Render thisDocument
to JSON.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
append
- Parameters:
key
- key with which the specified value is to be associated. must not be null.value
- value to be associated with the specified key.- Returns:
this
object.
-
get
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key. The value is casted within the method which makes it useful for calling code as it does not require casting on the calling side. If the value type is not assignable totype
, then this method throwsClassCastException
.- Type Parameters:
T
- expected return type.- Parameters:
key
- the key whose associated value is to be returnedtype
- the expected return value type.- Returns:
- the value to which the specified key is mapped, or null if this document contains no mapping for the key.
- Throws:
ClassCastException
- if the value of the given key is not oftype T
.
-
getBoolean
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key. If the value type is not aBoolean
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or null if this document contains no mapping for the key.
- Throws:
ClassCastException
- if the value of the given key is not aBoolean
.
-
getBooleanOrDefault
Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key. If the value type is not aBoolean
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aBoolean
.
-
getBooleanOrDefault
Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key. If the value type is not aBoolean
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or the value from
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aBoolean
.- See Also:
-
getInt
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key. If the value type is not aInteger
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or null if this document contains no mapping for the key.
- Throws:
ClassCastException
- if the value of the given key is not aInteger
.
-
getIntOrDefault
Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key. If the value type is not aInteger
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aInteger
.
-
getIntOrDefault
Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key. If the value type is not aInteger
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or the value from
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aInteger
.- See Also:
-
getLong
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key. If the value type is not aLong
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or null if this document contains no mapping for the key.
- Throws:
ClassCastException
- if the value of the given key is not aLong
.
-
getLongOrDefault
Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key. If the value type is not aLong
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aLong
.
-
getLongOrDefault
Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key. If the value type is not aLong
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or the value from
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aLong
.- See Also:
-
getString
Returns the value to which the specifiedkey
is mapped, or null if this document contains no mapping for the key. If the value type is not aString
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or null if this document contains no mapping for the key.
- Throws:
ClassCastException
- if the value of the given key is not aString
.
-
getStringOrDefault
Returns the value to which the specifiedkey
is mapped ordefaultValue
if this document contains no mapping for the key. If the value type is not aString
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aString
.
-
getStringOrDefault
Returns the value to which the specifiedkey
is mapped or the value fromdefaultValue
if this document contains no mapping for the key. If the value type is not aString
, then this method throwsClassCastException
.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped or the value from
defaultValue
if this document contains no mapping for the key. - Throws:
ClassCastException
- if the value of the given key is not aString
.- See Also:
-
toJson
String toJson()Render thisDocument
to JSON. Auxiliary values such as Id and version are not considered within the JSON representation.- Returns:
- a JSON representation of this document.
-
fromJson
initializes this object from the given JSON String.- Parameters:
json
- must not be null
-