public interface Document extends Map<String,Object>
Map with String keys. All iterators preserve
original insertion order.
Document 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.
| Modifier and Type | Method and Description |
|---|---|
default Document |
append(String key,
Object value)
|
static Document |
create()
Create a new mutable
Document. |
static Document |
from(Map<String,? extends Object> map)
|
default <T> T |
get(Object key,
Class<T> type)
Returns the value to which the specified
key is mapped, or null if this document contains no
mapping for the key. |
default Boolean |
getBoolean(String key)
Returns the value to which the specified
key 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 specified
key is mapped or defaultValue if this document contains no
mapping for the key. |
default boolean |
getBooleanOrDefault(String key,
BooleanSupplier defaultValue)
Returns the value to which the specified
key is mapped or the value from defaultValue if this
document contains no mapping for the key. |
default String |
getId()
Retrieve the identifier associated with this
Document. |
default String |
getIndex() |
default Integer |
getInt(String key)
Returns the value to which the specified
key 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 specified
key is mapped or defaultValue if this document contains no
mapping for the key. |
default int |
getIntOrDefault(String key,
IntSupplier defaultValue)
Returns the value to which the specified
key is mapped or the value from defaultValue if this
document contains no mapping for the key. |
default Long |
getLong(String key)
Returns the value to which the specified
key 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 specified
key is mapped or defaultValue if this document contains no
mapping for the key. |
default long |
getLongOrDefault(String key,
LongSupplier defaultValue)
Returns the value to which the specified
key is mapped or the value from defaultValue if this
document contains no mapping for the key. |
default long |
getPrimaryTerm()
Retrieve the primary_term associated with this
Document. |
default long |
getSeqNo()
Retrieve the seq_no associated with this
Document. |
default String |
getString(String key)
Returns the value to which the specified
key 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 specified
key is mapped or defaultValue if this document contains no
mapping for the key. |
default String |
getStringOrDefault(String key,
Supplier<String> defaultValue)
Returns the value to which the specified
key is mapped or the value from defaultValue if this
document contains no mapping for the key. |
default long |
getVersion()
Retrieve the version associated with this
Document. |
default boolean |
hasId()
Return true if this
Document is associated with an identifier. |
default boolean |
hasPrimaryTerm()
Return true if this
Document is associated with a primary_term. |
default boolean |
hasSeqNo()
Return true if this
Document is associated with a seq_no. |
default boolean |
hasVersion()
Return true if this
Document is associated with a version. |
static Document |
parse(String json)
Parse JSON to
Document. |
default void |
setId(String id)
Set the identifier for this
Document. |
default void |
setIndex(String index)
Sets the index name for this document
|
default void |
setPrimaryTerm(long primaryTerm)
Set the primary_term for this
Document. |
default void |
setSeqNo(long seqNo)
Set the seq_no for this
Document. |
default void |
setVersion(long version)
Set the version for this
Document. |
String |
toJson()
Render this
Document to JSON. |
default <R> R |
transform(Function<? super Document,? extends R> transformer)
This method allows the application of a function to
this Document. |
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesstatic Document from(Map<String,? extends Object> map)
map - source map containing key-value pairs and sub-documents. must not be null.Document.static Document parse(String json)
Document.json - must not be null.Document.default Document append(String key, Object value)
key - key with which the specified value is to be associated. must not be null.value - value to be associated with the specified key.this Document.default boolean hasId()
Document is associated with an identifier.Document is associated with an identifier, false otherwise.@Nullable default String getIndex()
default void setIndex(@Nullable String index)
index - index name
The default implementation throws UnsupportedOperationException.
default String getId()
Document.
The default implementation throws UnsupportedOperationException. It's recommended to check hasId()
prior to calling this method.
Document.IllegalStateException - if the underlying implementation supports Id's but no Id was yet associated with the
document.default void setId(String id)
Document.
The default implementation throws UnsupportedOperationException.
default boolean hasVersion()
Document is associated with a version.Document is associated with a version, false otherwise.default long getVersion()
Document.
The default implementation throws UnsupportedOperationException. It's recommended to check
hasVersion() prior to calling this method.
Document.IllegalStateException - if the underlying implementation supports Id's but no Id was yet associated with the
document.default void setVersion(long version)
Document.
The default implementation throws UnsupportedOperationException.
default boolean hasSeqNo()
Document is associated with a seq_no.Document is associated with a seq_no, false otherwise.default long getSeqNo()
Document.
The default implementation throws UnsupportedOperationException. It's recommended to check
hasSeqNo() prior to calling this method.
Document.IllegalStateException - if the underlying implementation supports seq_no's but no seq_no was yet associated
with the document.default void setSeqNo(long seqNo)
Document.
The default implementation throws UnsupportedOperationException.
default boolean hasPrimaryTerm()
Document is associated with a primary_term.Document is associated with a primary_term, false otherwise.default long getPrimaryTerm()
Document.
The default implementation throws UnsupportedOperationException. It's recommended to check
hasPrimaryTerm() prior to calling this method.
Document.IllegalStateException - if the underlying implementation supports primary_term's but no primary_term was yet
associated with the document.default void setPrimaryTerm(long primaryTerm)
Document.
The default implementation throws UnsupportedOperationException.
@Nullable default <T> T get(Object key, Class<T> type)
key 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 to type, then this method throws
ClassCastException.T - expected return type.key - the key whose associated value is to be returnedtype - the expected return value type.ClassCastException - if the value of the given key is not of type T.@Nullable default Boolean getBoolean(String key)
key is mapped, or null if this document contains no
mapping for the key. If the value type is not a Boolean, then this method throws
ClassCastException.key - the key whose associated value is to be returnedClassCastException - if the value of the given key is not a Boolean.default boolean getBooleanOrDefault(String key, boolean defaultValue)
key is mapped or defaultValue if this document contains no
mapping for the key. If the value type is not a Boolean, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document contains no mapping
for the key.ClassCastException - if the value of the given key is not a Boolean.default boolean getBooleanOrDefault(String key, BooleanSupplier defaultValue)
key is mapped or the value from defaultValue if this
document contains no mapping for the key. If the value type is not a Boolean, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document
contains no mapping for the key.ClassCastException - if the value of the given key is not a Boolean.BooleanSupplier@Nullable default Integer getInt(String key)
key is mapped, or null if this document contains no
mapping for the key. If the value type is not a Integer, then this method throws
ClassCastException.key - the key whose associated value is to be returnedClassCastException - if the value of the given key is not a Integer.default int getIntOrDefault(String key, int defaultValue)
key is mapped or defaultValue if this document contains no
mapping for the key. If the value type is not a Integer, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document contains no mapping
for the key.ClassCastException - if the value of the given key is not a Integer.default int getIntOrDefault(String key, IntSupplier defaultValue)
key is mapped or the value from defaultValue if this
document contains no mapping for the key. If the value type is not a Integer, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document
contains no mapping for the key.ClassCastException - if the value of the given key is not a Integer.IntSupplier@Nullable default Long getLong(String key)
key is mapped, or null if this document contains no
mapping for the key. If the value type is not a Long, then this method throws ClassCastException.key - the key whose associated value is to be returnedClassCastException - if the value of the given key is not a Long.default long getLongOrDefault(String key, long defaultValue)
key is mapped or defaultValue if this document contains no
mapping for the key. If the value type is not a Long, then this method throws ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document contains no mapping
for the key.ClassCastException - if the value of the given key is not a Long.default long getLongOrDefault(String key, LongSupplier defaultValue)
key is mapped or the value from defaultValue if this
document contains no mapping for the key. If the value type is not a Long, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document
contains no mapping for the key.ClassCastException - if the value of the given key is not a Long.LongSupplier@Nullable default String getString(String key)
key is mapped, or null if this document contains no
mapping for the key. If the value type is not a String, then this method throws ClassCastException.key - the key whose associated value is to be returnedClassCastException - if the value of the given key is not a String.default String getStringOrDefault(String key, String defaultValue)
key is mapped or defaultValue if this document contains no
mapping for the key. If the value type is not a String, then this method throws ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document contains no mapping
for the key.ClassCastException - if the value of the given key is not a String.default String getStringOrDefault(String key, Supplier<String> defaultValue)
key is mapped or the value from defaultValue if this
document contains no mapping for the key. If the value type is not a String, then this method throws
ClassCastException.key - the key whose associated value is to be returneddefaultValue if this document
contains no mapping for the key.ClassCastException - if the value of the given key is not a String.Supplierdefault <R> R transform(Function<? super Document,? extends R> transformer)
this Document. The function should expect a
single Document argument and produce an R result.
Any exception thrown by the function will be propagated to the caller.
R - class of the resulttransformer - functional interface to a apply. must not be null.FunctionCopyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.