HolonElement.java 6.0 KB

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