Class EmptyDocumentFactory
java.lang.Object
eu.cloudnetservice.driver.document.empty.EmptyDocumentFactory
- All Implemented Interfaces:
DocumentFactory
A document factory that only returns the singleton empty document instance. The format name of this factory is
empty.- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DocumentFactoryThe singleton document empty document factory instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSealed constructor as there should only be one singleton empty document factory. -
Method Summary
Modifier and TypeMethodDescriptionGet the name of the format that this factory produces documents for.Creates a new, completely empty document of the factory supported document type.newDocument(@NonNull String key, @Nullable Object value) Creates a new, completely empty document and appends the given key-value pair initially to it.newDocument(@Nullable Object wrapped) Creates a new, completely empty document and appends the tree of the given object to the document.parse(byte[] data) Parses a document of the factory supported document type from the given input data.Parses a document of the factory supported document type from the given data buf.parse(@NonNull InputStream stream) Parses a document of the factory supported document type from the given input stream.Parses a document of the factory supported document type from the given reader.Parses a document of the factory supported document type from the given string.Parses a document of the factory supported document type from the file at the given path.receive(@NonNull DocumentSend send) Receives the given document send into a new, completely empty document.
-
Field Details
-
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
Get the name of the format that this factory produces documents for.- Specified by:
formatNamein interfaceDocumentFactory- Returns:
- the name of the format this factory produces documents for.
-
parse
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:
parsein interfaceDocumentFactory- 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 byDocumentFactory.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:
parsein interfaceDocumentFactory- 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:
parsein interfaceDocumentFactory- 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:
parsein interfaceDocumentFactory- 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:
parsein interfaceDocumentFactory- 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:
parsein interfaceDocumentFactory- Parameters:
dataBuf- the data buf to read a string to parse from.- Returns:
- a parsed document from the data in the given buffer.
-
newDocument
Creates a new, completely empty document of the factory supported document type.- Specified by:
newDocumentin interfaceDocumentFactory- Returns:
- a new, completely empty document.
-
newDocument
Creates a new, completely empty document and appends the tree of the given object to the document. SeeDocument.Mutable.appendTree(Object)for more information. If the given initial object is null, this method does the same asDocumentFactory.newDocument().- Specified by:
newDocumentin interfaceDocumentFactory- Parameters:
wrapped- the object to initially append the tree of.- Returns:
- a new document with the tree of the given object appended.
-
newDocument
@NonNull public Document.Mutable newDocument(@NonNull @NonNull String key, @Nullable @Nullable Object value) 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:
newDocumentin interfaceDocumentFactory- 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:
receivein interfaceDocumentFactory- 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.
-