return (DebugObject) o;
try {
Class c = o.getClass();
if(c.isArray()) {
final int len = Array.getLength(o);
return new DebugArrayObject(new DebugArrayProvider() {
private BitSet map = new BitSet(len);
private DebugArrayElement[] provided = new DebugArrayElement[len];
public int size() {
return len;
}
public DebugArrayElement get(int index) {
if(map.get(index))
return provided[index];
DebugObject v = extractFrom(Array.get(o, index));
DebugArrayElement created = new DebugArrayElement(index, v);
provided[index] = created;
map.set(index);
return created;
}
public int indexOf(Object child) {
for(int i = 0; i < provided.length; i++) {
Object p = map.get(i)? provided[i]: get(i);
if(p == child || (p != null && p.equals(child)))
return i;
}
return -1;
}
});
}
if(Collection.class.isAssignableFrom(c)) {
final Collection col = (Collection) o;
final int len = col.size();
final Iterator it = col.iterator();
return new DebugArrayObject(new AbstractDebugArrayProvider() {
protected DebugArrayElement next() {
return new DebugArrayElement(this.index, extractFrom(it.next()));
}
public int size() {