|
1 | 1 | package tfm.arcs;
|
2 | 2 |
|
3 | 3 | import org.jgrapht.graph.DefaultEdge;
|
| 4 | +import org.jgrapht.io.Attribute; |
| 5 | +import tfm.arcs.cfg.ControlFlowArc; |
| 6 | +import tfm.arcs.pdg.ControlDependencyArc; |
| 7 | +import tfm.arcs.pdg.DataDependencyArc; |
4 | 8 | import tfm.nodes.GraphNode;
|
5 | 9 |
|
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.Map; |
6 | 12 | import java.util.Objects;
|
7 |
| -import java.util.Optional; |
8 | 13 |
|
9 | 14 | public abstract class Arc extends DefaultEdge {
|
10 |
| - |
11 |
| - private String variable; |
12 |
| - |
13 | 15 | public Arc() {
|
14 | 16 |
|
15 | 17 | }
|
16 | 18 |
|
17 |
| - public Arc(String variable) { |
18 |
| - this.variable = variable; |
| 19 | + public final boolean isControlFlowArc() { |
| 20 | + return this instanceof ControlFlowArc; |
19 | 21 | }
|
20 | 22 |
|
21 |
| - public abstract boolean isControlFlowArrow(); |
| 23 | + public final ControlFlowArc asControlFlowArc() { |
| 24 | + if (isControlFlowArc()) |
| 25 | + return (ControlFlowArc) this; |
| 26 | + throw new UnsupportedOperationException("Not a ControlFlowArc"); |
| 27 | + } |
22 | 28 |
|
23 |
| - public abstract boolean isControlDependencyArrow(); |
| 29 | + public final boolean isControlDependencyArc() { |
| 30 | + return this instanceof ControlDependencyArc; |
| 31 | + } |
24 | 32 |
|
25 |
| - public abstract boolean isDataDependencyArrow(); |
| 33 | + public final ControlDependencyArc asControlDependencyArc() { |
| 34 | + if (isControlDependencyArc()) |
| 35 | + return (ControlDependencyArc) this; |
| 36 | + throw new UnsupportedOperationException("Not a ControlDependencyArc"); |
| 37 | + } |
26 | 38 |
|
27 |
| - public Optional<String> getVariable() { |
28 |
| - return Optional.ofNullable(this.variable); |
| 39 | + public final boolean isDataDependencyArc() { |
| 40 | + return this instanceof DataDependencyArc; |
| 41 | + } |
| 42 | + |
| 43 | + public final DataDependencyArc asDataDependencyArc() { |
| 44 | + if (isDataDependencyArc()) |
| 45 | + return (DataDependencyArc) this; |
| 46 | + throw new UnsupportedOperationException("Not a DataDependencyArc"); |
29 | 47 | }
|
30 | 48 |
|
31 | 49 | @Override
|
32 | 50 | public String toString() {
|
33 |
| - return toGraphvizRepresentation(); |
| 51 | + return String.format("%s{%d -> %d}", getClass().getName(), |
| 52 | + ((GraphNode<?>) getSource()).getId(), ((GraphNode<?>) getTarget()).getId()); |
34 | 53 | }
|
35 | 54 |
|
36 |
| - public String toGraphvizRepresentation() { |
37 |
| - GraphNode<?> from = (GraphNode<?>) getSource(); |
38 |
| - GraphNode<?> to = (GraphNode<?>) getTarget(); |
| 55 | + public String getLabel() { |
| 56 | + return ""; |
| 57 | + } |
39 | 58 |
|
40 |
| - return String.format("%s -> %s", |
41 |
| - from.getId(), |
42 |
| - to.getId() |
43 |
| - ); |
| 59 | + public Map<String, Attribute> getDotAttributes() { |
| 60 | + return new HashMap<>(); |
44 | 61 | }
|
45 | 62 |
|
46 | 63 | @Override
|
47 | 64 | public boolean equals(Object o) {
|
48 |
| - if (this == o) { |
| 65 | + if (this == o) |
49 | 66 | return true;
|
50 |
| - } |
51 |
| - |
52 |
| - return Objects.equals(variable, ((Arc) o).variable); |
| 67 | + if (o == null) |
| 68 | + return false; |
| 69 | + if (!o.getClass().equals(this.getClass())) |
| 70 | + return false; |
| 71 | + return Objects.equals(getSource(), ((Arc) o).getSource()) && |
| 72 | + Objects.equals(getTarget(), ((Arc) o).getTarget()); |
53 | 73 | }
|
54 | 74 |
|
55 | 75 | @Override
|
56 | 76 | public int hashCode() {
|
57 |
| - return Objects.hash(variable, getSource(), getTarget()); |
| 77 | + return Objects.hash(getClass(), getSource(), getTarget()); |
58 | 78 | }
|
59 | 79 | }
|
0 commit comments