HolonElement.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package classes;
  2. import java.awt.Point;
  3. import java.util.LinkedList;
  4. import ui.model.IdCounterElem;
  5. /**
  6. * The class "HolonElement" represents any possible element that can be added to
  7. * a CpsObject (such as TV (consumer) or any energy source/producer).
  8. *
  9. * @author Gruppe14
  10. *
  11. */
  12. public class HolonElement {
  13. /* Name of the gadget */
  14. private String eleName;
  15. /* Quantity */
  16. private int amount;
  17. /* Energy per gadget */
  18. private float energy;
  19. /* If the gadget is working xor not (true xor false) */
  20. private boolean active;
  21. /* Total Energy */
  22. private float totalEnergy;
  23. /* +: for Consumers and -: Producers */
  24. private char sign;
  25. /* Place where the Object is Stored */
  26. private String sav;
  27. /* Object where the Element is Stored */
  28. private String obj;
  29. /* Unique Id of the Element */
  30. private int id;
  31. /*
  32. * Energy at each point of the graph with 100 predefined points. At the
  33. * beginning, it starts with all values at energy
  34. */
  35. private float[] energyAt = new float[100];
  36. // Points on the UnitGraph
  37. LinkedList<Point> graphPoints = new LinkedList<>();
  38. /**
  39. * Create a new HolonElement with a user-defined name, amount of the same
  40. * element and energy per element.
  41. *
  42. * @param eleName
  43. * String
  44. * @param amount
  45. * int
  46. * @param energy
  47. * float
  48. */
  49. public HolonElement(String eleName, int amount, float energy) {
  50. setEleName(eleName);
  51. setAmount(amount);
  52. setEnergy(energy);
  53. setActive(true);
  54. setSign(energy);
  55. setEnergyAt(energy);
  56. setId(IdCounterElem.nextId());
  57. }
  58. /**
  59. * Create a copy of the HolonElement given each one a new ID.
  60. *
  61. * @param element
  62. * element to copy
  63. */
  64. public HolonElement(HolonElement element) {
  65. setEleName(element.getEleName());
  66. setAmount(element.getAmount());
  67. setEnergy(element.getEnergy());
  68. setActive(element.getActive());
  69. setSign(element.getEnergy());
  70. setEnergyAt(element.getEnergy());
  71. setSav("CVS");
  72. setObj(element.getObj());
  73. setId(IdCounterElem.nextId());
  74. }
  75. /**
  76. * Get the Array of energy (100 values).
  77. *
  78. * @return energyAt Array of Floats
  79. */
  80. public float[] getEnergyAt() {
  81. return energyAt;
  82. }
  83. /**
  84. * Set energy to any value to the whole array.
  85. *
  86. * @param energy
  87. * the value
  88. */
  89. public void setEnergyAt(float energy) {
  90. for (int i = 0; i < energyAt.length; i++) {
  91. this.energyAt[i] = energy;
  92. }
  93. }
  94. /**
  95. * Set energy to any value at a given position.
  96. *
  97. * @param pos
  98. * int
  99. * @param energy
  100. * float
  101. */
  102. public void setEnergyAt(int pos, float energy) {
  103. this.energyAt[pos] = energy;
  104. }
  105. /**
  106. * Get the user-defined Name.
  107. *
  108. * @return the name String
  109. */
  110. public String getEleName() {
  111. return eleName;
  112. }
  113. /**
  114. * Set the name to any new name.
  115. *
  116. * @param name
  117. * the name to set
  118. */
  119. public void setEleName(String name) {
  120. this.eleName = name;
  121. }
  122. /**
  123. * Get the actual amount of Elements in the selected Object.
  124. *
  125. * @return the amount int
  126. */
  127. public int getAmount() {
  128. return amount;
  129. }
  130. /**
  131. * Set the amount of the Element in the selected Object.
  132. *
  133. * @param amount
  134. * the amount to set
  135. */
  136. public void setAmount(int amount) {
  137. this.amount = amount;
  138. }
  139. /**
  140. * Get the energy value of the selected Element.
  141. *
  142. * @return the energy
  143. */
  144. public float getEnergy() {
  145. return energy;
  146. }
  147. /**
  148. * Set the energy value of the selected Element.
  149. *
  150. * @param energy
  151. * the energy to set
  152. */
  153. public void setEnergy(float energy) {
  154. this.energy = energy;
  155. }
  156. /**
  157. * Get the Status of the Element (see description of variables).
  158. *
  159. * @return the active
  160. */
  161. public boolean getActive() {
  162. return active;
  163. }
  164. /**
  165. * Set the Status of the Element (see description of variables).
  166. *
  167. * @param active
  168. * the active to set
  169. */
  170. public void setActive(boolean active) {
  171. this.active = active;
  172. }
  173. /**
  174. * Multiply the amount of gadgets, given by the user, and the
  175. * consumption/production. If the switch isWorking is turned off for on
  176. * gadget, the energy of this gadget have to be subtracted.
  177. *
  178. * @return totalEnergy (actual)
  179. */
  180. public float getTotalEnergy() {
  181. totalEnergy = ((float) amount) * energy;
  182. return totalEnergy;
  183. }
  184. /**
  185. * Get the energy value at a selected time x.
  186. *
  187. * @param x
  188. * int
  189. * @return energy value
  190. */
  191. public float getTotalEnergyAtTimeStep(int x) {
  192. float result = ((float) amount) * energyAt[x];
  193. return result;
  194. }
  195. /**
  196. * Get the symbol of the value (see variable description).
  197. *
  198. * @return the sign
  199. */
  200. public char getSign() {
  201. return sign;
  202. }
  203. /**
  204. * Set symbol of the value.
  205. *
  206. * @param energy
  207. * the sign to set
  208. */
  209. public void setSign(float energy) {
  210. if (energy < 0)
  211. this.sign = '-';
  212. else
  213. this.sign = '+';
  214. }
  215. /**
  216. * @return the stored.
  217. */
  218. public String getSav() {
  219. return sav;
  220. }
  221. /**
  222. * for save purposes.
  223. *
  224. * @param sav
  225. * the stored to set
  226. */
  227. public void setSav(String sav) {
  228. this.sav = sav;
  229. }
  230. /**
  231. * Get the actual object.
  232. *
  233. * @return the obj
  234. */
  235. public String getObj() {
  236. return obj;
  237. }
  238. /**
  239. * Set the object to a new one.
  240. *
  241. * @param obj
  242. * the obj to set
  243. */
  244. public void setObj(String obj) {
  245. this.obj = obj;
  246. }
  247. /**
  248. * Get the points (values) in the graph.
  249. *
  250. * @return the Graph Points
  251. */
  252. public LinkedList<Point> getGraphPoints() {
  253. return graphPoints;
  254. }
  255. /**
  256. * Set the points (values) in the graph.
  257. *
  258. * @param points
  259. * the Graph points
  260. */
  261. public void setGraphPoints(LinkedList<Point> points) {
  262. this.graphPoints = points;
  263. }
  264. /**
  265. * Set the ID of the HolonElement (one time only).
  266. *
  267. * @param id
  268. * the id
  269. */
  270. private void setId(int id) {
  271. this.id = id;
  272. }
  273. /**
  274. * Get the Id of the selected HolonElement.
  275. *
  276. * @return id the id
  277. */
  278. public int getId() {
  279. return id;
  280. }
  281. }