Program: 50220
Project: 50220
Buggy source:
/** 
 * This function is the preorder function for constructing newick trees given a list of sources. This ONLY considers the sources. There should be a general function that considers some sort of hierarchy of decisions (WORKING ON THIS - CEH) TODO: this will need to eventually incorporate more functionality for deciding based on more than the sources
 * @param curnode
 * @param parent
 * @param sources
 * @param relcoming
 * @return
 */
private JadeNode preorderConstructNewickTieBreakerSOURCE(Node curnode,JadeNode parent,String[] sources,Relationship relcoming,boolean useTaxonomy){
  boolean ret=false;
  JadeNode newNode=new JadeNode();
  if (curnode.hasProperty("String_Node_Str")) {
    newNode.setName((String)curnode.getProperty("String_Node_Str"));
    newNode.setName(GeneralUtils.cleanName(newNode.getName()));
  }
  if (parent == null) {
    ret=true;
  }
 else {
    parent.addChild(newNode);
    if (sinkLostChildrenStrict || sinkLostChildrenRelaxed) {
      knownIdsInTree.add(curnode.getId());
    }
    if (relcoming.hasProperty("String_Node_Str")) {
      newNode.setBL((Double)relcoming.getProperty("String_Node_Str"));
    }
  }
  HashMap<Long,HashSet<Long>> candNodeDescendantIdsMap=new HashMap<Long,HashSet<Long>>();
  HashMap<Long,Integer> candNodeRankingMap=new HashMap<Long,Integer>();
  HashMap<Long,Relationship> candNodeRelationshipMap=new HashMap<Long,Relationship>();
  HashSet<Long> candidateNodeIds=new HashSet<Long>();
  for (  Relationship candRel : curnode.getRelationships(Direction.INCOMING,RelTypes.STREECHILDOF)) {
    if (useTaxonomy == false) {
      if (candRel.getProperty("String_Node_Str").equals("String_Node_Str"))       continue;
    }
    Long cid=candRel.getStartNode().getId();
    if (candidateNodeIds.contains(cid) == false) {
      candidateNodeIds.add(cid);
      HashSet<Long> descIds=new HashSet<Long>();
      for (      long descId : (long[])graphDb.getNodeById(cid).getProperty("String_Node_Str"))       descIds.add(descId);
      candNodeDescendantIdsMap.put(cid,descIds);
      candNodeRelationshipMap.put(cid,candRel);
      candNodeRankingMap.put(cid,sources.length);
    }
    if (candNodeRankingMap.get(cid) != 0) {
      String sourceName=(String)candRel.getProperty("String_Node_Str");
      for (int i=0; i < sources.length; i++) {
        if (sourceName.compareTo(sources[i]) == 0) {
          if (candNodeRankingMap.get(cid) > i) {
            candNodeRankingMap.put(cid,i);
            candNodeRelationshipMap.put(cid,candRel);
          }
          break;
        }
      }
    }
  }
  if (candidateNodeIds.size() == 0) {
    return null;
  }
  HashSet<Long> putativeLostChildIds=null;
  if (sinkLostChildrenStrict) {
    putativeLostChildIds=new HashSet<Long>();
  }
  HashSet<Long> nodesToExclude=new HashSet<Long>();
  for (  Long cid_i : candidateNodeIds) {
    if (nodesToExclude.contains(cid_i))     continue;
    HashSet<Long> descIds_i=candNodeDescendantIdsMap.get(cid_i);
    for (    Long cid_j : candidateNodeIds) {
      if (cid_j == cid_i || nodesToExclude.contains(cid_j))       continue;
      HashSet<Long> descIds_j=candNodeDescendantIdsMap.get(cid_j);
      HashSet<Long> descIds_iMinusj=new HashSet<Long>(descIds_i);
      descIds_iMinusj.removeAll(descIds_j);
      if ((descIds_i.size() - descIds_iMinusj.size()) > 0) {
        if (candNodeRankingMap.get(cid_i) < candNodeRankingMap.get(cid_j)) {
          nodesToExclude.add(cid_j);
          if (sinkLostChildrenStrict) {
            putativeLostChildIds.addAll(descIds_j);
          }
        }
 else {
          nodesToExclude.add(cid_i);
          if (sinkLostChildrenStrict) {
            putativeLostChildIds.addAll(descIds_i);
          }
 else {
            break;
          }
        }
      }
    }
  }
  candidateNodeIds.removeAll(nodesToExclude);
  if (candidateNodeIds.size() == 0) {
    return null;
  }
  if (sinkLostChildrenStrict) {
    HashSet<Long> impliedDescendantIds=new HashSet<Long>();
    for (    Long cid : candidateNodeIds) {
      for (      long descId : (long[])graphDb.getNodeById(cid).getProperty("String_Node_Str"))       impliedDescendantIds.add(descId);
    }
    for (    Long childId : putativeLostChildIds) {
      if (!impliedDescendantIds.contains(childId) && !knownIdsInTree.contains(childId)) {
        JadeNode addlChild=new JadeNode();
        Node graphNodeForChild=graphDb.getNodeById(childId);
        if (graphNodeForChild.hasProperty("String_Node_Str")) {
          addlChild.setName((String)graphNodeForChild.getProperty("String_Node_Str"));
          addlChild.setName(GeneralUtils.cleanName(addlChild.getName()));
        }
        newNode.addChild(addlChild);
        knownIdsInTree.add(childId);
      }
    }
  }
  for (  Long cid : candidateNodeIds) {
    preorderConstructNewickTieBreakerSOURCE(graphDb.getNodeById(cid),newNode,sources,candNodeRelationshipMap.get(cid),useTaxonomy);
  }
  if (ret == true) {
    return newNode;
  }
  return null;
}

