1 | package schedframe.resources.units; |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | public class PEUnit extends AbstractResourceUnit { |
---|
7 | |
---|
8 | protected int total; |
---|
9 | protected int used; |
---|
10 | protected int peSpeed; |
---|
11 | |
---|
12 | public PEUnit(PEUnit pe, int total, int used) { |
---|
13 | super(pe); |
---|
14 | this.total = total; |
---|
15 | this.used = used; |
---|
16 | this.peSpeed = 1; |
---|
17 | } |
---|
18 | |
---|
19 | protected PEUnit(){ |
---|
20 | super(StandardResourceUnitName.PE); |
---|
21 | this.peSpeed = 1; |
---|
22 | } |
---|
23 | |
---|
24 | public PEUnit(int total, int used, int avgSpeed){ |
---|
25 | this(); |
---|
26 | this.total = total; |
---|
27 | this.used = used; |
---|
28 | this.peSpeed = avgSpeed; |
---|
29 | } |
---|
30 | |
---|
31 | public PEUnit(String resId, int total, int used) { |
---|
32 | super(StandardResourceUnitName.PE, resId); |
---|
33 | this.total = total; |
---|
34 | this.used = used; |
---|
35 | this.peSpeed = 1; |
---|
36 | } |
---|
37 | |
---|
38 | public void setSpeed(int speed) { |
---|
39 | this.peSpeed = speed; |
---|
40 | } |
---|
41 | |
---|
42 | public int getSpeed(){ |
---|
43 | return this.peSpeed; |
---|
44 | } |
---|
45 | |
---|
46 | public int getFreeAmount() { |
---|
47 | return this.total - this.used; |
---|
48 | } |
---|
49 | |
---|
50 | public int getUsedAmount(){ |
---|
51 | return this.used; |
---|
52 | } |
---|
53 | |
---|
54 | public int getAmount(){ |
---|
55 | return this.total; |
---|
56 | } |
---|
57 | |
---|
58 | public void setUsedAmount(int amount) { |
---|
59 | this.used = amount; |
---|
60 | } |
---|
61 | |
---|
62 | public void reset(){ |
---|
63 | this.used = 0; |
---|
64 | } |
---|
65 | |
---|
66 | public ResourceUnit toDiscrete(){ |
---|
67 | throw new UnsupportedOperationException(); |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | /** |
---|
72 | * Compares processing power of the free processors, which is calculated as product |
---|
73 | * of {@link #getAmount()} * {@link #getProcessorSpeed()} |
---|
74 | * Returns a negative integer, zero, or a positive integer as this object is less |
---|
75 | * than, equal to, or greater than the specified object |
---|
76 | */ |
---|
77 | public int compareTo(ResourceUnit o) { |
---|
78 | if(o instanceof PEUnit){ |
---|
79 | PEUnit pe = (PEUnit) o; |
---|
80 | int p_power = pe.getAmount() * pe.getSpeed(); |
---|
81 | int power = this.getAmount() * this.getSpeed(); |
---|
82 | if(power < p_power) return -1; |
---|
83 | if(power > p_power) return 1; |
---|
84 | return 0; |
---|
85 | } else { |
---|
86 | throw new ClassCastException(); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | public boolean equals(Object o){ |
---|
91 | if(o instanceof PEUnit){ |
---|
92 | if(!super.equals(o)) |
---|
93 | return false; |
---|
94 | PEUnit pe = (PEUnit) o; |
---|
95 | if(pe.getSpeed() != this.getSpeed()) return false; |
---|
96 | return true; |
---|
97 | } else { |
---|
98 | return false; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | public PEUnit replicate (int amount){ |
---|
103 | amount = Math.min(getAmount(), amount); |
---|
104 | PEUnit peUnit = new PEUnit(this, amount, amount); |
---|
105 | return peUnit; |
---|
106 | } |
---|
107 | } |
---|