@SuppressWarnings("unchecked") public Intervals(Collection<T> content,Function<T,Double> probs){
  intervals=new Interval[content.size()];
  int i=0;
  double total=0.0f;
  for (  T a : content) {
    double prob=probs.apply(a);
    if (prob == Double.NaN) {
      throw new RuntimeException("probability is NaN: " + a);
    }
    intervals[i++]=new Interval<T>(a,total,total + prob);
    total+=prob;
  }
  if (total < 0.0001) {
    throw new RuntimeException("total prob is null: " + content);
  }
  totalProb=total;
}

@ SuppressWarnings ( "unchecked" ) public Intervals ( Collection < T > content , Function < T , Double > probs ) { intervals = new Interval [ content . size ( ) ] ; int i = 0 ; double total = 0.0f ; for ( T a : content ) { double prob = probs . apply ( a ) ; if ( prob == Double . NaN ) { throw new RuntimeException ( "probability is NaN: " + a ) ; } intervals [ i ++ ] = new Interval < T > ( a , total , total + prob ) ; total += prob ; } if ( total < 0.0001 ) { throw new RuntimeException ( "total prob is null: " + content ) ; } totalProb = total ; }
creates a new interval collection with a collection of values and a function specifying the probability of each value
