Program: 10513
Project: 10513
Buggy source:
/** 
 * Puts rules density on show.
 */
private void displayRuleDensity(){
  paintTheChart(this.session.chartData.getOriginalTimeseries());
  chartPanel=new ChartPanel(this.chart);
  chartPanel.setMaximumDrawHeight(this.getParent().getHeight());
  chartPanel.setMaximumDrawWidth(this.getParent().getWidth());
  chartPanel.setMinimumDrawWidth(0);
  chartPanel.setMinimumDrawHeight(0);
  chartPanel.revalidate();
  this.removeAll();
  this.add(chartPanel);
  int maxObservedCoverage=Integer.MIN_VALUE;
  int minObservedCoverage=Integer.MAX_VALUE;
  int[] coverageArray=new int[this.session.chartData.getOriginalTimeseries().length];
  for (  GrammarRuleRecord r : this.session.chartData.getGrammarRules()) {
    if (0 == r.ruleNumber()) {
      continue;
    }
    ArrayList<RuleInterval> occurrences=this.session.chartData.getRulePositionsByRuleNum(r.ruleNumber());
    for (    RuleInterval i : occurrences) {
      int start=i.getStart();
      int end=i.getEnd();
      for (int j=start; j < end; j++) {
        if (CoverageCountStrategy.COUNT.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + 1;
        }
 else         if (CoverageCountStrategy.LEVEL.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleLevel();
        }
 else         if (CoverageCountStrategy.OCCURRENCE.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getOccurrences().size();
        }
 else         if (CoverageCountStrategy.YIELD.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleYield();
        }
 else         if (CoverageCountStrategy.PRODUCT.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleLevel() * r.getOccurrences().size();
        }
        if (maxObservedCoverage < coverageArray[j]) {
          maxObservedCoverage=coverageArray[j];
        }
        if (minObservedCoverage > coverageArray[j]) {
          minObservedCoverage=coverageArray[j];
        }
      }
    }
  }
  double covIncrement=1.0 / (double)maxObservedCoverage;
  for (  GrammarRuleRecord r : this.session.chartData.getGrammarRules()) {
    if (0 == r.ruleNumber()) {
      continue;
    }
    ArrayList<RuleInterval> occurrences=r.getRuleIntervals();
    for (    RuleInterval i : occurrences) {
      IntervalMarker marker=new IntervalMarker(i.getStart(),i.getEnd());
      marker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
      marker.setPaint(Color.BLUE);
      if (CoverageCountStrategy.COUNT.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement);
      }
 else       if (CoverageCountStrategy.LEVEL.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getRuleLevel());
      }
 else       if (CoverageCountStrategy.OCCURRENCE.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getOccurrences().size());
      }
 else       if (CoverageCountStrategy.YIELD.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getRuleYield());
      }
 else       if (CoverageCountStrategy.PRODUCT.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * (r.getRuleLevel() * r.getOccurrences().size()));
      }
      marker.setLabelFont(new Font("String_Node_Str",Font.PLAIN,12));
      marker.setLabelPaint(Color.green);
      marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
      marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
      timeseriesPlot.addDomainMarker(marker,Layer.BACKGROUND);
    }
  }
  int sum=0;
  for (  int d : coverageArray)   sum+=d;
  double meanCoverage=1.0d * sum / coverageArray.length;
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String annotationString="String_Node_Str" + minObservedCoverage + "String_Node_Str"+ maxObservedCoverage+ "String_Node_Str"+ df.format(meanCoverage);
  NumberAxis domain=(NumberAxis)this.timeseriesPlot.getDomainAxis();
  Range domainRange=domain.getRange();
  NumberAxis range=(NumberAxis)this.timeseriesPlot.getRangeAxis();
  Range rangeRange=range.getRange();
  XYTextAnnotation a=new XYTextAnnotation(annotationString,domainRange.getLowerBound() + domainRange.getLength() / 100,rangeRange.getLowerBound() + 0.5);
  a.setTextAnchor(TextAnchor.BOTTOM_LEFT);
  a.setPaint(Color.RED);
  a.setOutlinePaint(Color.BLACK);
  a.setOutlineVisible(true);
  a.setFont(new java.awt.Font("String_Node_Str",java.awt.Font.BOLD,14));
  this.timeseriesPlot.addAnnotation(a);
  revalidate();
  repaint();
  this.saveRuleDensityCurve(coverageArray);
}