Fixed version (ground truth):
/** 
 * This function is the preorder function for constructing newick trees given a list of sources. This ONLY considers the sources. There should be a general function that considers some sort of hierarchy of decisions TODO: this will need to eventually incorporate more functionality for deciding based on more than the sources
 * @param curnode
 * @param parent
 * @param sources
 * @param relcoming
 * @return
 */
private JadeNode preorderConstructNewickTieBreakerSOURCE(Node curnode,JadeNode parent,String[] sources,Relationship relcoming,boolean useTaxonomy){
  boolean ret=false;
  JadeNode newNode=new JadeNode();
  if (curnode.hasProperty("String_Node_Str")) {
    newNode.setName((String)curnode.getProperty("String_Node_Str"));
    newNode.setName(GeneralUtils.cleanName(newNode.getName()));
  }
  if (parent == null) {
    ret=true;
  }
 else {
    parent.addChild(newNode);
    if (sinkLostChildrenStrict || sinkLostChildrenRelaxed) {
      knownIdsInTree.add(curnode.getId());
    }
    if (relcoming.hasProperty("String_Node_Str")) {
      newNode.setBL((Double)relcoming.getProperty("String_Node_Str"));
    }
  }
  HashMap<Long,HashSet<Long>> candNodeDescendantIdsMap=new HashMap<Long,HashSet<Long>>();
  HashMap<Long,Integer> candNodeRankingMap=new HashMap<Long,Integer>();
  HashMap<Long,Relationship> candNodeRelationshipMap=new HashMap<Long,Relationship>();
  HashSet<Long> candidateNodeIds=new HashSet<Long>();
  for (  Relationship candRel : curnode.getRelationships(Direction.INCOMING,RelTypes.STREECHILDOF)) {
    if (useTaxonomy == false) {
      if (candRel.getProperty("String_Node_Str").equals("String_Node_Str"))       continue;
    }
    Long cid=candRel.getStartNode().getId();
    if (candidateNodeIds.contains(cid) == false) {
      candidateNodeIds.add(cid);
      HashSet<Long> descIds=new HashSet<Long>();
      for (      long descId : (long[])graphDb.getNodeById(cid).getProperty("String_Node_Str"))       descIds.add(descId);
      candNodeDescendantIdsMap.put(cid,descIds);
      candNodeRelationshipMap.put(cid,candRel);
      candNodeRankingMap.put(cid,sources.length);
    }
    if (candNodeRankingMap.get(cid) != 0) {
      String sourceName=(String)candRel.getProperty("String_Node_Str");
      for (int i=0; i < sources.length; i++) {
        if (sourceName.compareTo(sources[i]) == 0) {
          if (candNodeRankingMap.get(cid) > i) {
            candNodeRankingMap.put(cid,i);
            candNodeRelationshipMap.put(cid,candRel);
          }
          break;
        }
      }
    }
  }
  if (candidateNodeIds.size() == 0) {
    return null;
  }
  HashSet<Long> putativeLostChildIds=null;
  if (sinkLostChildrenStrict) {
    putativeLostChildIds=new HashSet<Long>();
  }
  HashSet<Long> nodesToExclude=new HashSet<Long>();
  for (  Long cid_i : candidateNodeIds) {
    if (nodesToExclude.contains(cid_i))     continue;
    HashSet<Long> descIds_i=candNodeDescendantIdsMap.get(cid_i);
    for (    Long cid_j : candidateNodeIds) {
      if (cid_j == cid_i || nodesToExclude.contains(cid_j))       continue;
      HashSet<Long> descIds_j=candNodeDescendantIdsMap.get(cid_j);
      HashSet<Long> descIds_iMinusj=new HashSet<Long>(descIds_i);
      descIds_iMinusj.removeAll(descIds_j);
      if ((descIds_i.size() - descIds_iMinusj.size()) > 0) {
        if (candNodeRankingMap.get(cid_i) < candNodeRankingMap.get(cid_j)) {
          nodesToExclude.add(cid_j);
          if (sinkLostChildrenStrict) {
            putativeLostChildIds.addAll(descIds_j);
          }
        }
 else {
          nodesToExclude.add(cid_i);
          if (sinkLostChildrenStrict) {
            putativeLostChildIds.addAll(descIds_i);
          }
 else {
            break;
          }
        }
      }
    }
  }
  candidateNodeIds.removeAll(nodesToExclude);
  if (candidateNodeIds.size() == 0) {
    return null;
  }
  if (sinkLostChildrenStrict) {
    HashSet<Long> impliedDescendantIds=new HashSet<Long>();
    for (    Long cid : candidateNodeIds) {
      for (      long descId : (long[])graphDb.getNodeById(cid).getProperty("String_Node_Str"))       impliedDescendantIds.add(descId);
    }
    for (    Long childId : putativeLostChildIds) {
      if (!impliedDescendantIds.contains(childId) && !knownIdsInTree.contains(childId)) {
        JadeNode addlChild=new JadeNode();
        Node graphNodeForChild=graphDb.getNodeById(childId);
        if (graphNodeForChild.hasProperty("String_Node_Str")) {
          addlChild.setName((String)graphNodeForChild.getProperty("String_Node_Str"));
          addlChild.setName(GeneralUtils.cleanName(addlChild.getName()));
        }
        newNode.addChild(addlChild);
        knownIdsInTree.add(childId);
      }
    }
  }
  for (  Long cid : candidateNodeIds) {
    preorderConstructNewickTieBreakerSOURCE(graphDb.getNodeById(cid),newNode,sources,candNodeRelationshipMap.get(cid),useTaxonomy);
  }
  if (ret == true) {
    return newNode;
  }
  return null;
}