Package com.pnfsoftware.jeb.util.format
Class PrettyPrinter
java.lang.Object
com.pnfsoftware.jeb.util.format.PrettyPrinter
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of items rendered for arrays.static final intDefault maximum number of items rendered for collections.static final intDefault maximum number of entries rendered for maps.static final intDefault maximum number of characters rendered for strings. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a pretty-printer allowing arbitrary object formatting calls.PrettyPrinter(boolean allowUnsafeCalls) Create a pretty-printer using two-space indentation.PrettyPrinter(boolean allowUnsafeCalls, int indentStringLength) Create a pretty-printer. -
Method Summary
Modifier and TypeMethodDescriptionFormat an object.protected StringSubclasses can provide custom formatting for the given object.voidsetMaxArrayLength(int max) Set the maximum number of items rendered for arrays.voidsetMaxCollectionLength(int max) Set the maximum number of items rendered for collections.voidsetMaxMapLength(int max) Set the maximum number of entries rendered for maps.voidsetMaxStringLength(int max) Set the maximum number of characters rendered for strings.
-
Field Details
-
DEFAULT_MAX_STRING_LENGTH
public static final int DEFAULT_MAX_STRING_LENGTHDefault maximum number of characters rendered for strings.- See Also:
-
DEFAULT_MAX_ARRAY_ITEM_COUNT
public static final int DEFAULT_MAX_ARRAY_ITEM_COUNTDefault maximum number of items rendered for arrays.- See Also:
-
DEFAULT_MAX_COLLECTION_ITEM_COUNT
public static final int DEFAULT_MAX_COLLECTION_ITEM_COUNTDefault maximum number of items rendered for collections.- See Also:
-
DEFAULT_MAX_MAP_ITEM_COUNT
public static final int DEFAULT_MAX_MAP_ITEM_COUNTDefault 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 arbitrarytoString, collection, and map methodsindentStringLength- 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 arbitrarytoString, 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
Format an object.- Parameters:
o- object to format- Returns:
- a human-readable representation
-
formatObject
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
-