123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- package classes;
- import java.util.ArrayList;
- /**
- * The class "CpsEdge" represents the connections on the GUI. Each connection
- * contains a max. capacity, a flow, a status (isWorking), tags (for internal
- * use of electricity flow), source and destination
- *
- * @author Gruppe14
- *
- */
- public class CpsEdge {
- // Max. capacity of the Edge, if flow is greater than the status --> is
- // Working would be false
- float maxCapacity;
- // Current flow of electricity (through the edge)
- float flow;
- /*
- * Represents the actual status of the Edge (true = flows electricity; false
- * = no flow of electricity) State represents the real status of the edge If
- * it breaks --> stay ruin no matter the actual scenario The only way to
- * repair it is through manual change (setStateEdge)
- */
- boolean isWorking;
- // for internal use --> flow of electricity (simulation state)
- ArrayList<Integer> tags;
- // Source
- CpsObject A;
- // Destination
- CpsObject B;
- /**
- * Constructor without max. capacity (by default as 100)
- *
- * @param A
- * Source
- * @param B
- * Destination
- */
- public CpsEdge(CpsObject A, CpsObject B) {
- setA(A);
- setB(B);
- this.A.AddConnection(this);
- this.B.AddConnection(this);
- this.maxCapacity = 100;
- flow = 0;
- isWorking = true;
- }
- /**
- * Constructor with a user-defined max. capacity
- *
- * @param A
- * Source
- * @param B
- * Destination
- */
- public CpsEdge(CpsObject A, CpsObject B, float maxCap) {
- setA(A);
- setB(B);
- this.A.AddConnection(this);
- this.B.AddConnection(this);
- this.maxCapacity = maxCap;
- flow = 0;
- isWorking = true;
- }
- /**
- * Getter for the max. capacity
- *
- * @return the capacity
- */
- public float getCapacity() {
- return maxCapacity;
- }
- /**
- * Setter for the max. capacity
- *
- * @param cap
- * the Capacity to set
- */
- public void setCapacity(float cap) {
- this.maxCapacity = cap;
- }
- /**
- * Getter fot the current flow
- *
- * @return the flow
- */
- public float getFlow() {
- return flow;
- }
- /**
- * Set the flow into a new one
- *
- * @param flow
- * the flow to set
- */
- public void setFlow(float flow) {
- this.flow = flow;
- /**
- * if (flow <= maxCapacity || flow == -1) { isWorking = true; } else {
- * isWorking = false; state = false; }
- **/
- }
- /**
- * Calculates the state of the edge (see description of isWorking)
- *
- * @param simMode
- */
- public void calculateState(boolean simMode) {
- if (flow > maxCapacity && maxCapacity != -1) {
- isWorking = false;
- } else {
- if (!simMode && flow <= maxCapacity) {
- isWorking = true;
- }
- }
- }
- /**
- * Getter for the Source
- *
- * @return the a
- */
- public CpsObject getA() {
- return A;
- }
- /**
- * Set the Source to a new one
- *
- * @param a
- * the a to set
- */
- public void setA(CpsObject a) {
- A = a;
- }
- /**
- * Getter for the destination
- *
- * @return the b
- */
- public CpsObject getB() {
- return B;
- }
- /**
- * Set the Destination to a new one
- *
- * @param b
- * the b to set
- */
- public void setB(CpsObject b) {
- B = b;
- }
- /**
- * Set the state manually to a new one
- *
- * @param state
- */
- public void setState(boolean state) {
- isWorking = state;
- }
- /**
- * Getter for the status
- *
- * @return
- */
- public boolean getState() {
- return isWorking;
- }
- /**
- * set the tags into a new set of tags
- *
- * @param tags
- */
- public void setTags(ArrayList<Integer> tags) {
- this.tags = tags;
- }
- /**
- * Getter for the ArrayList of tags
- *
- * @return
- */
- public ArrayList<Integer> getTags() {
- return tags;
- }
- /**
- * Add a new tag to the ArrayList
- *
- * @param tag
- */
- public void addTag(int tag) {
- tags.add(tag);
- }
- }
|