HolonElement.java 6.0 KB

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