use of com.intellij.vcs.log.graph.api.elements.GraphEdgeType in project intellij-community by JetBrains.
the class LinearGraphParser method parse.
public static LinearGraph parse(@NotNull String in) {
List<GraphNode> graphNodes = new ArrayList<>();
Map<GraphNode, List<String>> edges = ContainerUtil.newHashMap();
Map<Integer, Integer> nodeIdToNodeIndex = ContainerUtil.newHashMap();
for (String line : toLines(in)) {
// parse input and create nodes
Pair<Pair<Integer, GraphNode>, List<String>> graphNodePair = parseLine(line, graphNodes.size());
GraphNode graphNode = graphNodePair.first.second;
edges.put(graphNode, graphNodePair.second);
nodeIdToNodeIndex.put(graphNodePair.first.first, graphNodes.size());
graphNodes.add(graphNode);
}
MultiMap<Integer, GraphEdge> upEdges = MultiMap.create();
MultiMap<Integer, GraphEdge> downEdges = MultiMap.create();
for (GraphNode graphNode : graphNodes) {
// create edges
for (String strEdge : edges.get(graphNode)) {
Pair<Integer, Character> pairEdge = parseNumberWithChar(strEdge);
GraphEdgeType type = parseGraphEdgeType(pairEdge.second);
GraphEdge edge;
switch(type) {
case USUAL:
case DOTTED:
Integer downNodeIndex = nodeIdToNodeIndex.get(pairEdge.first);
assert downNodeIndex != null;
edge = GraphEdge.createNormalEdge(graphNode.getNodeIndex(), downNodeIndex, type);
break;
case NOT_LOAD_COMMIT:
case DOTTED_ARROW_DOWN:
case DOTTED_ARROW_UP:
edge = GraphEdge.createEdgeWithTargetId(graphNode.getNodeIndex(), pairEdge.first, type);
break;
default:
throw new IllegalStateException("Unknown type: " + type);
}
if (edge.getUpNodeIndex() != null)
downEdges.putValue(edge.getUpNodeIndex(), edge);
if (edge.getDownNodeIndex() != null)
upEdges.putValue(edge.getDownNodeIndex(), edge);
}
}
return new TestLinearGraphWithElementsInfo(graphNodes, upEdges, downEdges);
}
Aggregations