CpsEdge.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package classes;
  2. import java.util.ArrayList;
  3. /**
  4. * The class "CpsEdge" represents the connections on the GUI. Each connection
  5. * contains a max. capacity, a flow, a status (isWorking), tags (for internal
  6. * use of electricity flow), source and destination
  7. *
  8. * @author Gruppe14
  9. *
  10. */
  11. public class CpsEdge {
  12. // Max. capacity of the Edge, if flow is greater than the status --> is
  13. // Working would be false
  14. float maxCapacity;
  15. // Current flow of electricity (through the edge)
  16. float flow;
  17. /*
  18. * Represents the actual status of the Edge (true = flows electricity; false
  19. * = no flow of electricity) State represents the real status of the edge If
  20. * it breaks --> stay ruin no matter the actual scenario The only way to
  21. * repair it is through manual change (setStateEdge)
  22. */
  23. boolean isWorking;
  24. // for internal use --> flow of electricity (simulation state)
  25. ArrayList<Integer> tags;
  26. // Source
  27. AbstractCpsObject a;
  28. // Destination
  29. AbstractCpsObject b;
  30. /**
  31. * Constructor without max. capacity (by default as 100)
  32. *
  33. * @param a
  34. * Source
  35. * @param b
  36. * Destination
  37. */
  38. public CpsEdge(AbstractCpsObject a, AbstractCpsObject b) {
  39. setA(a);
  40. setB(b);
  41. this.a.addConnection(this);
  42. this.b.addConnection(this);
  43. this.maxCapacity = 100;
  44. flow = 0;
  45. isWorking = true;
  46. }
  47. /**
  48. * Constructor with a user-defined max. capacity
  49. *
  50. * @param a
  51. * Source
  52. * @param b
  53. * Destination
  54. * @param maxCap
  55. * Maximum Capacity
  56. */
  57. public CpsEdge(AbstractCpsObject a, AbstractCpsObject b, float maxCap) {
  58. setA(a);
  59. setB(b);
  60. this.a.addConnection(this);
  61. this.b.addConnection(this);
  62. this.maxCapacity = maxCap;
  63. flow = 0;
  64. isWorking = true;
  65. }
  66. /**
  67. * Getter for the max. capacity
  68. *
  69. * @return the capacity
  70. */
  71. public float getCapacity() {
  72. return maxCapacity;
  73. }
  74. /**
  75. * Setter for the max. capacity
  76. *
  77. * @param cap
  78. * the Capacity to set
  79. */
  80. public void setCapacity(float cap) {
  81. this.maxCapacity = cap;
  82. }
  83. /**
  84. * Getter fot the current flow.
  85. *
  86. * @return the flow
  87. */
  88. public float getFlow() {
  89. return flow;
  90. }
  91. /**
  92. * Set the flow into a new one.
  93. *
  94. * @param flow
  95. * the flow to set
  96. */
  97. public void setFlow(float flow) {
  98. this.flow = flow;
  99. /**
  100. * if (flow <= maxCapacity || flow == -1) { isWorking = true; } else {
  101. * isWorking = false; state = false;
  102. **/
  103. }
  104. /**
  105. * Calculates the state of the edge (see description of isWorking).
  106. *
  107. * @param simMode
  108. * Simulation Mode
  109. */
  110. public void calculateState(boolean simMode) {
  111. if (flow > maxCapacity && maxCapacity != -1) {
  112. isWorking = false;
  113. } else {
  114. if (!simMode && (flow <= maxCapacity || maxCapacity == -1)) {
  115. isWorking = true;
  116. }
  117. }
  118. }
  119. /**
  120. * Getter for the Source.
  121. *
  122. * @return the a
  123. */
  124. public AbstractCpsObject getA() {
  125. return a;
  126. }
  127. /**
  128. * Set the Source to a new one.
  129. *
  130. * @param a
  131. * the a to set
  132. */
  133. public void setA(AbstractCpsObject a) {
  134. this.a = a;
  135. }
  136. /**
  137. * Getter for the destination.
  138. *
  139. * @return the b
  140. */
  141. public AbstractCpsObject getB() {
  142. return b;
  143. }
  144. /**
  145. * Set the Destination to a new one.
  146. *
  147. * @param b
  148. * the b to set
  149. */
  150. public void setB(AbstractCpsObject b) {
  151. this.b = b;
  152. }
  153. /**
  154. * Set the state manually to a new one.
  155. *
  156. * @param state
  157. * the state
  158. */
  159. public void setState(boolean state) {
  160. isWorking = state;
  161. }
  162. /**
  163. * Getter for the status.
  164. *
  165. * @return the state
  166. */
  167. public boolean getState() {
  168. return isWorking;
  169. }
  170. /**
  171. * set the tags into a new set of tags.
  172. *
  173. * @param tags
  174. * tags for this edge
  175. */
  176. public void setTags(ArrayList<Integer> tags) {
  177. this.tags = tags;
  178. }
  179. /**
  180. * Getter for the ArrayList of tags.
  181. *
  182. * @return tags tags for this edge
  183. */
  184. public ArrayList<Integer> getTags() {
  185. return tags;
  186. }
  187. /**
  188. * Add a new tag to the ArrayList.
  189. *
  190. * @param tag tag for the ArrayList
  191. */
  192. public void addTag(int tag) {
  193. tags.add(tag);
  194. }
  195. }