1 17 18 package org.objectweb.jac.lib.stats; 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.core.rtti.FieldItem; 24 25 29 public class Stats { 30 static Logger logger = Logger.getLogger("stats"); 31 32 41 public static void computeStats(Stat stats, Collection items, FieldItem field) { 42 double average = 0; 43 double sum = 0; 44 double max = 0; 45 double min = 0; 46 long count = 0; 47 long pos = 0; 48 Iterator it = items.iterator(); 49 while (it.hasNext()) { 50 Object item = it.next(); 51 if (item!=null) { 52 double value = ((Number )field.getThroughAccessor(item)).doubleValue(); 53 stats.sum += value; 54 if (count==0 || value<stats.min) 55 stats.min = value; 56 if (count==0 || value>stats.max) 57 stats.max = value; 58 stats.count++; 59 } else { 60 logger.error("computeStats "+field+": null element in collection at position "+pos); 61 } 62 pos++; 63 } 64 } 65 66 public static Stat computeStats(Collection items, FieldItem field) { 67 Stat stat = new Stat(); 68 computeStats(stat,items,field); 69 return stat; 70 } 71 } 72 | Popular Tags |