提交 1db1a65f 编写于 作者: wu-sheng's avatar wu-sheng

Support WayToNode for entry node.

上级 932dbbc7
......@@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public final class Graph<INPUT> {
private int id;
private Node startNode;
private WayToNode entryWay;
private ConcurrentHashMap<Integer, Node> nodeIndex = new ConcurrentHashMap<>();
Graph(int id) {
......@@ -33,13 +33,18 @@ public final class Graph<INPUT> {
}
public void start(INPUT INPUT) {
startNode.execute(INPUT);
entryWay.in(INPUT);
}
public <OUTPUT> Node<INPUT, OUTPUT> addNode(NodeProcessor<INPUT, OUTPUT> nodeProcessor) {
return addNode(new DirectWay(nodeProcessor));
}
public <OUTPUT> Node<INPUT, OUTPUT> addNode(WayToNode<INPUT, OUTPUT> entryWay) {
synchronized (this) {
startNode = new Node(this, nodeProcessor);
return startNode;
this.entryWay = entryWay;
this.entryWay.buildDestination(this);
return entryWay.getDestination();
}
}
......
......@@ -130,6 +130,20 @@ public class GraphManagerTest {
Assert.assertEquals(expected, output);
}
@Test
public void testEntryWay() {
Graph<String> graph = GraphManager.INSTANCE.createIfAbsent(8, String.class);
graph.addNode(new WayToNode<String, String>(new Node1Processor()) {
@Override protected void in(String INPUT) {
//don't call `out(intput)`;
}
}).addNext(new Node2Processor());
graph.start("Input String");
Assert.assertEquals("", outputStream.toString());
}
@After
public void tearDown() {
GraphManager.INSTANCE.reset();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册