private static double average(Iterable<? extends Comparable<?>> data,double start,double end){
  int startFloor=(int)Math.floor(start);
  int startCeil=(int)Math.ceil(start);
  int endFloor=(int)Math.floor(end);
  int endCeil=(int)Math.ceil(end);
  double sum=0.0;
  Iterator<? extends Comparable<?>> dataIterator=data.iterator();
  advance(dataIterator,startFloor);
  for (int i=startFloor; i < endCeil; i++) {
    Number number=(Number)dataIterator.next();
    double val=number.doubleValue();
    if (i == startFloor && startCeil != start) {
      sum+=(startCeil - start) * val;
    }
 else     if (i == endCeil - 1 && endFloor != end) {
      sum+=(end - endFloor) * val;
    }
 else {
      sum+=val;
    }
  }
  return sum / (end - start);
}

private static double average ( Iterable < ? extends Comparable < ? > > data , double start , double end ) { int startFloor = ( int ) Math . floor ( start ) ; int startCeil = ( int ) Math . ceil ( start ) ; int endFloor = ( int ) Math . floor ( end ) ; int endCeil = ( int ) Math . ceil ( end ) ; double sum = 0.0 ; Iterator < ? extends Comparable < ? > > dataIterator = data . iterator ( ) ; advance ( dataIterator , startFloor ) ; for ( int i = startFloor ; i < endCeil ; i ++ ) { Number number = ( Number ) dataIterator . next ( ) ; double val = number . doubleValue ( ) ; if ( i == startFloor && startCeil != start ) { sum += ( startCeil - start ) * val ; } else if ( i == endCeil - 1 && endFloor != end ) { sum += ( end - endFloor ) * val ; } else { sum += val ; } } return sum / ( end - start ) ; }
calculates the arithmetic mean of all values between start and end .
