use of suite.object.MapObject_ in project suite by stupidsing.
the class Dump method toLine.
private static void toLine(Object node, Sink<String> sink) {
var dumpedObjects = new IdentityHashMap<Object, Object>();
new Object() {
private void d(Object object, String suffix) {
if (object == null)
sink.f("null");
else if (dumpedObjects.put(object, true) == null)
try {
d_(object);
} finally {
dumpedObjects.remove(object);
}
else
sink.f("(recursed)");
sink.f(suffix);
}
private void d_(Object object) {
var clazz = object.getClass();
if (clazz.isArray()) {
sink.f("[");
for (var i = 0; i < Array.getLength(object); i++) d(Array.get(object, i), ",");
sink.f("]");
} else if (Util.isSimple(clazz))
sink.f(object.toString());
else
new //
Switch<Object>(//
object).doIf(Collection.class, collection -> {
sink.f("[");
for (var object1 : collection) d(object1, ",");
sink.f("]");
}).doIf(Map.class, map -> {
sink.f("{");
for (var e : ((Map<?, ?>) object).entrySet()) {
d(e.getKey(), ":");
d(e.getValue(), ",");
}
sink.f("}");
}).doIf(MapObject.class, mi -> {
sink.f(mi.getClass().getSimpleName());
sink.f("{");
for (var object1 : MapObject_.list(mi)) d(object1, ",");
sink.f("}");
}).doIf(Pair.class, pair -> {
sink.f("<");
d(pair.k, "|");
d(pair.v, ">");
}).doIf(Object.class, o -> {
sink.f(o.getClass().getSimpleName());
sink.f("{");
for (var pair : readers(object)) {
Object value;
try {
value = pair.v.call();
} catch (Throwable ex) {
value = "<" + ex.getClass() + ">";
}
if (value != null) {
sink.f(pair.k + ":");
d(value, ",");
}
}
sink.f("}");
}).nonNullResult();
}
}.d(node, "");
}
Aggregations