public final class DocumentUtil extends Object
Document
interface.Modifier and Type | Class and Description |
---|---|
static class |
DocumentUtil.Name
An enumeration of the types of names that documents can have.
|
Modifier and Type | Method and Description |
---|---|
static <E extends Document> |
ancestor(Document document,
Class<E> clazz)
Returns the first ancestor found of the specified type to the specified
document when walking up the tree.
|
static List<Map<String,Object>> |
castToDocumentList(Object obj)
Casts the specified object to a
List<Map<String, Object>> . |
static <E extends Document> |
childrenOf(Document document,
BiFunction<Document,Map<String,Object>,E> childConstructor)
Returns a stream of child documents to a specified document by using the
supplied constructor.
|
static <P extends Document,DOC extends Document & HasParent<P>> |
deepCopy(DOC document,
BiFunction<P,Map<String,Object>,DOC> constructor)
Creates a deep copy of the raw map in the specified document and wrap it
in a new typed document using the specified constructor.
|
static <DOC extends Document> |
deepCopy(DOC document,
Function<Map<String,Object>,DOC> constructor)
Creates a deep copy of the raw map in the specified document and wrap it
in a new typed document using the specified constructor.
|
static Map<String,Object> |
newDocument(Document parent,
String key)
Creates and returns a new raw map on a specified key in the specified
document.
|
static Supplier<NoSuchElementException> |
newNoSuchElementExceptionFor(Document document,
String key)
Returns an
Exception supplier for when no attribute could be
found on a specified key in a specified document. |
static <T extends Document & HasName,D extends Document & HasName> |
relativeName(D document,
Class<T> from,
DocumentUtil.Name name)
Returns the relative name for the given Document up to the point given by
the parent Class.
|
static <T extends Document & HasName,D extends Document & HasName> |
relativeName(D document,
Class<T> from,
DocumentUtil.Name name,
CharSequence separator,
Function<String,String> nameMapper)
Returns the relative name for the given Document up to the point given by
the parent Class by successively applying the provided nameMapper onto
the Node names and separating the names with the provided separator.
|
static <T extends Document & HasName,D extends Document & HasName> |
relativeName(D document,
Class<T> from,
DocumentUtil.Name name,
Function<String,String> nameMapper)
Returns the relative name for the given Document up to the point given by
the parent Class by successively applying the provided nameMapper onto
the Node names.
|
static String |
toStringHelper(Document document)
Helps documents to format a
toString() -method. |
static Stream<? extends Document> |
traverseOver(Document document)
Traverses all the documents at and below the specified document in a
tree.
|
public static Stream<? extends Document> traverseOver(Document document)
document
- the document to start atpublic static <E extends Document> Optional<E> ancestor(Document document, Class<E> clazz)
Optional
is
returned.E
- ancestor typedocument
- the starting pointclazz
- the ancestor type to look forpublic static <E extends Document> Stream<E> childrenOf(Document document, BiFunction<Document,Map<String,Object>,E> childConstructor)
E
- the expected child typedocument
- the parent documentchildConstructor
- child constructorpublic static Map<String,Object> newDocument(Document parent, String key)
parent
- the parent to create it inkey
- the key to create it underpublic static <T extends Document & HasName,D extends Document & HasName> String relativeName(D document, Class<T> from, DocumentUtil.Name name)
For example, relativeName(column, Dbms.class, DATABASE_NAME)
would return the String "dbms_name.schema_name.table_name.column_name".
T
- parent typeD
- document typedocument
- to usefrom
- the document type to get the name fromname
- if java or database name should be usedpublic static <T extends Document & HasName,D extends Document & HasName> String relativeName(D document, Class<T> from, DocumentUtil.Name name, Function<String,String> nameMapper)
For example, relativeName(column, Dbms.class, DATABASE_NAME)
would return the String "dbms_name.schema_name.table_name.column_name".
T
- parent typeD
- Document typedocument
- to usefrom
- classname
- if java or database name should be usednameMapper
- to apply to all names encountered during traversalpublic static <T extends Document & HasName,D extends Document & HasName> String relativeName(D document, Class<T> from, DocumentUtil.Name name, CharSequence separator, Function<String,String> nameMapper)
For example, relativeName(column, Dbms.class)
would return the
String "dbms_name.schema_name.table_name.column_name" if the separator is
"."
T
- parent typeD
- Document typedocument
- to usefrom
- classname
- if java or database name should be usedseparator
- to use between the document namesnameMapper
- to apply to all names encountered during traversalpublic static <DOC extends Document> DOC deepCopy(DOC document, Function<Map<String,Object>,DOC> constructor)
DOC
- the document typedocument
- the documentconstructor
- the document constructorpublic static <P extends Document,DOC extends Document & HasParent<P>> DOC deepCopy(DOC document, BiFunction<P,Map<String,Object>,DOC> constructor)
P
- the parent typeDOC
- the document typedocument
- the documentconstructor
- the document constructorpublic static Supplier<NoSuchElementException> newNoSuchElementExceptionFor(Document document, String key)
Exception
supplier for when no attribute could be
found on a specified key in a specified document.document
- the documentkey
- the keyException
supplierpublic static String toStringHelper(Document document)
toString()
-method.document
- the documentCopyright © 2017 Speedment, Inc.. All rights reserved.