KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > tool > reports > PerformanceStatisticsUtil


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.tool.reports;
19
20 import java.util.List JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 public final class PerformanceStatisticsUtil {
24     private PerformanceStatisticsUtil() {
25     }
26
27     public static long getSum(List JavaDoc numList) {
28         long sum = 0;
29         if (numList != null) {
30             for (Iterator JavaDoc i=numList.iterator(); i.hasNext();) {
31                 sum += ((Long JavaDoc)i.next()).longValue();
32             }
33         } else {
34             sum = -1;
35         }
36         return sum;
37     }
38
39     public static long getMin(List JavaDoc numList) {
40         long min = Long.MAX_VALUE;
41         if (numList != null) {
42             for (Iterator JavaDoc i=numList.iterator(); i.hasNext();) {
43                 min = Math.min(((Long JavaDoc)i.next()).longValue(), min);
44             }
45         } else {
46             min = -1;
47         }
48         return min;
49     }
50
51     public static long getMax(List JavaDoc numList) {
52         long max = Long.MIN_VALUE;
53         if (numList != null) {
54             for (Iterator JavaDoc i=numList.iterator(); i.hasNext();) {
55                 max = Math.max(((Long JavaDoc)i.next()).longValue(), max);
56             }
57         } else {
58             max = -1;
59         }
60         return max;
61     }
62
63     public static double getAve(List JavaDoc numList) {
64         double ave;
65         if (numList != null) {
66             int sampleCount = 0;
67             long totalTP = 0;
68             for (Iterator JavaDoc i=numList.iterator(); i.hasNext();) {
69                 sampleCount++;
70                 totalTP += ((Long JavaDoc)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 JavaDoc 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 JavaDoc i=numList.iterator(); i.hasNext();) {
88                 sampleCount++;
89                 sampleTP = ((Long JavaDoc)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