-
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathGraph.java
More file actions
65 lines (53 loc) · 1.7 KB
/
Graph.java
File metadata and controls
65 lines (53 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.HashMap;
import java.util.Map;
public final class Graph {
public int nextNodeId = 1;
public int nextPinId = 100;
public final Map<Integer, GraphNode> nodes = new HashMap<>();
public Graph() {
final GraphNode first = createGraphNode();
final GraphNode second = createGraphNode();
first.outputNodeId = second.nodeId;
}
public GraphNode createGraphNode() {
final GraphNode node = new GraphNode(nextNodeId++, nextPinId++, nextPinId++);
this.nodes.put(node.nodeId, node);
return node;
}
public GraphNode findByInput(final long inputPinId) {
for (GraphNode node : nodes.values()) {
if (node.getInputPinId() == inputPinId) {
return node;
}
}
return null;
}
public GraphNode findByOutput(final long outputPinId) {
for (GraphNode node : nodes.values()) {
if (node.getOutputPinId() == outputPinId) {
return node;
}
}
return null;
}
public static final class GraphNode {
public final int nodeId;
public final int inputPinId;
public final int outputPinId;
public int outputNodeId = -1;
public GraphNode(final int nodeId, final int inputPinId, final int outputPintId) {
this.nodeId = nodeId;
this.inputPinId = inputPinId;
this.outputPinId = outputPintId;
}
public int getInputPinId() {
return inputPinId;
}
public int getOutputPinId() {
return outputPinId;
}
public String getName() {
return "Node " + (char) (64 + nodeId);
}
}
}