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