source: xssim/trunk/src/schedframe/resources/units/CpuSpeed.java @ 104

Revision 104, 1.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.units;
2
3import schedframe.scheduling.utils.ResourceParameterName;
4
5/**
6 *
7 * @author Marcin Krystek
8 *
9 */
10public class CpuSpeed extends ResourceUnit{
11
12        protected int total;
13        protected int used;
14       
15        public CpuSpeed(CpuSpeed m) {
16                super(m);
17                this.total = m.total;
18                this.used = m.used;
19        }
20       
21        public CpuSpeed(int total, int used) {
22                super(ResourceParameterName.CPUSPEED);
23                this.total = total;
24                this.used = used;
25        }
26       
27        public CpuSpeed(String resId, int total, int used) {
28                super(resId, ResourceParameterName.CPUSPEED);
29                this.total = total;
30                this.used = used;
31        }
32       
33        public int getFreeAmount() {
34                return this.total - this.used;
35        }
36
37        public int getUsedAmount(){
38                return this.used;
39        }
40       
41        public void setUsedAmount(int amount){
42                this.used = amount;
43        }
44       
45        public void setAmount(int amount){
46                this.total = amount;
47        }
48
49        public int getAmount(){
50                return this.total;
51        }
52
53        public ResourceUnit toDiscrete() throws ClassNotFoundException {
54                throw new ClassNotFoundException("There is no distinguish class version for "
55                                                                                + getClass().getName());
56        }
57
58        /**
59         * Comparing two Memory objects is equivalent to
60         * comparing the free amount of the resource. See {@link #getAmount()}
61         */
62        public int compareTo(ResourceUnit o) {
63                if(o instanceof CpuSpeed){
64                        int free = total - used;
65                        if(free < o.getFreeAmount()) return -1;
66                        if(free > o.getFreeAmount()) return 1;
67                        return 0;
68                } else {
69                        throw new IllegalArgumentException(o + " is not an instance of " +
70                                                                                        "memory resource unit.");
71                }
72        }
73
74        public boolean equals(Object o){
75                if(o instanceof CpuSpeed){
76                        return super.equals(o);
77                } else {
78                        return false;
79                }
80        }
81
82}
Note: See TracBrowser for help on using the repository browser.