Class MutableGsonDocument
java.lang.Object
eu.cloudnetservice.driver.document.gson.ImmutableGsonDocument
eu.cloudnetservice.driver.document.gson.MutableGsonDocument
- All Implemented Interfaces:
Document,Document.Mutable,DefaultedDocPropertyHolder,DefaultedDocPropertyHolder.Mutable<Document.Mutable>,DocPropertyHolder,DocPropertyHolder.Mutable<Document.Mutable>,Serializable
final class MutableGsonDocument
extends ImmutableGsonDocument
implements Document.Mutable, DefaultedDocPropertyHolder.Mutable<Document.Mutable>
Mutable version of a gson document implementing the full mutable document functionality.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
DefaultedDocPropertyHolder.Mutable<S extends DocPropertyHolder.Mutable<S>>Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder.Mutable
DefaultedDocPropertyHolder.Mutable.WithDirectModifier<S extends DocPropertyHolder.Mutable<S>>Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.property.DocPropertyHolder
DocPropertyHolder.Mutable<S extends DocPropertyHolder.Mutable<S>>Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.Document
Document.Mutable -
Field Summary
FieldsFields inherited from class eu.cloudnetservice.driver.document.gson.ImmutableGsonDocument
internalObject -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty gson document instance.MutableGsonDocument(@NonNull com.google.gson.JsonObject internalObject) Constructs a new gson document instance using the given initial internal object. -
Method Summary
Modifier and TypeMethodDescriptionAppends all key-value pairs of the given document into this document.Appends the given document associated with the given key to this document.Appends the given boolean associated with the given key to this document.Appends the given number associated with the given key to this document.Appends the key-value pairs based on the given object into this document associated with the given key.Appends the given string associated with the given key to this document.appendNull(@NonNull String key) Associates a null value with the given key.appendTree(@Nullable Object value) Appends the key-value pairs based on the given object into this document.clear()Removes all key-value pairs from this document.Get the underlying document that all read and write operations are delegated to.private voidReads a json object from the given stream and copies all it's members into this document.receive(@NonNull DocumentSend send) Receives the given document send into this document.Removes the value associated with the given key from this document.private voidWrites this document in a compact way to the given output stream.Methods inherited from class eu.cloudnetservice.driver.document.gson.ImmutableGsonDocument
contains, elementCount, elements, empty, equals, factoryName, getBoolean, getByte, getDouble, getFloat, getInt, getLong, getShort, getString, hashCode, immutableCopy, keys, mutableCopy, readDocument, readMutableDocument, readObject, readObject, readObject, send, serializeToString, toInstanceOf, toInstanceOf, toInstanceOf, toString, writeTo, writeTo, writeTo, writeToMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
propertyAbsent, propertyPresent, readProperty, readPropertyOrDefault, readPropertyOrGet, readPropertyOrThrow, readPropertyOrThrowMethods inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder.Mutable
removeProperty, writeProperty, writePropertyIfAbsent, writePropertyIfAbsent, writePropertyIfPresent, writePropertyIfPresentMethods inherited from interface eu.cloudnetservice.driver.document.Document
contains, elementCount, elements, empty, equals, factoryName, getBoolean, getBoolean, getByte, getByte, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getShort, getShort, getString, getString, immutableCopy, keys, mutableCopy, readDocument, readDocument, readMutableDocument, readMutableDocument, readObject, readObject, readObject, readObject, readObject, readObject, send, serializeToString, serializeToString, toInstanceOf, toInstanceOf, toInstanceOf, toString, writeTo, writeTo, writeTo, writeTo, writeTo, writeTo, writeTo, writeTo
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
MutableGsonDocument
public MutableGsonDocument()Constructs a new, empty gson document instance. -
MutableGsonDocument
Constructs a new gson document instance using the given initial internal object. Note that the given object is not copied, it is up to the caller to ensure no races or data leaks are created when using this constructor.- Parameters:
internalObject- the initial internal json object to use.- Throws:
NullPointerException- if the given internal object is null.
-
-
Method Details
-
clear
Removes all key-value pairs from this document. After this method call this document is empty.- Specified by:
clearin interfaceDocument.Mutable- Returns:
- the same document instance as used to call the method, for chaining.
-
remove
Removes the value associated with the given key from this document. If the key is not associated with any value this method call has no effect.- Specified by:
removein interfaceDocument.Mutable- Parameters:
key- the key to remove from this document.- Returns:
- the same document instance as used to call the method, for chaining.
-
receive
Receives the given document send into this document. All key-value pairs given in the document send will be put into this document, ignoring the fact that a key might already be associated with a value in this document. If the document send contains a data type that is not supported by this document type, the key-value pair gets simply skipped.The receiving process of a document send should never throw an exception unless the given document send contains malformed or invalid data making it impossible to get imported.
- Specified by:
receivein interfaceDocument.Mutable- Parameters:
send- the document send to import into this document.- Returns:
- the same document instance as used to call the method, for chaining.
-
appendNull
Associates a null value with the given key. If this document type does not support null values, this call has no effect.- Specified by:
appendNullin interfaceDocument.Mutable- Parameters:
key- the key to associate with null.- Returns:
- the same document instance as used to call the method, for chaining.
-
appendTree
Appends the key-value pairs based on the given object into this document. Each field of the given object represents a key-value mapping that is directly appended to this document. How the field value is included into this document depends on the type of document. If a field type is not supported by this document type it gets silently ignored. If null or a non-object is passed to this method (for example a primitive) this method call does nothing.Note: passing a generic type to this method will lose all the generic type information.
- Specified by:
appendTreein interfaceDocument.Mutable- Parameters:
value- the value to serialize to a tree and append to this document.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
Appends all key-value pairs of the given document into this document. If a key-value pair with the same key already exists it gets overridden by this method call. If the given document contains a value type that is not supported by this document, the key-value pair is silently ignored. Changes made to this document after this method call will not reflect into the given document and vice-versa.This method should never throw an exception unless the given document contains malformed data.
- Specified by:
appendin interfaceDocument.Mutable- Parameters:
document- the document to import into this document.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
@NonNull public Document.Mutable append(@NonNull @NonNull String key, @Nullable @Nullable Object value) Appends the key-value pairs based on the given object into this document associated with the given key. Each field of the given object represents a key-value mapping. How the field value is included into this document depends on the type of document. If a field type is not supported by this document type it gets silently ignored.Note: passing a generic type to this method will lose all the generic type information.
- Specified by:
appendin interfaceDocument.Mutable- Parameters:
key- the key to associate the given value with.value- the value to serialize to a tree and append to this document associated with the given key.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
@NonNull public Document.Mutable append(@NonNull @NonNull String key, @Nullable @Nullable Number value) Appends the given number associated with the given key to this document. If the passed number instance is null, then null is appended to this document. If this document does not support numbers (or nulls) then this method call has no effect.- Specified by:
appendin interfaceDocument.Mutable- Parameters:
key- the key to associate the given number with.value- the number value to associate with the given key.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
@NonNull public Document.Mutable append(@NonNull @NonNull String key, @Nullable @Nullable Boolean value) Appends the given boolean associated with the given key to this document. If the passed boolean instance is null, then null is appended to this document. If this document does not support booleans (or nulls) then this method call has no effect.- Specified by:
appendin interfaceDocument.Mutable- Parameters:
key- the key to associate the given boolean with.value- the boolean value to associate with the given key.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
@NonNull public Document.Mutable append(@NonNull @NonNull String key, @Nullable @Nullable String value) Appends the given string associated with the given key to this document. If the passed string instance is null, then null is appended to this document. If this document does not support strings (or nulls) then this method call has no effect.- Specified by:
appendin interfaceDocument.Mutable- Parameters:
key- the key to associate the given string with.value- the string value to associate with the given key.- Returns:
- the same document instance as used to call the method, for chaining.
-
append
@NonNull public Document.Mutable append(@NonNull @NonNull String key, @Nullable @Nullable Document value) Appends the given document associated with the given key to this document. If the passed document instance is null, then null is appended to this document. If the given document contains a value type that is not supported by this document then that key-value pair is ignored.This method should never throw an exception unless the given document contains malformed data.
- Specified by:
appendin interfaceDocument.Mutable- Parameters:
key- the key to associate the given document with.value- the document value to associate with the given key.- Returns:
- the same document instance as used to call the method, for chaining.
-
propertyHolder
Get the underlying document that all read and write operations are delegated to.- Specified by:
propertyHolderin interfaceDocPropertyHolder- Specified by:
propertyHolderin interfaceDocPropertyHolder.Mutable<Document.Mutable>- Overrides:
propertyHolderin classImmutableGsonDocument- Returns:
- the underlying document.
-
writeObject
Writes this document in a compact way to the given output stream. This method is part of the java serialisation api.- Parameters:
out- the target stream to write the content of this document to.- Throws:
IOException- if an i/o error occurs while writing the content.DocumentSerialisationException- if an exception occurs serialising the document.
-
readObject
Reads a json object from the given stream and copies all it's members into this document. This method does not take into account whether a key of the deserialized object is already present in this document. This method is part of the java serialisation api.- Parameters:
in- the stream to read the json content from.- Throws:
IOException- if an i/o error occurs while reading the document content.IllegalArgumentException- if the decoded json element from the stream is not a json object.
-