1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.statistic;
22
23
24
25 /***
26 * TODO Add docs
27 *
28 * Created on 13.12.2004
29 * Contributing Author(s):
30 *
31 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
32 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
33 *
34 * @author vlads
35 * @version $Revision: 1.6 $ ($Author: vlads $) $Date: 2004/12/17 04:17:21 $
36 */
37 public class TimeBaseAccumulationList extends AccumulationItmesList {
38
39 public static final String ATTRIBUTE_TIME_START = "TimeBaseAccumulationList.TIME_START";
40 public static final String ATTRIBUTE_NAME = "TimeBaseAccumulationList.NAME";
41
42
43
44 private long timeFrame = 1000 * 60 * 1 / 4;
45
46 public String getName() {
47 return (String)getAttribute(ATTRIBUTE_NAME);
48 }
49
50 public void setName(String name) {
51 setAttribute(ATTRIBUTE_NAME, name);
52 }
53
54
55
56
57 public long roundTimeStamp(double millis) {
58 double f = (millis) / (this.timeFrame);
59 return this.timeFrame * new Double(Math.floor(f)).longValue();
60 }
61
62 public Object timeStampKey(double timeMillis) {
63 return new Long(roundTimeStamp(timeMillis));
64 }
65
66 public void onNewAccumulation(Object key, Accumulation accumulation) {
67 super.onNewAccumulation(key, accumulation);
68 accumulation.setAttribute(ATTRIBUTE_TIME_START , key);
69 }
70
71 public void add(double timeMillis, Object num) {
72 super.add(timeStampKey(timeMillis), num);
73 }
74
75 public MillisecondsPeriod getPeriod(Object key) {
76 return new MillisecondsPeriod( ((Long)key).longValue(), this.timeFrame);
77 }
78
79 public double getCallPerMinute(Object key) {
80 Accumulation acc = getItem(key);
81 return ((double) acc.getCount() * 1000.0 * 60) / (this.timeFrame);
82 }
83 /***
84 * @return Returns the timeFrame, millis.
85 */
86 public long getTimeFrame() {
87 return this.timeFrame;
88 }
89 /***
90 * @param timeFrame The timeFrame to set, millis.
91 */
92 public void setTimeFrame(long timeFrame) {
93 if (timeFrame != 0) {
94 this.timeFrame = timeFrame;
95 }
96 }
97 }