Class PrettyPrinter

java.lang.Object
com.pnfsoftware.jeb.util.format.PrettyPrinter

public class PrettyPrinter extends Object
The pretty-printer object does its best to provide a human-readable representation of any object. Elements of arrays, collections, and maps are rendered individually. For non-basic types, toString is called, unless forbidden (see `allowCallToString`) or customized (see formatObject(Object)). For maps, the key-value pairs are rendered one per line line. Indenting uses 2 white-space characters.
  • Field Details

    • DEFAULT_MAX_STRING_LENGTH

      public static final int DEFAULT_MAX_STRING_LENGTH
      Default maximum number of characters rendered for strings.
      See Also:
    • DEFAULT_MAX_ARRAY_ITEM_COUNT

      public static final int DEFAULT_MAX_ARRAY_ITEM_COUNT
      Default maximum number of items rendered for arrays.
      See Also:
    • DEFAULT_MAX_COLLECTION_ITEM_COUNT

      public static final int DEFAULT_MAX_COLLECTION_ITEM_COUNT
      Default maximum number of items rendered for collections.
      See Also:
    • DEFAULT_MAX_MAP_ITEM_COUNT

      public static final int DEFAULT_MAX_MAP_ITEM_COUNT
      Default maximum number of entries rendered for maps.
      See Also:
  • Constructor Details

    • PrettyPrinter

      public PrettyPrinter(boolean allowUnsafeCalls, int indentStringLength)
      Create a pretty-printer.
      Parameters:
      allowUnsafeCalls - true to allow calls to arbitrary toString, collection, and map methods
      indentStringLength - number of spaces used for one indentation level; a negative value disables multi-line map rendering
    • PrettyPrinter

      public PrettyPrinter(boolean allowUnsafeCalls)
      Create a pretty-printer using two-space indentation.
      Parameters:
      allowUnsafeCalls - true to allow calls to arbitrary toString, collection, and map methods
    • PrettyPrinter

      public PrettyPrinter()
      Create a pretty-printer allowing arbitrary object formatting calls.
  • Method Details

    • setMaxStringLength

      public void setMaxStringLength(int max)
      Set the maximum number of characters rendered for strings.
      Parameters:
      max - maximum string length
    • setMaxArrayLength

      public void setMaxArrayLength(int max)
      Set the maximum number of items rendered for arrays.
      Parameters:
      max - maximum array item count
    • setMaxCollectionLength

      public void setMaxCollectionLength(int max)
      Set the maximum number of items rendered for collections.
      Parameters:
      max - maximum collection item count
    • setMaxMapLength

      public void setMaxMapLength(int max)
      Set the maximum number of entries rendered for maps.
      Parameters:
      max - maximum map entry count
    • format

      public String format(Object o)
      Format an object.
      Parameters:
      o - object to format
      Returns:
      a human-readable representation
    • formatObject

      protected String formatObject(Object o)
      Subclasses can provide custom formatting for the given object.
      Parameters:
      o - object to format
      Returns:
      a string or null to let the pretty-printer proceed with its own implementation