public void accept(final ITreeNodeForObjectVisitor visitor,
final Set<NodeForObject> visitedSet, final int depth)
throws MemInspectorException {
if (isDeleted()) {
throw new MemInspectorException("deleted node " + this
+ " must not be attached to object graph");
}
/*
* check if this node attached to root and there is no cycle
*/
final Set<NodeForObject> set = new LinkedHashSet<NodeForObject>();
NodeForObject current = this;
while (!current.rootNode) {
if (!set.add(current)) {
final StringBuilder builder = new StringBuilder();// NOPMD
builder.append("cycle detected\n");
for (NodeForObject nodeForObject : set) {
builder.append(nodeForObject);
builder.append('\n');
}
throw new MemInspectorException(builder.toString());
}
current = current.getMainFatherNode();
if (current == null) {
throw new MemInspectorException(
"main father node must be defined");
}
}
final boolean firstVisit = visitedSet.add(this);
visitor.beginVisit(this, firstVisit);
if (firstVisit) {
for (NodeForObject childNode : childNodeMap.values()) {
// has a main father node
if (!childNode.rootNode
&& childNode.getMainFatherNode() == null) {
throw new MemInspectorException(
"main father node must be defined, has father="
+ (!childNode.fatherNodeSet.isEmpty()),
childNode.mainFatherNodeNullerTrace);
}
// child node has this as father
if (!childNode.getFatherNodeSet().contains(this)) {
throw new MemInspectorException(childNode + " must have "
+ this + " as father");
}
// visit child
childNode.accept(visitor, visitedSet, depth + 1);
}