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 Minitializes this object from the given JSON String.default <T> TReturns the value to which the specifiedkeyis mapped, or null if this document contains no mapping for the key.default BooleangetBoolean(String key) Returns the value to which the specifiedkeyis mapped, or null if this document contains no mapping for the key.default booleangetBooleanOrDefault(String key, boolean defaultValue) Returns the value to which the specifiedkeyis mapped ordefaultValueif this document contains no mapping for the key.default booleangetBooleanOrDefault(String key, BooleanSupplier defaultValue) Returns the value to which the specifiedkeyis mapped or the value fromdefaultValueif this document contains no mapping for the key.default IntegerReturns the value to which the specifiedkeyis mapped, or null if this document contains no mapping for the key.default intgetIntOrDefault(String key, int defaultValue) Returns the value to which the specifiedkeyis mapped ordefaultValueif this document contains no mapping for the key.default intgetIntOrDefault(String key, IntSupplier defaultValue) Returns the value to which the specifiedkeyis mapped or the value fromdefaultValueif this document contains no mapping for the key.default LongReturns the value to which the specifiedkeyis mapped, or null if this document contains no mapping for the key.default longgetLongOrDefault(String key, long defaultValue) Returns the value to which the specifiedkeyis mapped ordefaultValueif this document contains no mapping for the key.default longgetLongOrDefault(String key, LongSupplier defaultValue) Returns the value to which the specifiedkeyis mapped or the value fromdefaultValueif this document contains no mapping for the key.default StringReturns the value to which the specifiedkeyis mapped, or null if this document contains no mapping for the key.default StringgetStringOrDefault(String key, String defaultValue) Returns the value to which the specifiedkeyis mapped ordefaultValueif this document contains no mapping for the key.default StringgetStringOrDefault(String key, Supplier<String> defaultValue) Returns the value to which the specifiedkeyis mapped or the value fromdefaultValueif this document contains no mapping for the key.toJson()Render thisDocumentto 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:
thisobject.
-
get
Returns the value to which the specifiedkeyis 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 specifiedkeyis 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 specifiedkeyis mapped ordefaultValueif 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
defaultValueif 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 specifiedkeyis mapped or the value fromdefaultValueif 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
defaultValueif 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 specifiedkeyis 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 specifiedkeyis mapped ordefaultValueif 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
defaultValueif 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 specifiedkeyis mapped or the value fromdefaultValueif 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
defaultValueif 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 specifiedkeyis 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 specifiedkeyis mapped ordefaultValueif 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
defaultValueif 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 specifiedkeyis mapped or the value fromdefaultValueif 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
defaultValueif 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 specifiedkeyis 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 specifiedkeyis mapped ordefaultValueif 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
defaultValueif 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 specifiedkeyis mapped or the value fromdefaultValueif 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
defaultValueif 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 thisDocumentto 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
-