public interface Document
Document
is the base structure for storing configuration
parameters and can be seen as a hierarchial key-value store. Parameters can
be retreived using the different typed getAsXXX()
methods listed
here:
get(String)
getAsBoolean(String)
getAsLong(String)
getAsDouble(String)
getAsInt(String)
getAsString(String)
To traverse the document tree, the children(String, BiFunction)
method can be used. It takes a key and a constructor method reference and
returns a stream of constructed children.
Document
instances are typically short-lived objects that are
recreated every time they are used. References to other instances than the
root should therefore not be stored outside the tree.
Modifier and Type | Method and Description |
---|---|
default Stream<Document> |
ancestors()
Returns a
Stream of every ancestor to this Document ,
beginning with the first ancestor (the root) and ending with the parent
of this Document . |
Stream<? extends Document> |
children()
Returns a
Stream of child documents, instantiated using the
default document implementation. |
default <P extends Document,T extends Document> |
children(String key,
BiFunction<P,Map<String,Object>,T> constructor)
Returns the children on the specified key, instantiated using the
specified constructor.
|
Optional<Object> |
get(String key)
Returns the value mapped to the specified key, or an empty
Optional if no value was found. |
com.speedment.common.function.OptionalBoolean |
getAsBoolean(String key)
Returns the
boolean mapped to the specified key, or an empty
OptionalBoolean if no value was found. |
OptionalDouble |
getAsDouble(String key)
Returns the
double mapped to the specified key, or an empty
OptionalDouble if no value was found. |
OptionalInt |
getAsInt(String key)
Returns the
int mapped to the specified key, or an empty
OptionalInt if no value was found. |
OptionalLong |
getAsLong(String key)
Returns the
long mapped to the specified key, or an empty
OptionalLong if no value was found. |
Optional<String> |
getAsString(String key)
Returns the
String mapped to the specified key, or an empty
Optional if no value was found. |
Map<String,Object> |
getData()
Returns the raw data-map used in this
Document . |
Optional<? extends Document> |
getParent()
Returns the parent of this Document or
Optional.empty() if the
Document does not have a parent. |
void |
put(String key,
Object value)
Stores the specified value on the specified key in this document.
|
Optional<? extends Document> getParent()
Optional.empty()
if the
Document does not have a parent.Map<String,Object> getData()
Document
.Optional<Object> get(String key)
Optional
if no value was found.key
- the keyOptional
com.speedment.common.function.OptionalBoolean getAsBoolean(String key) throws ClassCastException
boolean
mapped to the specified key, or an empty
OptionalBoolean
if no value was found. If a value was found but
couldn't be parsed into a boolean
, a ClassCastException
will be thrown.key
- the keyOptionalBoolean
ClassCastException
- if the mapped value was not a Boolean
OptionalLong getAsLong(String key) throws ClassCastException
long
mapped to the specified key, or an empty
OptionalLong
if no value was found. If a value was found but
couldn't be parsed into a long
, a ClassCastException
will be thrown.key
- the keyOptionalLong
ClassCastException
- if the mapped value was not a Long
OptionalDouble getAsDouble(String key) throws ClassCastException
double
mapped to the specified key, or an empty
OptionalDouble
if no value was found. If a value was found but
couldn't be parsed into a double
, a ClassCastException
will be thrown.key
- the keyOptionalDouble
ClassCastException
- if the mapped value was not a Double
OptionalInt getAsInt(String key) throws ClassCastException
int
mapped to the specified key, or an empty
OptionalInt
if no value was found. If a value was found but
couldn't be parsed into a int
, a ClassCastException
will be thrown.key
- the keyOptionalInt
ClassCastException
- if the mapped value was not a Integer
Optional<String> getAsString(String key) throws ClassCastException
String
mapped to the specified key, or an empty
Optional
if no value was found. If a value was found but
couldn't be parsed into a String
, a ClassCastException
will be thrown.key
- the keyOptional
ClassCastException
- if the mapped value was not a String
void put(String key, Object value)
key
- the key to store the value onvalue
- the value to storedefault <P extends Document,T extends Document> Stream<T> children(String key, BiFunction<P,Map<String,Object>,T> constructor)
P
- the parent typeT
- the child typekey
- the keyconstructor
- the child constructor to usechildren()
Stream<? extends Document> children()
Stream
of child documents, instantiated using the
default document implementation. This method will consider every value
that is a List
of Map
instances a child.children(String, BiFunction)
default Stream<Document> ancestors()
Stream
of every ancestor to this Document
,
beginning with the first ancestor (the root) and ending with the parent
of this Document
.
This stream can typically not be short-circuited and operations on it
will therefore have a complexity of O(n)
.
Copyright © 2018 Speedment, Inc.. All rights reserved.