use of suite.object.MapObject in project suite by stupidsing.
the class Dump method toDetails.
private static void toDetails(String prefix, Object object, Sink<String> sink) {
var dumpedObjects = new IdentityHashMap<Object, Object>();
new Object() {
private void d(String prefix, Object object) {
d(prefix, object, object != null ? object.getClass() : void.class);
}
private void d(String prefix, Object object, Class<?> clazz) {
sink.f(prefix);
sink.f(" =");
if (object == null)
sink.f(" null\n");
else if (dumpedObjects.put(object, true) == null)
try {
d_(prefix, object, clazz);
} finally {
dumpedObjects.remove(object);
}
else
sink.f(" <<recursed>>");
}
private void d_(String prefix, Object object, Class<?> clazz) {
if (clazz.isArray() && Util.isSimple(clazz.getComponentType())) {
sink.f(" [ ");
for (var i = 0; i < Array.getLength(object); i++) sink.f(Array.get(object, i) + ", ");
sink.f("]\n");
} else if (clazz == String.class)
sink.f(" \"" + object + "\"");
else if (Util.isSimple(clazz))
sink.f(" " + object + " [" + clazz.getSimpleName() + "]\n");
else
d_c(prefix, object, clazz);
}
private void d_c(String prefix, Object object, Class<?> clazz) {
if (!Collection.class.isAssignableFrom(clazz))
sink.f(" " + object);
sink.f(" [" + clazz.getSimpleName() + "]\n");
var count = 0;
// simple listings for simple classes
if (clazz.isArray())
if (Util.isSimple(clazz.getComponentType()))
d(prefix, Build.string(sb -> {
sb.append("[");
for (var i = 0; i < Array.getLength(object); i++) sb.append(Array.get(object, i) + ", ");
sb.append("]");
}));
else
for (var i = 0; i < Array.getLength(object); i++) d(prefix + "[" + count++ + "]", Array.get(object, i));
else if (Collection.class.isAssignableFrom(clazz))
for (var o1 : (Collection<?>) object) d(prefix + "[" + count++ + "]", o1);
else if (Map.class.isAssignableFrom(clazz))
for (var e : ((Map<?, ?>) object).entrySet()) {
Object key = e.getKey(), value = e.getValue();
d(prefix + "[" + count + "].getKey()", key);
d(prefix + "[" + count + "].getValue()", value);
count++;
}
else if (MapObject.class.isAssignableFrom(clazz)) {
var i = 0;
for (var object1 : MapObject_.list((MapObject<?>) object)) d(prefix + "." + i++, object1);
} else if (Pair.class.isAssignableFrom(clazz)) {
var pair = (Pair<?, ?>) object;
d(prefix + ".fst", pair.k);
d(prefix + ".snd", pair.v);
} else
for (var pair : readers(object)) {
var k = prefix + "." + pair.k;
try {
d(k, pair.v.call());
} catch (Throwable ex) {
sink.f(k + "()");
sink.f(" caught " + ex + "\n");
}
}
}
}.d(prefix, object);
}
Aggregations