// tables for proto network we're merging into (1)
final TermTable mtt = protoNetwork1.getTermTable();
final ParameterTable mpt = protoNetwork1.getParameterTable();
final TermParameterMapTable mtpmt =
protoNetwork1.getTermParameterMapTable();
final ProtoNodeTable mpnt = protoNetwork1.getProtoNodeTable();
// if p1 contains an equivalent Term then return it's inndex without
// adding a new one.
Integer p1Index = mtt.getVisitedTerms().get(termToMerge);
if (p1Index != null) {
termMap.put(termId, p1Index);
return p1Index;
}
List<Integer> newTermParameterIndices = new ArrayList<Integer>();
List<Integer> termParameterIndices = mapTable.getTermParameterIndex()
.get(termId);
if (hasItems(termParameterIndices)) {
for (Integer termParameterIndex : termParameterIndices) {
TableParameter parameter = parameterTable.
getIndexTableParameter().get(termParameterIndex);
newTermParameterIndices.add(mpt
.addTableParameter(parameter));
}
}
Integer newTermIndex = mtt.addTerm(termToMerge);
mtpmt.addTermParameterMapping(
newTermIndex, newTermParameterIndices);
Integer newNode = mpnt.addNode(newTermIndex, mtt.getTermValues().get(newTermIndex));
termMap.put(termId, newNode);
return newTermIndex;
}