package classes; import java.util.ArrayList; import java.util.HashMap; import ui.controller.MultiPurposeController; import ui.model.idCounter; public class HolonObject extends CpsObject { /* Array of all consumers */ private ArrayList elements; /* Array of all Indices of Elements*/ private HashMap EleIdx; /* Total of consumption */ private float currentEnergy; /** * State of the building: 0 = fully supplied (currentEnergy == 0) 1 = not * enough energy (currentEnergy > 0) 2 = oversupplied (currentEnergy < 0) */ int state; /** * Constructor Set by default the name of the object equals to the category * name, until the user changes it. */ public HolonObject(String ObjName) { super(ObjName); setElements(new ArrayList()); setEleIdx(new HashMap()); } public HolonObject(String ObjName, String obj) { super(ObjName); super.setName(obj); setElements(new ArrayList()); setEleIdx(new HashMap()); } public HolonObject(CpsObject obj) { super(obj); setEleIdx(MultiPurposeController.copyHashMap(((HolonObject) obj).getEleIdx())); setElements(copyElements(((HolonObject)obj).getElements())); } /** * @return the elements */ public ArrayList getElements() { return elements; } /** * @param elements * the elements to set */ public void setElements(ArrayList elements) { this.elements = elements; } public void addElements(HolonElement element) { elements.add(element); } /** * @return the currentEnergy */ public float getCurrentEnergy() { float temp = 0; for (HolonElement e : getElements()) { if (e.getActive()) { temp = temp + e.getTotalEnergy(); } } currentEnergy = temp; return currentEnergy; } /** * @param currentEnergy * the currentEnergy to set */ public void setCurrentEnergy(float currentEnergy) { this.currentEnergy = currentEnergy; } /** * deletes Element * * @param idx */ public void deleteElement(int idx) { elements.remove(idx); } public float calculateCurrentEnergy() { return currentEnergy; } /** * String of all consumers in this HolonObject * * @return all the names of this HolonObject separated by "," each object */ public String toStringElements() { String objString = "Empty"; for (HolonElement e : elements) { if (objString == "Empty") { objString = e.getEleName(); } else { objString = objString + ", " + e.getEleName(); } } return objString; } /** * @return the eleIdx */ public HashMap getEleIdx() { return EleIdx; } /** * @param eleIdx the eleIdx to set */ public void setEleIdx(HashMap eleIdx) { EleIdx = eleIdx; } /** * Copy all Elements into a New Array * @param arr * @return */ public ArrayList copyElements(ArrayList arr) { ArrayList newArr = new ArrayList<>(); for (HolonElement t : arr) { newArr.add(new HolonElement(t)); } return newArr; } }