CpsEdge.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package classes;
  2. import com.google.gson.annotations.Expose;
  3. import java.util.ArrayList;
  4. /**
  5. * The class "CpsEdge" represents the connections on the GUI. Each connection
  6. * contains a max. capacity, a flow, a status (isWorking), tags (for internal
  7. * use of electricity flow), source and destination
  8. *
  9. * @author Gruppe14
  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. @Expose
  15. private float maxCapacity;
  16. ArrayList<Integer> tags;
  17. // for internal use --> flow of electricity (simulation state)
  18. ArrayList<Integer> pseudoTags;
  19. // Source
  20. AbstractCpsObject a;
  21. // Destination
  22. AbstractCpsObject b;
  23. @Expose
  24. private boolean breakedManuel = false;
  25. @Expose
  26. private boolean unlimitedCapacity = false;
  27. /**
  28. * Constructor without max. capacity (by default as 100)
  29. *
  30. * @param a Source
  31. * @param b Destination
  32. */
  33. public CpsEdge(AbstractCpsObject a, AbstractCpsObject b) {
  34. setA(a);
  35. setB(b);
  36. this.a.addConnection(this);
  37. this.b.addConnection(this);
  38. this.maxCapacity = 100;
  39. pseudoTags = new ArrayList<>();
  40. }
  41. /**
  42. * Constructor with a user-defined max. capacity
  43. *
  44. * @param a Source
  45. * @param b Destination
  46. * @param maxCap Maximum Capacity
  47. */
  48. public CpsEdge(AbstractCpsObject a, AbstractCpsObject b, float maxCap) {
  49. setA(a);
  50. setB(b);
  51. this.a.addConnection(this);
  52. this.b.addConnection(this);
  53. this.maxCapacity = maxCap;
  54. pseudoTags = new ArrayList<>();
  55. }
  56. /**
  57. * Getter for the max. capacity
  58. *
  59. * @return the capacity
  60. */
  61. public float getCapacity() {
  62. return maxCapacity;
  63. }
  64. /**
  65. * Setter for the max. capacity
  66. *
  67. * @param cap the Capacity to set
  68. */
  69. public void setCapacity(float cap) {
  70. this.maxCapacity = cap;
  71. }
  72. /**
  73. * Getter for the Source.
  74. *
  75. * @return the a
  76. */
  77. public AbstractCpsObject getA() {
  78. return a;
  79. }
  80. /**
  81. * Set the Source to a new one.
  82. *
  83. * @param a the a to set
  84. */
  85. public void setA(AbstractCpsObject a) {
  86. this.a = a;
  87. }
  88. /**
  89. * Getter for the destination.
  90. *
  91. * @return the b
  92. */
  93. public AbstractCpsObject getB() {
  94. return b;
  95. }
  96. /**
  97. * Set the Destination to a new one.
  98. *
  99. * @param b the b to set
  100. */
  101. public void setB(AbstractCpsObject b) {
  102. this.b = b;
  103. }
  104. /**
  105. * Getter for the ArrayList of tags.
  106. *
  107. * @return tags tags for this edge
  108. */
  109. public ArrayList<Integer> getTags() {
  110. return tags;
  111. }
  112. /**
  113. * set the tags into a new set of tags.
  114. *
  115. * @param tags tags for this edge
  116. */
  117. public void setTags(ArrayList<Integer> tags) {
  118. this.tags = tags;
  119. }
  120. /**
  121. * Add a new tag to the ArrayList.
  122. *
  123. * @param tag tag for the ArrayList
  124. */
  125. public void addTag(int tag) {
  126. if (!tags.contains(tag)) {
  127. tags.add(tag);
  128. }
  129. }
  130. /**
  131. * checks whether list contains all given tags
  132. *
  133. * @param toCheck tags that are checked
  134. * @param list list to be checked
  135. * @return true if all tags in toCheck are contained in list, false otherwise
  136. */
  137. public boolean containsTags(ArrayList<Integer> list, ArrayList<Integer> toCheck) {
  138. if (toCheck.size() == 0) {
  139. return true;
  140. } else {
  141. for (Integer i : toCheck) {
  142. if (!(list.contains(i))) {
  143. return false;
  144. }
  145. }
  146. return true;
  147. }
  148. }
  149. public void addPseudoTag(int tag) {
  150. if (!pseudoTags.contains(tag)) {
  151. pseudoTags.add(tag);
  152. }
  153. }
  154. public void setPseudoTag(ArrayList<Integer> list) {
  155. pseudoTags = list;
  156. }
  157. public ArrayList<Integer> getPseudoTags() {
  158. return pseudoTags;
  159. }
  160. public void recalculateTags() {
  161. for (Integer i : pseudoTags) {
  162. if (!tags.contains(i)) {
  163. tags.add(i);
  164. }
  165. }
  166. }
  167. /**
  168. * Check if a CpsEdge is Connected to the AbstractCpsObject.
  169. * @param holonObject the AbstractCpsObject to check.
  170. * @return true if either a or b is the AbstractCpsObject to check.
  171. */
  172. public boolean isConnectedTo(AbstractCpsObject holonObject)
  173. {
  174. return (holonObject.equals(a) || holonObject.equals(b));
  175. }
  176. @Override
  177. public String toString(){
  178. String A = (a == null) ? "null" : a.getName() + "[" + a.getId()+ "]";
  179. String B = (b == null) ? "null" : b.getName() + "[" + b.getId()+ "]";
  180. return "CpsEdge: " + A + " to " + B;
  181. }
  182. public boolean isBreakedManuel() {
  183. return breakedManuel;
  184. }
  185. public void setBreakedManuel(boolean breakedManuel) {
  186. this.breakedManuel = breakedManuel;
  187. }
  188. public boolean isUnlimitedCapacity() {
  189. return unlimitedCapacity;
  190. }
  191. public void setUnlimitedCapacity(boolean unlimitedCapacity) {
  192. this.unlimitedCapacity = unlimitedCapacity;
  193. }
  194. }