source: DCWoRMS/branches/coolemall/src/schedframe/resources/units/CpuSpeed.java @ 477

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