Program: 16844
Project: 16844
Buggy source:
/** 
 * Calculate the interface clusters for this StructureInterfaceList  using a contact overlap score to measure the similarity of interfaces. Subsequent calls will use the cached value without recomputing the clusters.
 * @return
 */
public List<StructureInterfaceCluster> getClusters(){
  if (clusters != null) {
    return clusters;
  }
  clusters=new ArrayList<StructureInterfaceCluster>();
  double[][] matrix=new double[list.size()][list.size()];
  for (int i=0; i < list.size(); i++) {
    for (int j=i + 1; j < list.size(); j++) {
      StructureInterface iInterf=list.get(i);
      StructureInterface jInterf=list.get(j);
      double scoreDirect=iInterf.getContactOverlapScore(jInterf,false);
      double scoreInvert=iInterf.getContactOverlapScore(jInterf,true);
      double maxScore=Math.max(scoreDirect,scoreInvert);
      matrix[i][j]=maxScore;
    }
  }
  SingleLinkageClusterer slc=new SingleLinkageClusterer(matrix,true);
  Map<Integer,Set<Integer>> clusteredIndices=slc.getClusters(CONTACT_OVERLAP_SCORE_CLUSTER_CUTOFF);
  for (  int clusterIdx : clusteredIndices.keySet()) {
    List<StructureInterface> members=new ArrayList<StructureInterface>();
    for (    int idx : clusteredIndices.get(clusterIdx)) {
      members.add(list.get(idx));
    }
    StructureInterfaceCluster cluster=new StructureInterfaceCluster();
    cluster.setMembers(members);
    clusters.add(cluster);
  }
  for (  StructureInterfaceCluster cluster : clusters) {
    for (    StructureInterface interf : cluster.getMembers()) {
      interf.setCluster(cluster);
    }
  }
  Collections.sort(clusters,new Comparator<StructureInterfaceCluster>(){
    @Override public int compare(    StructureInterfaceCluster o1,    StructureInterfaceCluster o2){
      return Double.compare(o2.getTotalArea(),o1.getTotalArea());
    }
  }
);
  int id=1;
  for (  StructureInterfaceCluster cluster : clusters) {
    cluster.setId(id);
    id++;
  }
  return clusters;
}

Fixed version (ground truth):
/** 
 * Calculate the interface clusters for this StructureInterfaceList  using a contact overlap score to measure the similarity of interfaces. Subsequent calls will use the cached value without recomputing the clusters.
 * @return
 */
public List<StructureInterfaceCluster> getClusters(){
  if (clusters != null) {
    return clusters;
  }
  clusters=new ArrayList<StructureInterfaceCluster>();
  if (list.size() == 0)   return clusters;
  double[][] matrix=new double[list.size()][list.size()];
  for (int i=0; i < list.size(); i++) {
    for (int j=i + 1; j < list.size(); j++) {
      StructureInterface iInterf=list.get(i);
      StructureInterface jInterf=list.get(j);
      double scoreDirect=iInterf.getContactOverlapScore(jInterf,false);
      double scoreInvert=iInterf.getContactOverlapScore(jInterf,true);
      double maxScore=Math.max(scoreDirect,scoreInvert);
      matrix[i][j]=maxScore;
    }
  }
  SingleLinkageClusterer slc=new SingleLinkageClusterer(matrix,true);
  Map<Integer,Set<Integer>> clusteredIndices=slc.getClusters(CONTACT_OVERLAP_SCORE_CLUSTER_CUTOFF);
  for (  int clusterIdx : clusteredIndices.keySet()) {
    List<StructureInterface> members=new ArrayList<StructureInterface>();
    for (    int idx : clusteredIndices.get(clusterIdx)) {
      members.add(list.get(idx));
    }
    StructureInterfaceCluster cluster=new StructureInterfaceCluster();
    cluster.setMembers(members);
    clusters.add(cluster);
  }
  for (  StructureInterfaceCluster cluster : clusters) {
    for (    StructureInterface interf : cluster.getMembers()) {
      interf.setCluster(cluster);
    }
  }
  Collections.sort(clusters,new Comparator<StructureInterfaceCluster>(){
    @Override public int compare(    StructureInterfaceCluster o1,    StructureInterfaceCluster o2){
      return Double.compare(o2.getTotalArea(),o1.getTotalArea());
    }
  }
);
  int id=1;
  for (  StructureInterfaceCluster cluster : clusters) {
    cluster.setId(id);
    id++;
  }
  return clusters;
}