source: DCWoRMS/trunk/src/schedframe/resources/units/Memory.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 Memory extends AbstractResourceUnit {
6
7        protected int total;
8        protected int used;
9
10        public Memory(Memory m, int total, int used) {
11                super(m);
12                this.total = total;
13                this.used = used;
14        }
15       
16        public Memory(Memory m) {
17                super(m);
18                this.total = m.total;
19                this.used = m.used;
20        }
21       
22        public Memory(int total, int used) {
23                super(StandardResourceUnitName.MEMORY);
24                this.total = total;
25                this.used = used;
26        }
27       
28        public Memory(String resId, int total, int used) {
29                super(StandardResourceUnitName.MEMORY, resId);
30                this.total = total;
31                this.used = used;
32        }
33
34        public int getFreeAmount() {
35                return this.total - this.used - this.getProvisioner().getPending();
36        }
37
38        public int getUsedAmount(){
39                return this.used;
40        }
41       
42        public void setUsedAmount(int amount){
43                if(amount > this.total){
44                        throw new IllegalArgumentException(
45                                        "Used amount can not be grather then total amount.");
46                }
47                this.used = 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 Memory){
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 Memory){
77                        return super.equals(o);
78                } else {
79                        return false;
80                }
81        }
82
83
84}
85
86
Note: See TracBrowser for help on using the repository browser.