source: DCWoRMS/trunk/build/classes/dcworms/schedframe/scheduling/queues/AbstractStatsSupportingQueue.java @ 539

Revision 539, 2.0 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package dcworms.schedframe.scheduling.queues;
2
3import java.util.ArrayList;
4import java.util.Collection;
5
6import schedframe.scheduling.queue.Queue;
7
8
9import eduni.simjava.Sim_stat;
10import eduni.simjava.Sim_system;
11
12
13/**
14 *
15 * @author Marcin Krystek
16 *
17 * @param <K>
18 */
19
20public abstract class AbstractStatsSupportingQueue<K> extends ArrayList<K> implements Queue<K>{
21
22        private static final long serialVersionUID = 2067736388365966634L;
23        protected double lastUpdateTime;
24        protected Sim_stat stats;
25        protected String measureName;
26       
27        protected AbstractStatsSupportingQueue(){
28                this.stats = null;
29                this.lastUpdateTime = 0.0;
30                this.measureName = null;
31        }
32       
33        public boolean add(K o) {
34                boolean ret = super.add(o);
35                updateStats();
36                return ret;
37        }
38
39        public void add(int index, K element) {
40                super.add(index, element);
41                updateStats();
42        }
43
44        public boolean addAll(Collection<? extends K> c) {
45                boolean ret = super.addAll(c);
46                updateStats();
47                return ret;
48        }
49
50        public boolean addAll(int index, Collection<? extends K> c) {
51                boolean ret = super.addAll(index, c);
52                updateStats();
53                return ret;
54        }
55
56        public void clear() {
57                super.clear();
58                updateStats();
59        }
60
61        public boolean remove(Object o) {
62                boolean ret = super.remove(o);
63                updateStats();
64                return ret;
65        }
66
67        public K remove(int index) {
68                 K ret = super.remove(index);
69                 updateStats();
70                 return ret;
71        }
72
73        public boolean removeAll(Collection<?> c) {
74                boolean ret = super.removeAll(c);
75                updateStats();
76                return ret;
77        }
78
79        public boolean retainAll(Collection<?> c) {
80                boolean ret = super.retainAll(c);
81                updateStats();
82                return ret;
83        }
84
85        public K set(int index, K element) {
86                K ret = super.set(index, element);
87                updateStats();
88                return ret;
89        }
90       
91       
92        public void setStats(Sim_stat stats, String measureName){
93                this.stats = stats;
94                this.measureName = measureName;
95        }
96       
97        protected void updateStats() {
98                if(stats == null)
99                        return;
100               
101                double time = Sim_system.clock();
102                stats.update(measureName, size(), lastUpdateTime); //continuous
103                lastUpdateTime = time;
104        }
105       
106}
Note: See TracBrowser for help on using the repository browser.