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
  • 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

      ImmutableGsonDocument(@NonNull @NonNull com.google.gson.JsonObject internalObject)
      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

      @NonNull public @NonNull String factoryName()
      Specified by:
      factoryName in interface eu.cloudnetservice.driver.document.Document
    • empty

      public boolean empty()
      Specified by:
      empty in interface eu.cloudnetservice.driver.document.Document
    • elementCount

      public int elementCount()
      Specified by:
      elementCount in interface eu.cloudnetservice.driver.document.Document
    • contains

      public boolean contains(@NonNull @NonNull String key)
      Specified by:
      contains in interface eu.cloudnetservice.driver.document.Document
    • containsNonNull

      public boolean containsNonNull(@NonNull @NonNull String key)
      Specified by:
      containsNonNull in interface eu.cloudnetservice.driver.document.Document
    • send

      @NonNull public @NonNull eu.cloudnetservice.driver.document.send.DocumentSend send()
      Specified by:
      send in interface eu.cloudnetservice.driver.document.Document
    • immutableCopy

      @NonNull public @NonNull eu.cloudnetservice.driver.document.Document immutableCopy()
      Specified by:
      immutableCopy in interface eu.cloudnetservice.driver.document.Document
    • mutableCopy

      @NonNull public eu.cloudnetservice.driver.document.Document.Mutable mutableCopy()
      Specified by:
      mutableCopy in interface eu.cloudnetservice.driver.document.Document
    • keys

      Specified by:
      keys in interface eu.cloudnetservice.driver.document.Document
    • elements

      @NonNull public @Unmodifiable @NonNull Collection<? extends eu.cloudnetservice.driver.document.send.element.Element> elements()
      Specified by:
      elements in interface eu.cloudnetservice.driver.document.Document
    • toInstanceOf

      public <T> @UnknownNullability T toInstanceOf(@NonNull @NonNull Type type)
      Specified by:
      toInstanceOf in interface eu.cloudnetservice.driver.document.Document
    • toInstanceOf

      public <T> @UnknownNullability T toInstanceOf(@NonNull @NonNull Class<T> type)
      Specified by:
      toInstanceOf in interface eu.cloudnetservice.driver.document.Document
    • toInstanceOf

      public <T> @UnknownNullability T toInstanceOf(@NonNull @NonNull io.leangen.geantyref.TypeToken<T> type)
      Specified by:
      toInstanceOf in interface eu.cloudnetservice.driver.document.Document
    • readObject

      public <T> @UnknownNullability T readObject(@NonNull @NonNull String key, @NonNull @NonNull Type type, @Nullable T def)
      Specified by:
      readObject in interface eu.cloudnetservice.driver.document.Document
    • readObject

      public <T> @UnknownNullability T readObject(@NonNull @NonNull String key, @NonNull @NonNull Class<T> type, @Nullable T def)
      Specified by:
      readObject in interface eu.cloudnetservice.driver.document.Document
    • readObject

      public <T> @UnknownNullability T readObject(@NonNull @NonNull String key, @NonNull @NonNull io.leangen.geantyref.TypeToken<T> type, @Nullable T def)
      Specified by:
      readObject in interface eu.cloudnetservice.driver.document.Document
    • readDocument

      public @UnknownNullability eu.cloudnetservice.driver.document.Document readDocument(@NonNull @NonNull String key, @Nullable @Nullable eu.cloudnetservice.driver.document.Document def)
      Specified by:
      readDocument in interface eu.cloudnetservice.driver.document.Document
    • readMutableDocument

      public @UnknownNullability eu.cloudnetservice.driver.document.Document.Mutable readMutableDocument(@NonNull @NonNull String key, @Nullable eu.cloudnetservice.driver.document.Document.Mutable def)
      Specified by:
      readMutableDocument in interface eu.cloudnetservice.driver.document.Document
    • getByte

      public byte getByte(@NonNull @NonNull String key, byte def)
      Specified by:
      getByte in interface eu.cloudnetservice.driver.document.Document
    • getShort

      public short getShort(@NonNull @NonNull String key, short def)
      Specified by:
      getShort in interface eu.cloudnetservice.driver.document.Document
    • getInt

      public int getInt(@NonNull @NonNull String key, int def)
      Specified by:
      getInt in interface eu.cloudnetservice.driver.document.Document
    • getLong

      public long getLong(@NonNull @NonNull String key, long def)
      Specified by:
      getLong in interface eu.cloudnetservice.driver.document.Document
    • getFloat

      public float getFloat(@NonNull @NonNull String key, float def)
      Specified by:
      getFloat in interface eu.cloudnetservice.driver.document.Document
    • getDouble

      public double getDouble(@NonNull @NonNull String key, double def)
      Specified by:
      getDouble in interface eu.cloudnetservice.driver.document.Document
    • getBoolean

      public boolean getBoolean(@NonNull @NonNull String key, boolean def)
      Specified by:
      getBoolean in interface eu.cloudnetservice.driver.document.Document
    • getString

      Specified by:
      getString in interface eu.cloudnetservice.driver.document.Document
    • 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

      @NonNull private @NonNull com.google.gson.JsonElement getElementSafe(@NonNull @NonNull String key)
      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

      public void writeTo(@NonNull @NonNull Path path, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style)
      Specified by:
      writeTo in interface eu.cloudnetservice.driver.document.Document
    • writeTo

      public void writeTo(@NonNull @NonNull OutputStream stream, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style)
      Specified by:
      writeTo in interface eu.cloudnetservice.driver.document.Document
    • writeTo

      public void writeTo(@NonNull @NonNull Appendable appendable, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style)
      Specified by:
      writeTo in interface eu.cloudnetservice.driver.document.Document
    • writeTo

      public void writeTo(@NonNull eu.cloudnetservice.driver.network.buffer.DataBuf.Mutable dataBuf, @NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style)
      Specified by:
      writeTo in interface eu.cloudnetservice.driver.document.Document
    • serializeToString

      @NonNull public @NonNull String serializeToString(@NonNull @NonNull eu.cloudnetservice.driver.document.SerialisationStyle style)
      Specified by:
      serializeToString in interface eu.cloudnetservice.driver.document.Document
    • 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

      @NonNull public @NonNull eu.cloudnetservice.driver.document.Document propertyHolder()
      Specified by:
      propertyHolder in interface eu.cloudnetservice.driver.document.property.DocPropertyHolder
    • equals

      public boolean equals(@Nullable @Nullable Object other)
      Specified by:
      equals in interface eu.cloudnetservice.driver.document.Document
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @NonNull public @NonNull String toString()
      Specified by:
      toString in interface eu.cloudnetservice.driver.document.Document
      Overrides:
      toString in class Object
    • writeExternal

      public void writeExternal(@NonNull @NonNull ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(@NonNull @NonNull ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException