Program: 107957
Project: 107957
Buggy source:
/** 
 * Returns statistics about the equivalence classes.
 * @return
 */
public StatisticsEquivalenceClasses getEquivalenceClassStatistics(){
  interrupt.value=false;
  Set<String> attributes=handle.getDefinition().getQuasiIdentifyingAttributes();
  final int[] indices=new int[attributes.size()];
  int index=0;
  for (int column=0; column < handle.getNumColumns(); column++) {
    if (attributes.contains(handle.getAttributeName(column))) {
      indices[index++]=column;
    }
  }
  int capacity=handle.getNumRows() / 10;
  capacity=capacity > 10 ? capacity : 10;
  Groupify<TupleWrapper> map=new Groupify<TupleWrapper>(capacity);
  int numRows=handle.getNumRows();
  for (int row=0; row < numRows; row++) {
    TupleWrapper tuple=new TupleWrapper(handle,indices,row,false);
    map.add(tuple);
    checkInterrupt();
  }
  double averageEquivalenceClassSize=0d;
  double averageEquivalenceClassSizeIncludingOutliers=0d;
  int maximalEquivalenceClassSize=Integer.MIN_VALUE;
  int maximalEquivalenceClassSizeIncludingOutliers=Integer.MIN_VALUE;
  int minimalEquivalenceClassSize=Integer.MAX_VALUE;
  int minimalEquivalenceClassSizeIncludingOutliers=Integer.MAX_VALUE;
  int numberOfEquivalenceClasses=0;
  int numberOfEquivalenceClassesIncludingOutliers=map.size();
  int numberOfTuples=0;
  int numberOfOutlyingTuples=0;
  boolean containsOutliers=false;
  Group<TupleWrapper> element=map.first();
  while (element != null) {
    checkInterrupt();
    maximalEquivalenceClassSizeIncludingOutliers=Math.max(element.getCount(),maximalEquivalenceClassSizeIncludingOutliers);
    minimalEquivalenceClassSizeIncludingOutliers=Math.min(element.getCount(),minimalEquivalenceClassSizeIncludingOutliers);
    averageEquivalenceClassSizeIncludingOutliers+=element.getCount();
    numberOfTuples+=element.getCount();
    if (!element.getElement().isOutlier()) {
      maximalEquivalenceClassSize=Math.max(element.getCount(),maximalEquivalenceClassSize);
      minimalEquivalenceClassSize=Math.min(element.getCount(),minimalEquivalenceClassSize);
      averageEquivalenceClassSize+=element.getCount();
    }
 else {
      containsOutliers=true;
      numberOfOutlyingTuples=element.getCount();
    }
    element=element.next();
  }
  numberOfEquivalenceClasses=numberOfEquivalenceClassesIncludingOutliers;
  if (containsOutliers) {
    numberOfEquivalenceClasses-=1;
  }
  averageEquivalenceClassSize/=(double)numberOfEquivalenceClasses;
  averageEquivalenceClassSizeIncludingOutliers/=(double)numberOfEquivalenceClassesIncludingOutliers;
  return new StatisticsEquivalenceClasses(averageEquivalenceClassSize,averageEquivalenceClassSizeIncludingOutliers,maximalEquivalenceClassSize,maximalEquivalenceClassSizeIncludingOutliers,minimalEquivalenceClassSize,minimalEquivalenceClassSizeIncludingOutliers,numberOfEquivalenceClasses,numberOfEquivalenceClassesIncludingOutliers,numberOfTuples,numberOfOutlyingTuples);
}

Fixed version (ground truth):
/** 
 * Returns statistics about the equivalence classes.
 * @return
 */
public StatisticsEquivalenceClasses getEquivalenceClassStatistics(){
  interrupt.value=false;
  Set<String> attributes=handle.getDefinition().getQuasiIdentifyingAttributes();
  final int[] indices=new int[attributes.size()];
  int index=0;
  for (int column=0; column < handle.getNumColumns(); column++) {
    if (attributes.contains(handle.getAttributeName(column))) {
      indices[index++]=column;
    }
  }
  int capacity=handle.getNumRows() / 10;
  capacity=capacity > 10 ? capacity : 10;
  Groupify<TupleWrapper> map=new Groupify<TupleWrapper>(capacity);
  int numRows=handle.getNumRows();
  for (int row=0; row < numRows; row++) {
    TupleWrapper tuple=new TupleWrapper(handle,indices,row,false);
    map.add(tuple);
    checkInterrupt();
  }
  double averageEquivalenceClassSize=0d;
  double averageEquivalenceClassSizeIncludingOutliers=0d;
  int maximalEquivalenceClassSize=Integer.MIN_VALUE;
  int maximalEquivalenceClassSizeIncludingOutliers=Integer.MIN_VALUE;
  int minimalEquivalenceClassSize=Integer.MAX_VALUE;
  int minimalEquivalenceClassSizeIncludingOutliers=Integer.MAX_VALUE;
  int numberOfEquivalenceClasses=0;
  int numberOfEquivalenceClassesIncludingOutliers=map.size();
  int numberOfTuples=0;
  int numberOfOutlyingTuples=0;
  boolean containsOutliers=false;
  Group<TupleWrapper> element=map.first();
  while (element != null) {
    checkInterrupt();
    maximalEquivalenceClassSizeIncludingOutliers=Math.max(element.getCount(),maximalEquivalenceClassSizeIncludingOutliers);
    minimalEquivalenceClassSizeIncludingOutliers=Math.min(element.getCount(),minimalEquivalenceClassSizeIncludingOutliers);
    averageEquivalenceClassSizeIncludingOutliers+=element.getCount();
    numberOfTuples+=element.getCount();
    if (!element.getElement().isOutlier()) {
      maximalEquivalenceClassSize=Math.max(element.getCount(),maximalEquivalenceClassSize);
      minimalEquivalenceClassSize=Math.min(element.getCount(),minimalEquivalenceClassSize);
      averageEquivalenceClassSize+=element.getCount();
    }
 else {
      containsOutliers=true;
      numberOfOutlyingTuples=element.getCount();
    }
    element=element.next();
  }
  numberOfEquivalenceClasses=numberOfEquivalenceClassesIncludingOutliers;
  if (containsOutliers) {
    numberOfEquivalenceClasses-=1;
  }
  averageEquivalenceClassSize/=(double)numberOfEquivalenceClasses;
  averageEquivalenceClassSizeIncludingOutliers/=(double)numberOfEquivalenceClassesIncludingOutliers;
  if (numberOfEquivalenceClasses == 0) {
    averageEquivalenceClassSize=0;
    maximalEquivalenceClassSize=0;
    minimalEquivalenceClassSize=0;
  }
  return new StatisticsEquivalenceClasses(averageEquivalenceClassSize,averageEquivalenceClassSizeIncludingOutliers,maximalEquivalenceClassSize,maximalEquivalenceClassSizeIncludingOutliers,minimalEquivalenceClassSize,minimalEquivalenceClassSizeIncludingOutliers,numberOfEquivalenceClasses,numberOfEquivalenceClassesIncludingOutliers,numberOfTuples,numberOfOutlyingTuples);
}