View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.statistics.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.jetspeed.statistics.AggregateStatistics;
25  
26  /***
27   * AggregateStatisticsImpl
28   * 
29   * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer </a>
30   * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
31   * @version $Id: $
32   */
33  public class AggregateStatisticsImpl implements AggregateStatistics
34  {
35  
36      private float avgProcessingTime;
37  
38      private float maxProcessingTime;
39  
40      private float minProcessingTime;
41  
42      private float stddevProcessingTime;
43  
44      private int hitcount;
45  
46      private List statlist;
47  
48      public AggregateStatisticsImpl()
49      {
50          statlist = new ArrayList();
51      }
52  
53      public void addRow(Map row)
54      {
55          statlist.add(row);
56      }
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @see org.apache.jetspeed.statistics.AggregateStatistics#getAvgProcessingTime()
62       */
63      public float getAvgProcessingTime()
64      {
65          return this.avgProcessingTime;
66      }
67  
68      /*
69       * (non-Javadoc)
70       * 
71       * @see org.apache.jetspeed.statistics.AggregateStatistics#getHitCount()
72       */
73      public int getHitCount()
74      {
75          return this.hitcount;
76      }
77  
78      /*
79       * (non-Javadoc)
80       * 
81       * @see org.apache.jetspeed.statistics.AggregateStatistics#getMaxProcessingTime()
82       */
83      public float getMaxProcessingTime()
84      {
85          return this.maxProcessingTime;
86      }
87  
88      /*
89       * (non-Javadoc)
90       * 
91       * @see org.apache.jetspeed.statistics.AggregateStatistics#getMinProcessingTime()
92       */
93      public float getMinProcessingTime()
94      {
95          return this.minProcessingTime;
96      }
97  
98  
99      /*
100      * (non-Javadoc)
101      * 
102      * @see org.apache.jetspeed.statistics.AggregateStatistics#setHitCount(int)
103      */
104     public void setHitCount(int hitCount)
105     {
106         
107         this.hitcount = hitCount;
108     }
109 
110     /*
111      * (non-Javadoc)
112      * 
113      * @see org.apache.jetspeed.statistics.AggregateStatistics#setMaxProcessingTime(float)
114      */
115     public void setMaxProcessingTime(float time)
116     {
117         this.maxProcessingTime = Math.round(time);
118     }
119 
120     /*
121      * (non-Javadoc)
122      * 
123      * @see org.apache.jetspeed.statistics.AggregateStatistics#setMinProcessingTime(float)
124      */
125     public void setMinProcessingTime(float time)
126     {
127         this.minProcessingTime = Math.round(time);
128     }
129     
130     /* (non-Javadoc)
131      * @see org.apache.jetspeed.statistics.AggregateStatistics#setAvgProcessingTime(float)
132      */
133     public void setAvgProcessingTime(float time)
134     {
135         this.avgProcessingTime = Math.round(time);
136 
137     }
138 
139 
140     public String toString()
141     {
142         String s = "hit count = " + this.hitcount + "\n";
143         s = s + "max time = " + this.maxProcessingTime + "\n";
144         s = s + "min time = " + this.minProcessingTime + "\n";
145         s = s + "avg time = " + this.avgProcessingTime + "\n";
146         s = s + "stddev   = " + this.stddevProcessingTime + "\n";
147         String listStr ="";
148         Iterator it = this.statlist.iterator();
149         int count = 0;
150         int size = statlist.size();
151         int max = 5;
152         while((it.hasNext()) && (count++<max)) {
153             Object o = it.next();
154             listStr = listStr+"\t"+o+"\n";
155         }
156         if(size > max) {
157             s = s + "\tlist (top "+max+"):\n"+listStr;
158         } else {
159             s = s + "\tlist ("+size+" entries):\n"+listStr;
160         }
161         return s;
162     }
163 
164     /***
165      * @return Returns the statlist.
166      */
167     public List getStatlist()
168     {
169         return statlist;
170     }
171 
172     /***
173      * @param statlist
174      *            The statlist to set.
175      */
176     public void setStatlist(List statlist)
177     {
178         this.statlist = statlist;
179     }
180 }