package schedframe.resources.units; import schedframe.resources.units.ResourceUnitType; import schedframe.scheduling.utils.ResourceParameterName; /** * Class representing concrete amount (values) of specific resource unit * * @author Ariel * */ public abstract class ResourceUnit implements Comparable, Cloneable { protected ResourceParameterName unitName; protected ResourceUnitType resourceType;; protected String resourceId; private int id; protected static int id_ = 0; protected synchronized void setId(){ this.id = id_; id_++; } public ResourceUnit(ResourceUnit unit){ this.unitName = unit.unitName; this.resourceType = unit.resourceType; this.resourceId = unit.resourceId; this.id = unit.id; } public ResourceUnit(ResourceParameterName name) { unitName = name; resourceId = ""; resourceType = ResourceUnitType.CONTINUOUS_RESOURCE; setId(); } public ResourceUnit(String resId, ResourceParameterName name) { this(name); resourceId = resId; } public int getId(){ return id; } public ResourceParameterName getName() { return unitName; } public String getResourceId() { return resourceId; } public boolean areValuesUnique(){ return false; } /** * Returns resource unit type; if equals DISCRETE_RESOURCE the DiscreteResourceUnit subclass * must be used to obtain information about specific allocations * @return ResourceUnitType object */ public ResourceUnitType getResourceUnitType() { return this.resourceType; } public String toString(){ return getName() + " total/used/free amount=" + getAmount() + "/" + getUsedAmount() + "/" + getFreeAmount(); } public boolean equals(Object o){ if(o instanceof ResourceUnit){ ResourceUnit unit = (ResourceUnit) o; if(this.unitName != unit.getName()) return false; if(! this.resourceId.equals(unit.getResourceId())) return false; if(this.getFreeAmount() != unit.getFreeAmount()) return false; if(this.getUsedAmount() != unit.getUsedAmount()) return false; return true; } else { return false; } } public Object clone(){ Object obj = null; try { obj = super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } return obj; } public void reset(){}; public abstract int getFreeAmount() ; public abstract int getUsedAmount(); public abstract int getAmount(); public abstract void setUsedAmount(int amount); public abstract ResourceUnit toDiscrete() throws ClassNotFoundException; }