123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package classes;
- import java.util.ArrayList;
- public class HolonObject extends CpsObject {
- /* Array of all consumers */
- private ArrayList<HolonElement> elements;
- /* 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<HolonElement>());
- }
- public HolonObject(String ObjName, String obj) {
- super(ObjName);
- super.setName(obj);
- setElements(new ArrayList<HolonElement>());
- }
- public HolonObject(CpsObject obj) {
- super(obj);
- setElements(((HolonObject) obj).getCopyofElements());
- }
- /**
- * @return the elements
- */
- public ArrayList<HolonElement> getElements() {
- return elements;
- }
- /**
- * @param elements
- * the elements to set
- */
- public void setElements(ArrayList<HolonElement> elements) {
- this.elements = elements;
- }
- /**
- * @return the currentEnergy
- */
- public float getCurrentEnergy() {
- 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;
- }
-
- /**
- * Copys the ArrayList
- *
- * @param the ArrayList to Copy
- *
- * @return the currentEnergy
- */
- public ArrayList<HolonElement> getCopyofElements() {
- ArrayList<HolonElement> temp = new ArrayList<>();
- for (HolonElement h : elements) {
- HolonElement he = new HolonElement(h);
- temp.add(he);
- }
- return temp;
- }
- }
|