Class ImmutableGsonDocument
java.lang.Object
eu.cloudnetservice.driver.impl.document.gson.ImmutableGsonDocument
- All Implemented Interfaces:
eu.cloudnetservice.driver.document.Document, eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder, eu.cloudnetservice.driver.document.property.DocPropertyHolder, Externalizable, Serializable
- Direct Known Subclasses:
MutableGsonDocument
class ImmutableGsonDocument
extends Object
implements eu.cloudnetservice.driver.document.Document, eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
Immutable version of a gson document implementing the full document functionality.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder.Mutable<S>Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.Document
eu.cloudnetservice.driver.document.Document.Mutable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.gson.JsonObjectprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty gson document instance.ImmutableGsonDocument(@NonNull com.google.gson.JsonObject internalObject) Constructs a new gson document instance using the given initial internal object. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanint@Unmodifiable @NonNull Collection<? extends eu.cloudnetservice.driver.document.send.element.Element> elements()booleanempty()booleanbooleangetBoolean(@NonNull String key, boolean def) bytedoubleprivate @NonNull com.google.gson.JsonElementgetElementSafe(@NonNull String key) Internal helper method to safely read a json element from the underlying json object.floatintlongprivate @Nullable com.google.gson.JsonPrimitiveInternal helper method to get a json element as JsonPrimitive if it is one, else returns null.shortinthashCode()@NonNull eu.cloudnetservice.driver.document.Documentkeys()eu.cloudnetservice.driver.document.Document.Mutable@NonNull eu.cloudnetservice.driver.document.Document@UnknownNullability eu.cloudnetservice.driver.document.DocumentreadDocument(@NonNull String key, @Nullable eu.cloudnetservice.driver.document.Document def) void@UnknownNullability eu.cloudnetservice.driver.document.Document.MutablereadMutableDocument(@NonNull String key, eu.cloudnetservice.driver.document.Document.Mutable def) <T> @UnknownNullability TreadObject(@NonNull String key, @NonNull io.leangen.geantyref.TypeToken<T> type, T def) <T> @UnknownNullability TreadObject(@NonNull String key, @NonNull Class<T> type, T def) <T> @UnknownNullability TreadObject(@NonNull String key, @NonNull Type type, T def) private @NonNull com.google.gson.GsonresolveSerialisationGsonInstance(@NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) Resolves the gson instance to use to serialize this document, throwing an exception if the given serialisation style is not supported.@NonNull eu.cloudnetservice.driver.document.send.DocumentSendsend()serializeToString(@NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) <T> @UnknownNullability TtoInstanceOf(@NonNull io.leangen.geantyref.TypeToken<T> type) <T> @UnknownNullability TtoInstanceOf(@NonNull Class<T> type) <T> @UnknownNullability TtoInstanceOf(@NonNull Type type) toString()voidvoidwriteTo(eu.cloudnetservice.driver.network.buffer.DataBuf.Mutable dataBuf, @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) voidwriteTo(@NonNull OutputStream stream, @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) voidwriteTo(@NonNull Appendable appendable, @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) voidMethods inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
propertyAbsent, propertyPresent, readProperty, readPropertyOrDefault, readPropertyOrGet, readPropertyOrThrow, readPropertyOrThrowMethods inherited from interface eu.cloudnetservice.driver.document.Document
getBoolean, getByte, getDouble, getFloat, getInt, getLong, getShort, getString, readDocument, readMutableDocument, readObject, readObject, readObject, serializeToString, writeTo, writeTo, writeTo, writeTo
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
internalObject
protected final com.google.gson.JsonObject internalObject
-
-
Constructor Details
-
ImmutableGsonDocument
public ImmutableGsonDocument()Constructs a new, empty gson document instance. -
ImmutableGsonDocument
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
-
factoryName
-
empty
public boolean empty()- Specified by:
emptyin interfaceeu.cloudnetservice.driver.document.Document
-
elementCount
public int elementCount()- Specified by:
elementCountin interfaceeu.cloudnetservice.driver.document.Document
-
contains
-
containsNonNull
-
send
-
immutableCopy
-
mutableCopy
- Specified by:
mutableCopyin interfaceeu.cloudnetservice.driver.document.Document
-
keys
- Specified by:
keysin interfaceeu.cloudnetservice.driver.document.Document
-
elements
@NonNull public @Unmodifiable @NonNull Collection<? extends eu.cloudnetservice.driver.document.send.element.Element> elements()- Specified by:
elementsin interfaceeu.cloudnetservice.driver.document.Document
-
toInstanceOf
- Specified by:
toInstanceOfin interfaceeu.cloudnetservice.driver.document.Document
-
toInstanceOf
- Specified by:
toInstanceOfin interfaceeu.cloudnetservice.driver.document.Document
-
toInstanceOf
public <T> @UnknownNullability T toInstanceOf(@NonNull @NonNull io.leangen.geantyref.TypeToken<T> type) - Specified by:
toInstanceOfin interfaceeu.cloudnetservice.driver.document.Document
-
readObject
-
readObject
-
readObject
-
readDocument
-
readMutableDocument
public @UnknownNullability eu.cloudnetservice.driver.document.Document.Mutable readMutableDocument(@NonNull @NonNull String key, @Nullable eu.cloudnetservice.driver.document.Document.Mutable def) - Specified by:
readMutableDocumentin interfaceeu.cloudnetservice.driver.document.Document
-
getByte
-
getShort
-
getInt
-
getLong
-
getFloat
-
getDouble
-
getBoolean
-
getString
-
getPrimitiveElement
@Nullable private @Nullable com.google.gson.JsonPrimitive getPrimitiveElement(@NonNull @NonNull String key) Internal helper method to get a json element as JsonPrimitive if it is one, else returns null. This method is purely to make the code in the methods that return primitive values more readable and should not be used externally.- Parameters:
key- the key of the json primitive to get.- Returns:
- the json primitive instance of the json element associated with the key, null if not a primitive entry.
- Throws:
NullPointerException- if the given key is null.
-
getElementSafe
Internal helper method to safely read a json element from the underlying json object. In comparison to the JsonObject.get(String) method, this method returns the jvm-static JsonNull instance if no element with the given key exists.- Parameters:
key- the key to get the json element of.- Returns:
- the json element associated with the key, or the jvm-static JsonNull instance if no mapping exists.
- Throws:
NullPointerException- if the given key is null.
-
writeTo
-
writeTo
public void writeTo(@NonNull @NonNull OutputStream stream, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) - Specified by:
writeToin interfaceeu.cloudnetservice.driver.document.Document
-
writeTo
public void writeTo(@NonNull @NonNull Appendable appendable, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) - Specified by:
writeToin interfaceeu.cloudnetservice.driver.document.Document
-
writeTo
-
serializeToString
-
resolveSerialisationGsonInstance
@NonNull private @NonNull com.google.gson.Gson resolveSerialisationGsonInstance(@NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style) Resolves the gson instance to use to serialize this document, throwing an exception if the given serialisation style is not supported.- Parameters:
style- the requested serialisation style.- Returns:
- the gson instance to use to serialize this document with the given style.
- Throws:
NullPointerException- if the given style is null.UnsupportedOperationException- if the given style is not supported.
-
propertyHolder
-
equals
-
hashCode
-
toString
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOException
-