Fixed version (ground truth):
/** 
 * Puts rules density on show.
 */
private void displayRuleDensity(){
  this.removeAll();
  this.add(chartPanel);
  int maxObservedCoverage=Integer.MIN_VALUE;
  int minObservedCoverage=Integer.MAX_VALUE;
  int[] coverageArray=new int[this.session.chartData.getOriginalTimeseries().length];
  for (  GrammarRuleRecord r : this.session.chartData.getGrammarRules()) {
    if (0 == r.ruleNumber()) {
      continue;
    }
    ArrayList<RuleInterval> occurrences=this.session.chartData.getRulePositionsByRuleNum(r.ruleNumber());
    for (    RuleInterval i : occurrences) {
      int start=i.getStart();
      int end=i.getEnd();
      for (int j=start; j < end; j++) {
        if (CoverageCountStrategy.COUNT.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + 1;
        }
 else         if (CoverageCountStrategy.LEVEL.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleLevel();
        }
 else         if (CoverageCountStrategy.OCCURRENCE.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getOccurrences().size();
        }
 else         if (CoverageCountStrategy.YIELD.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleYield();
        }
 else         if (CoverageCountStrategy.PRODUCT.equals(this.session.countStrategy)) {
          coverageArray[j]=coverageArray[j] + r.getRuleLevel() * r.getOccurrences().size();
        }
        if (maxObservedCoverage < coverageArray[j]) {
          maxObservedCoverage=coverageArray[j];
        }
        if (minObservedCoverage > coverageArray[j]) {
          minObservedCoverage=coverageArray[j];
        }
      }
    }
  }
  double covIncrement=1.0 / (double)maxObservedCoverage;
  for (  GrammarRuleRecord r : this.session.chartData.getGrammarRules()) {
    if (0 == r.ruleNumber()) {
      continue;
    }
    ArrayList<RuleInterval> occurrences=r.getRuleIntervals();
    for (    RuleInterval i : occurrences) {
      IntervalMarker marker=new IntervalMarker(i.getStart(),i.getEnd());
      marker.setLabelOffsetType(LengthAdjustmentType.EXPAND);
      marker.setPaint(Color.BLUE);
      if (CoverageCountStrategy.COUNT.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement);
      }
 else       if (CoverageCountStrategy.LEVEL.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getRuleLevel());
      }
 else       if (CoverageCountStrategy.OCCURRENCE.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getOccurrences().size());
      }
 else       if (CoverageCountStrategy.YIELD.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * r.getRuleYield());
      }
 else       if (CoverageCountStrategy.PRODUCT.equals(this.session.countStrategy)) {
        marker.setAlpha((float)covIncrement * (r.getRuleLevel() * r.getOccurrences().size()));
      }
      marker.setLabelFont(new Font("String_Node_Str",Font.PLAIN,12));
      marker.setLabelPaint(Color.green);
      marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
      marker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
      timeseriesPlot.addDomainMarker(marker,Layer.BACKGROUND);
    }
  }
  int sum=0;
  for (  int d : coverageArray)   sum+=d;
  double meanCoverage=1.0d * sum / coverageArray.length;
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String annotationString="String_Node_Str" + minObservedCoverage + "String_Node_Str"+ maxObservedCoverage+ "String_Node_Str"+ df.format(meanCoverage);
  NumberAxis domain=(NumberAxis)this.timeseriesPlot.getDomainAxis();
  Range domainRange=domain.getRange();
  NumberAxis range=(NumberAxis)this.timeseriesPlot.getRangeAxis();
  Range rangeRange=range.getRange();
  XYTextAnnotation a=new XYTextAnnotation(annotationString,domainRange.getLowerBound() + domainRange.getLength() / 100,rangeRange.getLowerBound() + 0.5);
  a.setTextAnchor(TextAnchor.BOTTOM_LEFT);
  a.setPaint(Color.RED);
  a.setOutlinePaint(Color.BLACK);
  a.setOutlineVisible(true);
  a.setFont(new java.awt.Font("String_Node_Str",java.awt.Font.BOLD,14));
  this.timeseriesPlot.addAnnotation(a);
  revalidate();
  repaint();
  this.saveRuleDensityCurve(coverageArray);
}