CpsEdge.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. CpsObject A;
  28. // Destination
  29. CpsObject 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(CpsObject A, CpsObject 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. */
  55. public CpsEdge(CpsObject A, CpsObject B, float maxCap) {
  56. setA(A);
  57. setB(B);
  58. this.A.AddConnection(this);
  59. this.B.AddConnection(this);
  60. this.maxCapacity = maxCap;
  61. flow = 0;
  62. isWorking = true;
  63. }
  64. /**
  65. * Getter for the max. capacity
  66. *
  67. * @return the capacity
  68. */
  69. public float getCapacity() {
  70. return maxCapacity;
  71. }
  72. /**
  73. * Setter for the max. capacity
  74. *
  75. * @param cap
  76. * the Capacity to set
  77. */
  78. public void setCapacity(float cap) {
  79. this.maxCapacity = cap;
  80. }
  81. /**
  82. * Getter fot the current flow
  83. *
  84. * @return the flow
  85. */
  86. public float getFlow() {
  87. return flow;
  88. }
  89. /**
  90. * Set the flow into a new one
  91. *
  92. * @param flow
  93. * the flow to set
  94. */
  95. public void setFlow(float flow) {
  96. this.flow = flow;
  97. /**
  98. * if (flow <= maxCapacity || flow == -1) { isWorking = true; } else {
  99. * isWorking = false; state = false; }
  100. **/
  101. }
  102. /**
  103. * Calculates the state of the edge (see description of isWorking)
  104. *
  105. * @param simMode
  106. */
  107. public void calculateState(boolean simMode) {
  108. if (flow > maxCapacity && maxCapacity != -1) {
  109. isWorking = false;
  110. } else {
  111. if (!simMode && flow <= maxCapacity) {
  112. isWorking = true;
  113. }
  114. }
  115. }
  116. /**
  117. * Getter for the Source
  118. *
  119. * @return the a
  120. */
  121. public CpsObject getA() {
  122. return A;
  123. }
  124. /**
  125. * Set the Source to a new one
  126. *
  127. * @param a
  128. * the a to set
  129. */
  130. public void setA(CpsObject a) {
  131. A = a;
  132. }
  133. /**
  134. * Getter for the destination
  135. *
  136. * @return the b
  137. */
  138. public CpsObject getB() {
  139. return B;
  140. }
  141. /**
  142. * Set the Destination to a new one
  143. *
  144. * @param b
  145. * the b to set
  146. */
  147. public void setB(CpsObject b) {
  148. B = b;
  149. }
  150. /**
  151. * Set the state manually to a new one
  152. *
  153. * @param state
  154. */
  155. public void setState(boolean state) {
  156. isWorking = state;
  157. }
  158. /**
  159. * Getter for the status
  160. *
  161. * @return
  162. */
  163. public boolean getState() {
  164. return isWorking;
  165. }
  166. /**
  167. * set the tags into a new set of tags
  168. *
  169. * @param tags
  170. */
  171. public void setTags(ArrayList<Integer> tags) {
  172. this.tags = tags;
  173. }
  174. /**
  175. * Getter for the ArrayList of tags
  176. *
  177. * @return
  178. */
  179. public ArrayList<Integer> getTags() {
  180. return tags;
  181. }
  182. /**
  183. * Add a new tag to the ArrayList
  184. *
  185. * @param tag
  186. */
  187. public void addTag(int tag) {
  188. tags.add(tag);
  189. }
  190. }