Skip to content

Package: Edge

Edge

nameinstructionbranchcomplexitylinemethod
Edge(Node, Node)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
calculateMiddle()
M: 0 C: 36
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
deregister()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
draw(Graphics)
M: 41 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 4 C: 22
85%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 6
75%
M: 0 C: 1
100%
getN1()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getN2()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasConnection(Node, Node)
M: 4 C: 16
80%
M: 4 C: 4
50%
M: 3 C: 2
40%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
isConnectedTo(Node)
M: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
register()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: package networkconfigurator.item;
2:
3: import java.awt.Graphics;
4: import java.awt.Point;
5:
6: /**
7: * An Edge is a pair of Nodes.
8: */
9: public abstract class Edge extends Item {
10:         /**
11:          * Node 1 is connected to Node2.
12:          */
13:         private final Node node1;
14:         /**
15:          * Node 2 is connected to Node1.
16:          */
17:         private final Node node2;
18:
19:         /**
20:          * Constructor.
21:          *
22:          * @param n1
23:          * Node1
24:          * @param n2
25:          * Node2
26:          */
27:         public Edge(final Node n1, final Node n2) {
28:                 this.node1 = n1;
29:                 this.node2 = n2;
30:                 calculateMiddle();
31:         }
32:
33:         /**
34:          * setting color of the Edge.
35:          *
36:          * @param g
37:          * graphic of the edge.
38:          */
39:         abstract void setColor(Graphics g);
40:
41:         /**
42:          * Getter of Node 2.
43:          *
44:          * @return node 2
45:          */
46:         public Node getN2() {
47:                 return node2;
48:         }
49:
50:         /**
51:          * Getter of Node 1.
52:          *
53:          * @return Node 1
54:          */
55:         public Node getN1() {
56:                 return node1;
57:         }
58:
59:         /**
60:          * register the edge at the Nodes as a observer.
61:          */
62:         public void register() {
63:                 getN1().registerObserver(this);
64:                 getN2().registerObserver(this);
65:         }
66:
67:         /**
68:          * deregister the edge from the Nodes.
69:          */
70:         public void deregister() {
71:                 getN1().removeObserver(this);
72:                 getN2().removeObserver(this);
73:         }
74:
75:         /**
76:          * Calculates the middle between Node n1 and Node n2.
77:          */
78:         public final void calculateMiddle() {
79:                 final Point point1 = node1.getPoint();
80:                 final Point point2 = node2.getPoint();
81:                 final int xPosition = (point1.x + point2.x) / 2;
82:                 final int yPosition = (point1.y + point2.y) / 2;
83:                 final Point newPoint = new Point(xPosition, yPosition);
84:                 this.setPoint(newPoint);
85:                 this.setBoundary();
86:         }
87:
88:         /**
89:          * drawing the connecting between Node 1 and Node2.
90:          *
91:          * @param g
92:          * line to be drawn
93:          */
94:         @Override
95:         public void draw(final Graphics g) {
96:                 final Point p1 = getN1().getPoint();
97:                 final Point p2 = getN2().getPoint();
98:                 setColor(g);
99:                 g.drawLine(p1.x, p1.y, p2.x, p2.y);
100:                 calculateMiddle();
101:•                if (getSelected()) {
102:                         g.drawOval(getBoundary().x, getBoundary().y, getBoundary().width,
103:                                         getBoundary().height);
104:                 }
105:         }
106:
107:         /**
108:          * method to check if there is a connection between Node n1 and Node n2.
109:          *
110:          * @param n1
111:          * Node 1.
112:          * @param n2
113:          * Node 2.
114:          * @return if there is a connection between Node n1 and Node n2.
115:          */
116:         public boolean hasConnection(final Node n1, final Node n2) {
117:•                return n1 == this.node1 && n2 == this.node2 || n2 == this.node1 && n1 == this.node2;
118:         }
119:
120:         /**
121:          * checks if this edge is connected to the node n.
122:          *
123:          * @param n
124:          * the node
125:          * @return true, if it is connected.
126:          */
127:         public boolean isConnectedTo(final Node n) {
128:•                return n.equals(node1) || n.equals(node2);
129:         }
130:
131:         @Override
132:         public int hashCode() {
133:                 final int result = 1;
134:                 return result;
135:         }
136:
137:         @Override
138:         public boolean equals(final Object obj) {
139:•                if (this == obj) {
140:                         return true;
141:                 }
142:•                if (obj == null) {
143:                         return false;
144:                 }
145:•                if (getClass() != obj.getClass()) {
146:                         return false;
147:                 }
148:                 final Edge other = (Edge) obj;
149:                 return hasConnection(other.getN1(), other.getN2());
150:         }
151: }