HolonElement.java 5.8 KB

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