Class EmptyDocumentFactory

java.lang.Object
eu.cloudnetservice.driver.document.empty.EmptyDocumentFactory
All Implemented Interfaces:
DocumentFactory

public final class EmptyDocumentFactory extends Object implements DocumentFactory
A document factory that only returns the singleton empty document instance. The format name of this factory is empty.
Since:
4.0
  • Field Details

    • INSTANCE

      public static final DocumentFactory INSTANCE
      The singleton document empty document factory instance.
  • Constructor Details

    • EmptyDocumentFactory

      private EmptyDocumentFactory()
      Sealed constructor as there should only be one singleton empty document factory.
  • Method Details

    • formatName

      @NonNull public @NonNull String formatName()
      Get the name of the format that this factory produces documents for.
      Specified by:
      formatName in interface DocumentFactory
      Returns:
      the name of the format this factory produces documents for.
    • parse

      @NonNull public Document.Mutable parse(byte[] data)
      Parses a document of the factory supported document type from the given input data. The given data must be the root object of a document in order to work. If possible it should be preferred to read the data from a stream to prevent large heap allocations.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      data - the data to parse the document from.
      Returns:
      a parsed document from the given input data.
    • parse

      Parses a document of the factory supported document type from the file at the given path. The given data must be the root object of a document in order to work. Note: if the file at the given does not exist or the given path is a directory, this method returns a new, empty document from this factory (as specified by DocumentFactory.newDocument()). However, this method invocation will fail in case the current jvm does not have the appropriate privileges that would allow it open the file for reading.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      path - the path to the file to parse.
      Returns:
      a parsed document from the file at the given path.
    • parse

      Parses a document of the factory supported document type from the given string. The given data must be the root object of a document in order to work. If possible it should be preferred to read the data from a stream to prevent large heap allocations.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      data - the string data to read the document from.
      Returns:
      a parsed document from the given data.
    • parse

      Parses a document of the factory supported document type from the given reader. The given data must be the root object of a document in order to work.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      reader - a reader of the data to read the document from.
      Returns:
      a parsed document from the given data.
    • parse

      Parses a document of the factory supported document type from the given input stream. The given data must be the root object of a document in order to work.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      stream - a stream of the data to read the document from.
      Returns:
      a parsed document from the given data.
    • parse

      Parses a document of the factory supported document type from the given data buf. The given data must be the root object of a document in order to work. This method will read one string from the given buffer and parse that.
      Specified by:
      parse in interface DocumentFactory
      Parameters:
      dataBuf - the data buf to read a string to parse from.
      Returns:
      a parsed document from the data in the given buffer.
    • newDocument

      @NonNull public Document.Mutable newDocument()
      Creates a new, completely empty document of the factory supported document type.
      Specified by:
      newDocument in interface DocumentFactory
      Returns:
      a new, completely empty document.
    • newDocument

      @NonNull public Document.Mutable newDocument(@Nullable @Nullable Object wrapped)
      Creates a new, completely empty document and appends the tree of the given object to the document. See Document.Mutable.appendTree(Object) for more information. If the given initial object is null, this method does the same as DocumentFactory.newDocument().
      Specified by:
      newDocument in interface DocumentFactory
      Parameters:
      wrapped - the object to initially append the tree of.
      Returns:
      a new document with the tree of the given object appended.
    • newDocument

      Creates a new, completely empty document and appends the given key-value pair initially to it. If the given initial value is null then null will be associated with the given key unless null values are not supported by this document type.
      Specified by:
      newDocument in interface DocumentFactory
      Parameters:
      key - the key of the initial mapping.
      value - the value of the initial mapping.
      Returns:
      a new document with the given key-value pair initially appended.
    • receive

      Receives the given document send into a new, completely empty 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:
      receive in interface DocumentFactory
      Parameters:
      send - the document send to import into this document.
      Returns:
      a new, empty document containing all supported key-value pairs of the given document send.