Class TreeWeaver

java.lang.Object
com.robinloom.jweaver.tree.TreeWeaver
All Implemented Interfaces:
Weaver

public class TreeWeaver extends Object implements Weaver
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 Details

    • TreeWeaver

      public TreeWeaver()
  • Method Details

    • maxDepth

      public TreeWeaver maxDepth(int maxDepth)
      Sets the maximum depth for the resulting tree.
      Parameters:
      maxDepth - an integer for the maximum depth
      Returns:
      instance for chaining
    • maxSequenceLength

      public TreeWeaver maxSequenceLength(int 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

      public TreeWeaver branchChar(char 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

      public TreeWeaver lastBranchChar(char 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

      public TreeWeaver includeFields(List<String> fields)
      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

      public TreeWeaver excludeFields(List<String> fields)
      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
    • omitClassName

      public TreeWeaver omitClassName()
      Determines if the class name should be omitted when printing. By default, the class name is included.
      Returns:
      instance for chaining
    • capitalizeFields

      public TreeWeaver capitalizeFields()
      Enables capitalization of field names. firstName -> FirstName
      Returns:
      instance for chaining
    • showDataTypes

      public TreeWeaver showDataTypes()
      Enables the printing of data types
      Returns:
      instance for chaining
    • showInheritedFields

      public TreeWeaver showInheritedFields()
      Activates the inclusion of inherited fields.
      Returns:
      instance for chaining
    • weave

      public String weave(Object object)
      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 regular toString() result is returned. Detects reciprocal and circular object dependencies.
      Specified by:
      weave in interface Weaver
      Parameters:
      object - object to generate a string representation for
      Returns:
      a well-structured, human-readable representation of that object