Issue #3242 - Allow Dumpable to control how self is represented

+ Do not rely on Object.toString() for representing self (aka:this)
  in the dump output.  Using Object.toString() can result in lots
  of duplicated information in the dump (and super long lines)

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-01-08 15:47:17 -06:00
parent 0078d8aed6
commit 87c82ae644
1 changed files with 11 additions and 0 deletions

View File

@ -70,6 +70,15 @@ public interface Dumpable
return b.toString();
}
/**
* The description of this/self found in the dump.
* Allows for alternative representation of Object other then .toString()
* where the long form output of toString() is represented in a cleaner way
* within the dump infrastructure.
*
* @return the representation of self
*/
default String dumpSelf() { return toString(); }
/**
* Dump just an Object (but not it's contained items) to an Appendable.
@ -90,6 +99,8 @@ public interface Dumpable
s = String.format("%s@%x[size=%d]",o.getClass().getComponentType(),o.hashCode(), Array.getLength(o));
else if (o instanceof Map)
s = String.format("%s@%x{size=%d}",o.getClass().getName(),o.hashCode(),((Map<?,?>)o).size());
else if (o instanceof Dumpable)
s = ((Dumpable)o).dumpSelf().replace("\r\n","|").replace("\n","|");
else
s = String.valueOf(o).replace("\r\n","|").replace("\n","|");