Package com.robinloom.jweaver.tree
Class TreeWeaver
java.lang.Object
com.robinloom.jweaver.tree.TreeWeaver
TreeWeaver depicts a given object and its fields as a tree.
This representation is particularly suitable for nested objects.
After setting up the tree structure, it is traversed in a depth-first search.
The object string is built while traversing the tree.
Example:
Person |-- name=John Doe `-- birthday=1990-01-01
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbranchChar(char branchChar) Sets the character that will be used for a simple branch of the tree.Enables capitalization of field names.excludeFields(List<String> fields) Sets the names of fields that should be excluded from the output.includeFields(List<String> fields) Sets the names of fields that should be included in the output.lastBranchChar(char lastBranchChar) Sets the character that will be used as the last char of a branch on a certain level Default is '`'maxDepth(int maxDepth) Sets the maximum depth for the resulting tree.maxSequenceLength(int maxSequenceLength) Sets the maximum length of collections and arrays to be included in the output.Enables the printing of data typesActivates the inclusion of inherited fields.Generates a string representation of the given object via reflections.
-
Constructor Details
-
TreeWeaver
public TreeWeaver()
-
-
Method Details
-
maxDepth
Sets the maximum depth for the resulting tree.- Parameters:
maxDepth- an integer for the maximum depth- Returns:
- instance for chaining
-
maxSequenceLength
Sets the maximum length of collections and arrays to be included in the output. Elements that exceed the limit will be summarized (... 57 more).- Parameters:
maxSequenceLength- an integer value- Returns:
- instance for chaining
-
branchChar
Sets the character that will be used for a simple branch of the tree. Default is '|'- Parameters:
branchChar- the character to use- Returns:
- instance for chaining
-
lastBranchChar
Sets the character that will be used as the last char of a branch on a certain level Default is '`'- Parameters:
lastBranchChar- the character to use- Returns:
- instance for chaining
-
includeFields
Sets the names of fields that should be included in the output. By default, every field is included.- Parameters:
fields- list of strings containing included field names- Returns:
- instance for chaining
-
excludeFields
Sets the names of fields that should be excluded from the output. By default, no field is excluded.- Parameters:
fields- list of strings containing excluded field names- Returns:
- instance for chaining
-
capitalizeFields
Enables capitalization of field names. firstName -> FirstName- Returns:
- instance for chaining
-
showDataTypes
Enables the printing of data types- Returns:
- instance for chaining
-
showInheritedFields
Activates the inclusion of inherited fields.- Returns:
- instance for chaining
-
weave
Generates a string representation of the given object via reflections. Prints the class name followed by every accessible field in a tree structure. For JDK classes, a regulartoString()result is returned. Detects reciprocal and circular object dependencies.- Parameters:
object- object to generate a string representation for- Returns:
- a well-structured, human-readable representation of that object
-