Coverage Report - datafu.pig.stats.QuantileUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
QuantileUtil
81%
13/16
81%
13/16
11
 
 1  
 package datafu.pig.stats;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 
 5  0
 public class QuantileUtil
 6  
 { 
 7  
   public static ArrayList<Double> getQuantilesFromParams(String... k)
 8  
   {
 9  5103
     ArrayList<Double> quantiles = new ArrayList<Double>(k.length);
 10  22152
     for (String s : k) { 
 11  17049
       quantiles.add(Double.parseDouble(s));
 12  
     }
 13  
     
 14  5103
     if (quantiles.size() == 1 && quantiles.get(0) > 1.0)
 15  
     {
 16  1090
       int numQuantiles = Integer.parseInt(k[0]);
 17  1090
       if (numQuantiles < 1)
 18  
       {
 19  0
         throw new IllegalArgumentException("Number of quantiles must be greater than 1");
 20  
       }
 21  
       
 22  1090
       quantiles = new ArrayList<Double>(numQuantiles);
 23  6540
       for (double d = 0.0; d <= 1.0; d += 1.0/(numQuantiles-1))
 24  
       {
 25  5450
         quantiles.add(d);
 26  
       }
 27  1090
     }
 28  
     else
 29  
     {
 30  4013
       for (Double d : quantiles)
 31  
       {
 32  15959
         if (d < 0.0 || d > 1.0)
 33  
         {
 34  0
           throw new IllegalArgumentException("Quantile must be between 0.0 and 1.0");
 35  
         }
 36  
       }
 37  
     }
 38  
     
 39  5103
     return quantiles;
 40  
   }
 41  
 }