final NodeForObjectModel nodeForObjectModel=new NodeForObjectModel();
nodeForObjectModel.setNumberOfNode(map.size());
// create NodeForObject for each NodeInfo
for (NodeInfo nodeInfo : map.values()) {
NodeForObject nodeForObject = nodeInfo.nodeForObject;
if (nodeForObject == null) {
final NodeForObjectTO nodeForObjectTO = nodeInfo.nodeForObjectTO;
final NodeIdentifier identifier = nodeForObjectTO.getId();
nodeForObject = new NodeForObject(null, identifier,
nodeForObjectTO.getIdentityHashCode(),
nodeForObjectTO.getObjectClassName(),
nodeForObjectTO.isMarkedNew(),
nodeForObjectTO.isMarkedNewSon(),
nodeForObjectTO.getFieldByChildNodeIdMap(),
nodeForObjectTO.getFieldIsStaticMap(),
nodeForObjectTO.getObjectSize());
nodeInfo.nodeForObject = nodeForObject;
nodeForObjectModel.add(nodeForObject);
} else {
throw new MemInspectorException("node object must not be set");
}
}
// create father link
for (NodeInfo nodeInfo : map.values()) {
NodeForObject nodeForObject = nodeInfo.nodeForObject;
if (nodeForObject == null) {
throw new MemInspectorException("node object must be set");
}
final NodeForObjectTO nodeForObjectTO = nodeInfo.nodeForObjectTO;
final NodeIdentifier mainFatherId = nodeForObjectTO
.getMainFatherNodeId();
final NodeForObject mainFatherNode;
if (mainFatherId == null) {
mainFatherNode = null;
} else {
final NodeInfo fatherNodeInfo = map.get(mainFatherId);
if (fatherNodeInfo == null) {
throw new MemInspectorException("node of id #"
+ mainFatherId + " must exist");
}
mainFatherNode = fatherNodeInfo.nodeForObject;
}
nodeForObject.setMainFatherNode(mainFatherNode);
for (NodeIdentifier fatherId : nodeInfo.fatherIdSet) {
final NodeInfo fatherNodeInfo = map.get(fatherId);
if (fatherNodeInfo == null) {
// throw new MemInspectorException(
// "missing node info for node #" + fatherId);
LOGGER.warn("missing node info for node #" + fatherId
+ " father of " + nodeInfo.nodeForObject);
} else {
final NodeForObject fatherNode = map.get(fatherId).nodeForObject;
if (fatherNode == null) {
throw new MemInspectorException("missing node #"
+ fatherId + ", fatherNodeInfo="
+ fatherNodeInfo + ", node="
+ nodeInfo.nodeForObject);
}
nodeForObject.addFather(fatherNode);
}
}
}
// create child link
for (NodeInfo nodeInfo : map.values()) {
NodeForObject nodeForObject = nodeInfo.nodeForObject;
for (NodeIdentifier childId : nodeInfo.childIdSet) {
final NodeInfo childNodeInfo = map.get(childId);
if (childNodeInfo == null) {
throw new MemInspectorException(
"missing node info for node #" + childId);
}
final NodeForObject childNode = map.get(childId).nodeForObject;
if (childNode == null) {
throw new MemInspectorException("missing node #" + childId
+ ", childNodeInfo=" + childNodeInfo + ", node="
+ nodeInfo.nodeForObject);
}
nodeForObject.addChild(childNode);
}
}
final NodeForObject rootNode = map.get(rootNodeId).nodeForObject;
nodeForObjectModel.setRootNode(rootNode);
//nodeForObjectModel.x();
// was for debug: check father path