1 18 package org.apache.activemq.tool.reports; 19 20 import java.util.List ; 21 import java.util.Iterator ; 22 23 public final class PerformanceStatisticsUtil { 24 private PerformanceStatisticsUtil() { 25 } 26 27 public static long getSum(List numList) { 28 long sum = 0; 29 if (numList != null) { 30 for (Iterator i=numList.iterator(); i.hasNext();) { 31 sum += ((Long )i.next()).longValue(); 32 } 33 } else { 34 sum = -1; 35 } 36 return sum; 37 } 38 39 public static long getMin(List numList) { 40 long min = Long.MAX_VALUE; 41 if (numList != null) { 42 for (Iterator i=numList.iterator(); i.hasNext();) { 43 min = Math.min(((Long )i.next()).longValue(), min); 44 } 45 } else { 46 min = -1; 47 } 48 return min; 49 } 50 51 public static long getMax(List numList) { 52 long max = Long.MIN_VALUE; 53 if (numList != null) { 54 for (Iterator i=numList.iterator(); i.hasNext();) { 55 max = Math.max(((Long )i.next()).longValue(), max); 56 } 57 } else { 58 max = -1; 59 } 60 return max; 61 } 62 63 public static double getAve(List numList) { 64 double ave; 65 if (numList != null) { 66 int sampleCount = 0; 67 long totalTP = 0; 68 for (Iterator i=numList.iterator(); i.hasNext();) { 69 sampleCount++; 70 totalTP += ((Long )i.next()).longValue(); 71 } 72 return (double)totalTP / (double)sampleCount; 73 } else { 74 ave = -1; 75 } 76 return ave; 77 } 78 79 public static double getAveEx(List numList) { 80 double ave; 81 long minTP = getMin(numList); 82 long maxTP = getMax(numList); 83 if (numList != null) { 84 int sampleCount = 0; 85 long totalTP = 0; 86 long sampleTP; 87 for (Iterator i=numList.iterator(); i.hasNext();) { 88 sampleCount++; 89 sampleTP = ((Long )i.next()).longValue(); 90 if (sampleTP != minTP && sampleTP != maxTP) { 91 totalTP += sampleTP; 92 } 93 } 94 return (double)totalTP / (double)sampleCount; 95 } else { 96 ave = -1; 97 } 98 return ave; 99 } 100 101 } 102 | Popular Tags |