HolonElement.java 6.1 KB

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