HolonElement.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package classes;
  2. import java.awt.Point;
  3. import java.util.LinkedList;
  4. import ui.model.idCounterElem;
  5. public class HolonElement {
  6. /* Name of the gadget */
  7. String eleName;
  8. /* Quantity */
  9. int amount;
  10. /* Energy per gadget */
  11. float energy;
  12. /* If the gadget is working xor not (true xor false) */
  13. boolean active;
  14. /* Total Energy */
  15. float totalEnergy;
  16. /* Path of the image for the Obj. */
  17. String image;
  18. /* +: for Consumers and -: Producers */
  19. char sign;
  20. /* Place where the Object is Stored */
  21. String sav;
  22. /* Object where the Element is Stored */
  23. String obj;
  24. int id;
  25. /*
  26. * Energy at each point of the graph with 100 predefined points. At the
  27. * beginning, it starts with all values at energy
  28. */
  29. float[] energyAt = new float[100];
  30. // Points on the UnitGraph
  31. LinkedList<Point> graphPoints = new LinkedList<>();
  32. public HolonElement(String eleName, int amount, float energy) {
  33. setEleName(eleName);
  34. setAmount(amount);
  35. setEnergy(energy);
  36. setActive(true);
  37. setSign(energy);
  38. setEnergyAt(energy);
  39. setId(idCounterElem.nextId());
  40. }
  41. public HolonElement(HolonElement element) {
  42. setEleName(element.getEleName());
  43. setAmount(element.getAmount());
  44. setEnergy(element.getEnergy());
  45. setActive(element.getActive());
  46. setSign(element.getEnergy());
  47. setEnergyAt(element.getEnergy());
  48. setSav("CVS");
  49. setObj(element.getObj());
  50. setId(idCounterElem.nextId());
  51. }
  52. /**
  53. * get the EnergyAt Array
  54. */
  55. public float[] getEnergyAt() {
  56. return energyAt;
  57. }
  58. /**
  59. * @param energy,
  60. * the value
  61. */
  62. public void setEnergyAt(float energy) {
  63. for (int i = 0; i < energyAt.length; i++) {
  64. this.energyAt[i] = energy;
  65. }
  66. }
  67. public void setEnergyAt(int pos, float energy) {
  68. this.energyAt[pos] = energy;
  69. }
  70. /**
  71. * @return the name
  72. */
  73. public String getEleName() {
  74. return eleName;
  75. }
  76. /**
  77. * @param name
  78. * the name to set
  79. */
  80. public void setEleName(String name) {
  81. this.eleName = name;
  82. }
  83. /**
  84. * @return the amount
  85. */
  86. public int getAmount() {
  87. return amount;
  88. }
  89. /**
  90. * @param amount
  91. * the amount to set
  92. */
  93. public void setAmount(int amount) {
  94. this.amount = amount;
  95. }
  96. /**
  97. * @return the energy
  98. */
  99. public float getEnergy() {
  100. return energy;
  101. }
  102. /**
  103. * @param energy
  104. * the energy to set
  105. */
  106. public void setEnergy(float energy) {
  107. this.energy = energy;
  108. }
  109. /**
  110. * @return the active
  111. */
  112. public boolean getActive() {
  113. return active;
  114. }
  115. /**
  116. * @param active
  117. * the active to set
  118. */
  119. public void setActive(boolean active) {
  120. this.active = active;
  121. }
  122. /**
  123. * @return the image
  124. */
  125. public String getImage() {
  126. return image;
  127. }
  128. /**
  129. * @param image
  130. * the image to set
  131. */
  132. public void setImage(String image) {
  133. this.image = image;
  134. }
  135. /**
  136. * Multiply the amount of gadgets, given by the user, and the
  137. * consumption/production. If the switch isWorking is turned off for on
  138. * gadget, the energy of this gadget have to be subtracted
  139. *
  140. * @return totalEnergy (actual)
  141. */
  142. public float getTotalEnergy() {
  143. totalEnergy = ((float) amount) * energy;
  144. return totalEnergy;
  145. }
  146. public float getTotalEnergyAtTimeStep(int x) {
  147. float result = ((float) amount) * energyAt[x];
  148. return result;
  149. }
  150. /**
  151. * @return the sign
  152. */
  153. public char getSign() {
  154. return sign;
  155. }
  156. /**
  157. * @param energy
  158. * the sign to set
  159. */
  160. public void setSign(float energy) {
  161. if (energy < 0)
  162. this.sign = '-';
  163. else
  164. this.sign = '+';
  165. }
  166. /**
  167. * @return the stored
  168. */
  169. public String getSav() {
  170. return sav;
  171. }
  172. /**
  173. * @param stored
  174. * the stored to set
  175. */
  176. public void setSav(String sav) {
  177. this.sav = sav;
  178. }
  179. /**
  180. * @return the obj
  181. */
  182. public String getObj() {
  183. return obj;
  184. }
  185. /**
  186. * @param obj
  187. * the obj to set
  188. */
  189. public void setObj(String obj) {
  190. this.obj = obj;
  191. }
  192. /**
  193. * @return the Graph Points
  194. */
  195. public LinkedList<Point> getGraphPoints() {
  196. return graphPoints;
  197. }
  198. /**
  199. * @param points,
  200. * the Graph points
  201. */
  202. public void setGraphPoints(LinkedList<Point> points) {
  203. this.graphPoints = points;
  204. }
  205. private void setId(int id) {
  206. this.id = id;
  207. }
  208. public int getId() {
  209. return id;
  210. }
  211. }