Deque<PredictionContext> workList = new ArrayDeque<PredictionContext>();
visited.put(context, context);
contextIds.put(context, contextIds.size());
workList.add(context);
while (!workList.isEmpty()) {
PredictionContext current = workList.pop();
nodes.append(" s").append(contextIds.get(current)).append('[');
if (current.size() > 1) {
nodes.append("shape=record, ");
}
nodes.append("label=\"");
if (current.isEmpty()) {
nodes.append(rootIsWildcard ? '*' : '$');
} else if (current.size() > 1) {
for (int i = 0; i < current.size(); i++) {
if (i > 0) {
nodes.append('|');
}
nodes.append("<p").append(i).append('>');
if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
nodes.append(rootIsWildcard ? '*' : '$');
}
}
} else {
nodes.append(contextIds.get(current));
}
nodes.append("\"];\n");
if (current.isEmpty()) {
continue;
}
for (int i = 0; i < current.size(); i++) {
if (current.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
continue;
}
if (visited.put(current.getParent(i), current.getParent(i)) == null) {
contextIds.put(current.getParent(i), contextIds.size());
workList.push(current.getParent(i));
}
edges.append(" s").append(contextIds.get(current));
if (current.size() > 1) {
edges.append(":p").append(i);
}
edges.append("->");
edges.append('s').append(contextIds.get(current.getParent(i)));
edges.append("[label=\"").append(current.getReturnState(i)).append("\"]");
edges.append(";\n");
}
}
StringBuilder builder = new StringBuilder();