Class DynamicWeaver

java.lang.Object
com.robinloom.jweaver.dynamic.DynamicWeaver
All Implemented Interfaces:
Weaver

public class DynamicWeaver extends Object implements Weaver
DynamicWeaver generates a string representation for a given object by combining the object information (class name, field names, values) with a set of separator strings. The set of separator strings is dynamically configurable.

Example:

 Person[name=John Doe, birthday=1990-01-01]
 
  • Field Details

  • Constructor Details

    • DynamicWeaver

      public DynamicWeaver()
  • Method Details

    • multiline

      public DynamicWeaver multiline()
      Sets newline '\n' as separator for fields and for classname and fields. The result will be a multiline output.
      Returns:
      instance for chaining
    • classNamePrefix

      public DynamicWeaver classNamePrefix(String classNamePrefix)
      Sets a string to be placed before the class name. Default is empty string.
      Parameters:
      classNamePrefix - the string to use
      Returns:
      instance for chaining
    • classNameSuffix

      public DynamicWeaver classNameSuffix(String classNameSuffix)
      Sets a string to be placed after the class name. Default is empty string.
      Parameters:
      classNameSuffix - the string to use
      Returns:
      instance for chaining
    • classNameFieldsSeparator

      public DynamicWeaver classNameFieldsSeparator(String separator)
      Sets a string to separate the class name and the fields to be printed. Will be between the class name suffix and the first field. Default string is "[".
      Parameters:
      separator - the separator string to use
      Returns:
      instance for chaining
    • fieldValueSeparator

      public DynamicWeaver fieldValueSeparator(String separator)
      Sets a string to separate the field name and the corresponding value. Default string is "=".
      Parameters:
      separator - the separator string to use
      Returns:
      instance for chaining
    • fieldSeparator

      public DynamicWeaver fieldSeparator(String separator)
      Sets a string that is used to separate the printed fields. Default string is ","
      Parameters:
      separator - the separator string to use.
      Returns:
      instance for chaining
    • globalSuffix

      public DynamicWeaver globalSuffix(String suffix)
      Sets a string that is placed at the end of the generated string. Default string is "]".
      Parameters:
      suffix - the string to be used.
      Returns:
      instance for chaining.
    • maxSequenceLength

      public DynamicWeaver 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
    • includeFields

      public DynamicWeaver 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 DynamicWeaver 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 DynamicWeaver omitClassName()
      Determines if the class name should be omitted when printing. By default, the class name is included.
      Returns:
      instance for chaining
    • capitalizeFields

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

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

      public DynamicWeaver 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. 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