HolonObject.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package classes;
  2. import java.util.ArrayList;
  3. public class HolonObject extends CpsObject {
  4. /* Array of all consumers */
  5. private ArrayList<HolonElement> elements;
  6. /* Total of consumption */
  7. private float currentEnergy;
  8. /**
  9. * State of the building: 0 = fully supplied (currentEnergy == 0) 1 = not
  10. * enough energy (currentEnergy > 0) 2 = oversupplied (currentEnergy < 0)
  11. */
  12. int state;
  13. /**
  14. * Constructor Set by default the name of the object equals to the category
  15. * name, until the user changes it.
  16. */
  17. public HolonObject(String ObjName) {
  18. super(ObjName);
  19. setElements(new ArrayList<HolonElement>());
  20. }
  21. public HolonObject(String ObjName, String obj) {
  22. super(ObjName);
  23. super.setName(obj);
  24. setElements(new ArrayList<HolonElement>());
  25. }
  26. public HolonObject(CpsObject obj) {
  27. super(obj);
  28. setElements(((HolonObject) obj).getCopyofElements());
  29. }
  30. /**
  31. * @return the elements
  32. */
  33. public ArrayList<HolonElement> getElements() {
  34. return elements;
  35. }
  36. /**
  37. * @param elements
  38. * the elements to set
  39. */
  40. public void setElements(ArrayList<HolonElement> elements) {
  41. this.elements = elements;
  42. }
  43. /**
  44. * @return the currentEnergy
  45. */
  46. public float getCurrentEnergy() {
  47. return currentEnergy;
  48. }
  49. /**
  50. * @param currentEnergy
  51. * the currentEnergy to set
  52. */
  53. public void setCurrentEnergy(float currentEnergy) {
  54. this.currentEnergy = currentEnergy;
  55. }
  56. /**
  57. * deletes Element
  58. *
  59. * @param idx
  60. */
  61. public void deleteElement(int idx) {
  62. elements.remove(idx);
  63. }
  64. public float calculateCurrentEnergy() {
  65. return currentEnergy;
  66. }
  67. /**
  68. * String of all consumers in this HolonObject
  69. *
  70. * @return all the names of this HolonObject separated by "," each object
  71. */
  72. public String toStringElements() {
  73. String objString = "Empty";
  74. for (HolonElement e : elements) {
  75. if (objString == "Empty") {
  76. objString = e.getEleName();
  77. } else {
  78. objString = objString + ", " + e.getEleName();
  79. }
  80. }
  81. return objString;
  82. }
  83. /**
  84. * Copys the ArrayList
  85. *
  86. * @param the ArrayList to Copy
  87. *
  88. * @return the currentEnergy
  89. */
  90. public ArrayList<HolonElement> getCopyofElements() {
  91. ArrayList<HolonElement> temp = new ArrayList<>();
  92. for (HolonElement h : elements) {
  93. HolonElement he = new HolonElement(h);
  94. temp.add(he);
  95. }
  96. return temp;
  97. }
  98. }