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.jetspeed.statistics.impl;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.jetspeed.statistics.AggregateStatistics;
025:
026: /**
027: * AggregateStatisticsImpl
028: *
029: * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer </a>
030: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
031: * @version $Id: $
032: */
033: public class AggregateStatisticsImpl implements AggregateStatistics {
034:
035: private float avgProcessingTime;
036:
037: private float maxProcessingTime;
038:
039: private float minProcessingTime;
040:
041: private float stddevProcessingTime;
042:
043: private int hitcount;
044:
045: private List statlist;
046:
047: public AggregateStatisticsImpl() {
048: statlist = new ArrayList();
049: }
050:
051: public void addRow(Map row) {
052: statlist.add(row);
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see org.apache.jetspeed.statistics.AggregateStatistics#getAvgProcessingTime()
059: */
060: public float getAvgProcessingTime() {
061: return this .avgProcessingTime;
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see org.apache.jetspeed.statistics.AggregateStatistics#getHitCount()
068: */
069: public int getHitCount() {
070: return this .hitcount;
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see org.apache.jetspeed.statistics.AggregateStatistics#getMaxProcessingTime()
077: */
078: public float getMaxProcessingTime() {
079: return this .maxProcessingTime;
080: }
081:
082: /*
083: * (non-Javadoc)
084: *
085: * @see org.apache.jetspeed.statistics.AggregateStatistics#getMinProcessingTime()
086: */
087: public float getMinProcessingTime() {
088: return this .minProcessingTime;
089: }
090:
091: /*
092: * (non-Javadoc)
093: *
094: * @see org.apache.jetspeed.statistics.AggregateStatistics#setHitCount(int)
095: */
096: public void setHitCount(int hitCount) {
097:
098: this .hitcount = hitCount;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see org.apache.jetspeed.statistics.AggregateStatistics#setMaxProcessingTime(float)
105: */
106: public void setMaxProcessingTime(float time) {
107: this .maxProcessingTime = Math.round(time);
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see org.apache.jetspeed.statistics.AggregateStatistics#setMinProcessingTime(float)
114: */
115: public void setMinProcessingTime(float time) {
116: this .minProcessingTime = Math.round(time);
117: }
118:
119: /* (non-Javadoc)
120: * @see org.apache.jetspeed.statistics.AggregateStatistics#setAvgProcessingTime(float)
121: */
122: public void setAvgProcessingTime(float time) {
123: this .avgProcessingTime = Math.round(time);
124:
125: }
126:
127: public String toString() {
128: String s = "hit count = " + this .hitcount + "\n";
129: s = s + "max time = " + this .maxProcessingTime + "\n";
130: s = s + "min time = " + this .minProcessingTime + "\n";
131: s = s + "avg time = " + this .avgProcessingTime + "\n";
132: s = s + "stddev = " + this .stddevProcessingTime + "\n";
133: String listStr = "";
134: Iterator it = this .statlist.iterator();
135: int count = 0;
136: int size = statlist.size();
137: int max = 5;
138: while ((it.hasNext()) && (count++ < max)) {
139: Object o = it.next();
140: listStr = listStr + "\t" + o + "\n";
141: }
142: if (size > max) {
143: s = s + "\tlist (top " + max + "):\n" + listStr;
144: } else {
145: s = s + "\tlist (" + size + " entries):\n" + listStr;
146: }
147: return s;
148: }
149:
150: /**
151: * @return Returns the statlist.
152: */
153: public List getStatlist() {
154: return statlist;
155: }
156:
157: /**
158: * @param statlist
159: * The statlist to set.
160: */
161: public void setStatlist(List statlist) {
162: this.statlist = statlist;
163: }
164: }
|