Skip to content
Permalink
Browse files

[509077] Allow reuse of identifiable nodes.

  • Loading branch information
mwienand committed Dec 12, 2016
1 parent a70c085 commit 5d91b42a36ec40811b29a867136fcbd0b3c0df41
@@ -29,6 +29,14 @@

public class GraphBuilderTests {

public static class Semantic {
public String data;

public Semantic(String data) {
this.data = data;
}
}

private void addNodeBuilders(Graph.Builder graphBuilder, int count,
int startNumber) {
for (int i = 0; i < count; i++) {
@@ -119,6 +127,21 @@ public int compare(Edge o1, Edge o2) {
"n3");
}

@Test
public void buildSemanticTwice() {
Builder b = new Graph.Builder();
Semantic s1 = new Semantic("a");
b.node(s1).attr("test", "value");
b.node(s1).attr("test2", "value2");
Graph graph = b.build();
assertEquals(1, graph.getNodes().size());
assertEquals(0, graph.getEdges().size());
assertEquals("value",
graph.getNodes().get(0).getAttributes().get("test"));
assertEquals("value2",
graph.getNodes().get(0).getAttributes().get("test2"));
}

@Test
public void buildWithExistingNodes() {
Node n1 = new Node.Builder().attr("label", "n1")//
@@ -78,6 +78,10 @@
* Stores incoming node keys in order.
*/
protected List<Object> nodeKeys = new ArrayList<>();
/**
* Stores node builders
*/
protected Map<Object, Node.Builder> nodeKeyToBuilderMap = new HashMap<>();
}

private List<Entry<Object, Object>> attr = new ArrayList<>();
@@ -249,6 +253,9 @@ protected Node findOrCreateNode(Object key) {
* @return A new {@link Node.Builder}.
*/
public Node.Builder node(Object key) {
if (context.nodeBuilders.containsKey(key)) {
return context.nodeBuilders.get(key);
}
Node.Builder nb = new Node.Builder(context, key);
context.nodeKeys.add(key);
return nb;

0 comments on commit 5d91b42

Please sign in to comment.
You can’t perform that action at this time.