[477] | 1 | package schedframe.resources.computing; |
---|
| 2 | |
---|
| 3 | import java.util.ArrayList; |
---|
| 4 | import java.util.HashMap; |
---|
| 5 | import java.util.List; |
---|
| 6 | import java.util.Map; |
---|
| 7 | |
---|
| 8 | import schedframe.Parameters; |
---|
| 9 | import schedframe.resources.computing.location.Location; |
---|
| 10 | import schedframe.resources.units.ResourceUnit; |
---|
| 11 | import schedframe.resources.units.ResourceUnitName; |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | public class ResourceCharacteristics /*extends Properties*/{ |
---|
| 15 | |
---|
| 16 | private static final long serialVersionUID = 2719535186621622647L; |
---|
| 17 | |
---|
| 18 | protected Map<ResourceUnitName, List<ResourceUnit>> resUnits; |
---|
| 19 | protected Parameters parameters; |
---|
| 20 | protected Location location; |
---|
| 21 | |
---|
| 22 | /*public ResourceCharacteristics(Map<ResourceUnitName, List<AbstractResourceUnit>> resUnits){ |
---|
| 23 | this.resUnits = resUnits; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public ResourceCharacteristics(){ |
---|
| 27 | this.resUnits = null; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | public ResourceCharacteristics(Map<ResourceUnitName, List<AbstractResourceUnit>> resUnits, Parameters parameters){ |
---|
| 31 | this(resUnits); |
---|
| 32 | }*/ |
---|
| 33 | |
---|
| 34 | public Map<ResourceUnitName, List<ResourceUnit>> getResourceUnits() { |
---|
| 35 | if(resUnits == null) |
---|
| 36 | return new HashMap<ResourceUnitName, List<ResourceUnit>>(); |
---|
| 37 | return resUnits; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | public ResourceUnit getResourceUnit(ResourceUnitName unitName) throws NoSuchFieldException{ |
---|
| 41 | if(getResourceUnits().containsKey(unitName)) |
---|
| 42 | return getResourceUnits().get(unitName).get(0); |
---|
| 43 | else throw new NoSuchFieldException("Resource unit " + unitName + |
---|
| 44 | " is not available in this resource "); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public void addResourceUnit(ResourceUnit unit){ |
---|
| 48 | if(resUnits == null){ |
---|
| 49 | resUnits = new HashMap<ResourceUnitName, List<ResourceUnit>>(2); |
---|
| 50 | } |
---|
| 51 | List<ResourceUnit> list = null; |
---|
| 52 | if(resUnits.containsKey(unit.getName())){ |
---|
| 53 | list = resUnits.get(unit.getName()); |
---|
| 54 | } else { |
---|
| 55 | list = new ArrayList<ResourceUnit>(1); |
---|
| 56 | resUnits.put(unit.getName(), list); |
---|
| 57 | } |
---|
| 58 | list.add(unit); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | public static class Builder { |
---|
| 63 | |
---|
| 64 | protected Map<ResourceUnitName, List<ResourceUnit>> resUnits; |
---|
| 65 | protected Location location; |
---|
| 66 | protected Parameters parameters; |
---|
| 67 | |
---|
| 68 | public Builder location(Location params){this.location = params; return this; } |
---|
| 69 | public Builder parameters(Parameters prop){this.parameters = prop; return this; } |
---|
| 70 | public Builder resourceUnits(Map<ResourceUnitName, List<ResourceUnit>> units){this.resUnits = units; return this; } |
---|
| 71 | public Builder resourceUnits(){this.resUnits = new HashMap<ResourceUnitName, List<ResourceUnit>>(2); return this; } |
---|
| 72 | |
---|
| 73 | public ResourceCharacteristics build() { |
---|
| 74 | return new ResourceCharacteristics(this); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | private ResourceCharacteristics(Builder builder) { |
---|
| 79 | this.location = builder.location; |
---|
| 80 | this.parameters = builder.parameters; |
---|
| 81 | this.resUnits = builder.resUnits; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public Parameters getParameters() { |
---|
| 85 | return parameters; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | public Location getLocation() { |
---|
| 89 | return location; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | } |
---|