forked from sourcegraph/scip-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmitter.java
More file actions
39 lines (30 loc) · 962 Bytes
/
Emitter.java
File metadata and controls
39 lines (30 loc) · 962 Bytes
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
import com.google.gson.Gson;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public class Emitter {
private PrintWriter writer;
private Gson gson = new Gson();
private int nextId = 1;
public Emitter(PrintWriter writer) {
this.writer = writer;
}
public int numElements() {
return nextId;
}
public String emitVertex(String labelName, Map<String, Object> args) {
return emit("vertex", labelName, args);
}
public String emitEdge(String labelName, Map<String, Object> args) {
return emit("edge", labelName, args);
}
private String emit(String typeName, String labelName, Map<String, Object> args) {
String id = String.format("%d", nextId++);
writer.println(gson.toJson(Util.union(args, Util.mapOf(
"id", id,
"type", typeName,
"label", labelName
))));
return id;
}
}