1 | package schedframe.resources.units; |
---|
2 | |
---|
3 | import schedframe.resources.units.ResourceUnitType; |
---|
4 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
5 | |
---|
6 | /** |
---|
7 | * Class representing concrete amount (values) of specific resource unit |
---|
8 | * |
---|
9 | * @author Ariel |
---|
10 | * |
---|
11 | */ |
---|
12 | public abstract class ResourceUnit implements Comparable<ResourceUnit>, Cloneable { |
---|
13 | |
---|
14 | protected ResourceParameterName unitName; |
---|
15 | |
---|
16 | protected ResourceUnitType resourceType;; |
---|
17 | |
---|
18 | protected String resourceId; |
---|
19 | |
---|
20 | |
---|
21 | private int id; |
---|
22 | |
---|
23 | protected static int id_ = 0; |
---|
24 | |
---|
25 | |
---|
26 | protected synchronized void setId(){ |
---|
27 | this.id = id_; |
---|
28 | id_++; |
---|
29 | } |
---|
30 | |
---|
31 | public ResourceUnit(ResourceUnit unit){ |
---|
32 | this.unitName = unit.unitName; |
---|
33 | this.resourceType = unit.resourceType; |
---|
34 | this.resourceId = unit.resourceId; |
---|
35 | this.id = unit.id; |
---|
36 | } |
---|
37 | |
---|
38 | public ResourceUnit(ResourceParameterName name) { |
---|
39 | unitName = name; |
---|
40 | resourceId = ""; |
---|
41 | resourceType = ResourceUnitType.CONTINUOUS_RESOURCE; |
---|
42 | setId(); |
---|
43 | } |
---|
44 | |
---|
45 | public ResourceUnit(String resId, ResourceParameterName name) { |
---|
46 | this(name); |
---|
47 | resourceId = resId; |
---|
48 | } |
---|
49 | |
---|
50 | public int getId(){ |
---|
51 | return id; |
---|
52 | } |
---|
53 | |
---|
54 | public ResourceParameterName getName() { |
---|
55 | return unitName; |
---|
56 | } |
---|
57 | |
---|
58 | public String getResourceId() { |
---|
59 | return resourceId; |
---|
60 | } |
---|
61 | |
---|
62 | public boolean areValuesUnique(){ |
---|
63 | return false; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Returns resource unit type; if equals DISCRETE_RESOURCE the DiscreteResourceUnit subclass |
---|
68 | * must be used to obtain information about specific allocations |
---|
69 | * @return ResourceUnitType object |
---|
70 | */ |
---|
71 | public ResourceUnitType getResourceUnitType() { |
---|
72 | return this.resourceType; |
---|
73 | } |
---|
74 | |
---|
75 | public String toString(){ |
---|
76 | return getName() + " total/used/free amount=" + getAmount() + "/" + getUsedAmount() + "/" + getFreeAmount(); |
---|
77 | } |
---|
78 | |
---|
79 | public boolean equals(Object o){ |
---|
80 | if(o instanceof ResourceUnit){ |
---|
81 | ResourceUnit unit = (ResourceUnit) o; |
---|
82 | if(this.unitName != unit.getName()) return false; |
---|
83 | if(! this.resourceId.equals(unit.getResourceId())) return false; |
---|
84 | if(this.getFreeAmount() != unit.getFreeAmount()) return false; |
---|
85 | if(this.getUsedAmount() != unit.getUsedAmount()) return false; |
---|
86 | return true; |
---|
87 | } else { |
---|
88 | return false; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | public Object clone(){ |
---|
93 | Object obj = null; |
---|
94 | try { |
---|
95 | obj = super.clone(); |
---|
96 | } catch (CloneNotSupportedException e) { |
---|
97 | e.printStackTrace(); |
---|
98 | } |
---|
99 | return obj; |
---|
100 | } |
---|
101 | |
---|
102 | public void reset(){}; |
---|
103 | |
---|
104 | public abstract int getFreeAmount() ; |
---|
105 | |
---|
106 | public abstract int getUsedAmount(); |
---|
107 | |
---|
108 | public abstract int getAmount(); |
---|
109 | |
---|
110 | public abstract void setUsedAmount(int amount); |
---|
111 | |
---|
112 | public abstract ResourceUnit toDiscrete() throws ClassNotFoundException; |
---|
113 | |
---|
114 | } |
---|