HolonElement.java 6.8 KB

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