001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.tool.reports; 018 019 import java.util.Iterator; 020 import java.util.List; 021 022 public final class PerformanceStatisticsUtil { 023 private PerformanceStatisticsUtil() { 024 } 025 026 public static long getSum(List numList) { 027 long sum = 0; 028 if (numList != null) { 029 for (Iterator i = numList.iterator(); i.hasNext();) { 030 sum += ((Long)i.next()).longValue(); 031 } 032 } else { 033 sum = -1; 034 } 035 return sum; 036 } 037 038 public static long getMin(List numList) { 039 long min = Long.MAX_VALUE; 040 if (numList != null) { 041 for (Iterator i = numList.iterator(); i.hasNext();) { 042 min = Math.min(((Long)i.next()).longValue(), min); 043 } 044 } else { 045 min = -1; 046 } 047 return min; 048 } 049 050 public static long getMax(List numList) { 051 long max = Long.MIN_VALUE; 052 if (numList != null) { 053 for (Iterator i = numList.iterator(); i.hasNext();) { 054 max = Math.max(((Long)i.next()).longValue(), max); 055 } 056 } else { 057 max = -1; 058 } 059 return max; 060 } 061 062 public static double getAve(List numList) { 063 double ave; 064 if (numList != null) { 065 int sampleCount = 0; 066 long totalTP = 0; 067 for (Iterator i = numList.iterator(); i.hasNext();) { 068 sampleCount++; 069 totalTP += ((Long)i.next()).longValue(); 070 } 071 return (double)totalTP / (double)sampleCount; 072 } else { 073 ave = -1; 074 } 075 return ave; 076 } 077 078 public static double getAveEx(List numList) { 079 double ave; 080 long minTP = getMin(numList); 081 long maxTP = getMax(numList); 082 if (numList != null) { 083 int sampleCount = 0; 084 long totalTP = 0; 085 long sampleTP; 086 for (Iterator i = numList.iterator(); i.hasNext();) { 087 sampleCount++; 088 sampleTP = ((Long)i.next()).longValue(); 089 if (sampleTP != minTP && sampleTP != maxTP) { 090 totalTP += sampleTP; 091 } 092 } 093 return (double)totalTP / (double)sampleCount; 094 } else { 095 ave = -1; 096 } 097 return ave; 098 } 099 100 }