Top Description Fields Constructors Methods
uk.ac.ed.ph.snuggletex.internal.util

public final Class ObjectDumper

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.Collection, .List, .Map, .Set, .Map.Entry

Trivial but slightly useful helper for creating deep dumps of Objects and their its properties, which can be useful for displaying status messages and debugging. (This is copied from ph-commons-util.)
Author
David McKain
Version
$Revision$

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
private static final String
private int
indentWidth

Number of spaces to indent at each level of Object depth

private int
maxDepth

Maximum child Object depth to traverse to before issuing circularity error

private final StringBuilder
result

StringBuilder that the dump will append to

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
appendArray(Object[] array, DumpMode dumpMode, int depth)

private <E> void
appendCollection(Collection<E> collection, DumpMode dumpMode, int depth)

private <E> void
appendList(List<E> list, DumpMode dumpMode, int depth)

private <K, V> void
appendMap(Map<K, V> map, DumpMode dumpMode, int depth)

public void
appendObject(Object object)

Does a dump of the given Object, using whatever DumpMode is providied for its class.

public void
appendObject(Object object, DumpMode
if DumpMode#DEEP then the Object is dumped deeply, if DumpMode#TO_STRING then the Object's toString() is called, if DumpMode#IGNORE then nothing happens.
dumpMode
)

Does a dump of the given Object using the given DumpMode.

private void
appendObject(Object object, DumpMode dumpMode, int depth)

private void
appendObjectDeep(Object object, int depth)

private <E> void
appendSet(Set<E> set, DumpMode dumpMode, int depth)

public static String
dumpObject(Object object, DumpMode dumpMode)

Convenience method to do a DumpMode#DEEP dump of a single Object and return the resulting String.

private DumpMode
getElementDumpMode(Object
Object being dumped
object
,
DumpMode
DumpMode currently in operation, used if nothing is specified for the Object's class or if the Object is null.
currentDumpMode
)

Works out the most appropriate DumpMode for the given Object by inspecting its class for the relevant annotation.

public int
public int
private void
makeIndent(int depth)

public void
setIndentWidth(int indentWidth)

public void
setMaxDepth(int maxDepth)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_INDENT_WIDTHback to summary
public static final int DEFAULT_INDENT_WIDTH
DEFAULT_MAX_DEPTHback to summary
public static final int DEFAULT_MAX_DEPTH
EMPTYback to summary
private static final String EMPTY
indentWidthback to summary
private int indentWidth

Number of spaces to indent at each level of Object depth

maxDepthback to summary
private int maxDepth

Maximum child Object depth to traverse to before issuing circularity error

resultback to summary
private final StringBuilder result

StringBuilder that the dump will append to

Constructor Detail

ObjectDumperback to summary
public ObjectDumper(StringBuilder result)

Method Detail

appendArrayback to summary
private void appendArray(Object[] array, DumpMode dumpMode, int depth)
appendCollectionback to summary
private <E> void appendCollection(Collection<E> collection, DumpMode dumpMode, int depth)
appendListback to summary
private <E> void appendList(List<E> list, DumpMode dumpMode, int depth)
appendMapback to summary
private <K, V> void appendMap(Map<K, V> map, DumpMode dumpMode, int depth)
appendObjectback to summary
public void appendObject(Object object)

Does a dump of the given Object, using whatever DumpMode is providied for its class. If the Object is null, then DumpMode#TO_STRING is used.

appendObjectback to summary
public void appendObject(Object object, DumpMode dumpMode)

Does a dump of the given Object using the given DumpMode.

Parameters
dumpMode:DumpMode

if DumpMode#DEEP then the Object is dumped deeply, if DumpMode#TO_STRING then the Object's toString() is called, if DumpMode#IGNORE then nothing happens.

appendObjectback to summary
private void appendObject(Object object, DumpMode dumpMode, int depth)
appendObjectDeepback to summary
private void appendObjectDeep(Object object, int depth)
appendSetback to summary
private <E> void appendSet(Set<E> set, DumpMode dumpMode, int depth)
dumpObjectback to summary
public static String dumpObject(Object object, DumpMode dumpMode)

Convenience method to do a DumpMode#DEEP dump of a single Object and return the resulting String.

getElementDumpModeback to summary
private DumpMode getElementDumpMode(Object object, DumpMode currentDumpMode)

Works out the most appropriate DumpMode for the given Object by inspecting its class for the relevant annotation.

Parameters
object:Object

Object being dumped

currentDumpMode:DumpMode

DumpMode currently in operation, used if nothing is specified for the Object's class or if the Object is null.

getIndentWidthback to summary
public int getIndentWidth()
getMaxDepthback to summary
public int getMaxDepth()
makeIndentback to summary
private void makeIndent(int depth)
setIndentWidthback to summary
public void setIndentWidth(int indentWidth)
setMaxDepthback to summary
public void setMaxDepth(int maxDepth)