Program: 32224
Project: 32224
Buggy source:
/** 
 * Insert one @HistogramUnit node into the histogram. Meanwhile it will try to keep the histogram as most @maxHistogramUnitCnt So when inserting one node in, the method will try to find the place to insert as well as minimum interval
 * @param node
 */
private void insertWithTrim(LinkNode<HistogramUnit> node){
  LinkNode<HistogramUnit> insertOpsUnit=null;
  LinkNode<HistogramUnit> minIntervalOpsUnit=null;
  Double minInterval=Double.MAX_VALUE;
  LinkNode<HistogramUnit> tmp=this.tail;
  while (tmp != null) {
    if (insertOpsUnit == null) {
      int res=Double.compare(tmp.data().getHval(),node.data().getHval());
      if (res > 0) {
      }
 else       if (res == 0) {
        tmp.data().setHcnt(tmp.data().getHcnt() + node.data().getHcnt());
        return;
      }
 else       if (res < 0) {
        insertOpsUnit=tmp;
        double interval=node.data().getHval() - tmp.data().getHval();
        if (interval < minInterval) {
          minInterval=interval;
          minIntervalOpsUnit=tmp;
        }
        if (tmp.next() != null) {
          interval=tmp.next().data().getHval() - node.data().getHval();
          if (interval < minInterval) {
            minInterval=interval;
            minIntervalOpsUnit=node;
          }
        }
      }
    }
    if (tmp.next() != null) {
      LinkNode<HistogramUnit> next=tmp.next();
      double interval=next.data().getHval() - tmp.data().getHval();
      if (interval < minInterval) {
        minInterval=interval;
        minIntervalOpsUnit=tmp;
      }
    }
    tmp=tmp.prev();
  }
  if (insertOpsUnit == null) {
    this.header.setPrev(node);
    node.setNext(this.header);
    this.header=node;
  }
 else   if (insertOpsUnit == this.tail) {
    node.setPrev(insertOpsUnit);
    insertOpsUnit.setNext(node);
    this.tail=node;
  }
 else {
    node.setNext(insertOpsUnit.next());
    node.setPrev(insertOpsUnit);
    insertOpsUnit.next().setPrev(node);
    insertOpsUnit.setNext(node);
  }
  if (this.currentHistogramUnitCnt == this.maxHistogramUnitCnt) {
    LinkNode<HistogramUnit> nextNode=minIntervalOpsUnit.next();
    HistogramUnit chu=minIntervalOpsUnit.data();
    HistogramUnit nhu=nextNode.data();
    nhu.setHval((chu.getHval() * chu.getHcnt() + nhu.getHval() * nhu.getHcnt()) / (chu.getHcnt() + nhu.getHcnt()));
    nhu.setHcnt(chu.getHcnt() + nhu.getHcnt());
    removeCurrentNode(minIntervalOpsUnit,nextNode);
  }
 else {
    this.currentHistogramUnitCnt++;
  }
}

Fixed version (ground truth):
/** 
 * Insert one @HistogramUnit node into the histogram. Meanwhile it will try to keep the histogram as most @maxHistogramUnitCnt So when inserting one node in, the method will try to find the place to insert as well as minimum interval
 * @param node
 */
private void insertWithTrim(LinkNode<HistogramUnit> node){
  LinkNode<HistogramUnit> insertOpsUnit=null;
  LinkNode<HistogramUnit> minIntervalOpsUnit=null;
  Double minInterval=Double.MAX_VALUE;
  LinkNode<HistogramUnit> tmp=this.tail;
  while (tmp != null) {
    if (insertOpsUnit == null) {
      int res=Double.compare(tmp.data().getHval(),node.data().getHval());
      if (res > 0) {
      }
 else       if (res == 0) {
        tmp.data().setHcnt(tmp.data().getHcnt() + node.data().getHcnt());
        return;
      }
 else       if (res < 0) {
        insertOpsUnit=tmp;
        double interval=node.data().getHval() - tmp.data().getHval();
        if (interval < minInterval) {
          minInterval=interval;
          minIntervalOpsUnit=tmp;
        }
        if (tmp.next() != null) {
          interval=tmp.next().data().getHval() - node.data().getHval();
          if (interval < minInterval) {
            minInterval=interval;
            minIntervalOpsUnit=node;
          }
        }
      }
    }
    if (tmp.next() != null) {
      LinkNode<HistogramUnit> next=tmp.next();
      double interval=next.data().getHval() - tmp.data().getHval();
      if (interval < minInterval) {
        minInterval=interval;
        minIntervalOpsUnit=tmp;
      }
    }
    tmp=tmp.prev();
  }
  if (insertOpsUnit == null) {
    if (this.header != null) {
      this.header.setPrev(node);
    }
    node.setNext(this.header);
    this.header=node;
    if (this.tail == null) {
      this.tail=node;
    }
  }
 else   if (insertOpsUnit == this.tail) {
    node.setPrev(insertOpsUnit);
    insertOpsUnit.setNext(node);
    this.tail=node;
  }
 else {
    node.setNext(insertOpsUnit.next());
    node.setPrev(insertOpsUnit);
    insertOpsUnit.next().setPrev(node);
    insertOpsUnit.setNext(node);
  }
  if (this.currentHistogramUnitCnt == this.maxHistogramUnitCnt) {
    LinkNode<HistogramUnit> nextNode=minIntervalOpsUnit.next();
    HistogramUnit chu=minIntervalOpsUnit.data();
    HistogramUnit nhu=nextNode.data();
    nhu.setHval((chu.getHval() * chu.getHcnt() + nhu.getHval() * nhu.getHcnt()) / (chu.getHcnt() + nhu.getHcnt()));
    nhu.setHcnt(chu.getHcnt() + nhu.getHcnt());
    removeCurrentNode(minIntervalOpsUnit,nextNode);
  }
 else {
    this.currentHistogramUnitCnt++;
  }
}