Search in sources :

Example 1 with GraphEdgeType

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);
}
Also used : EdgeNodeCharConverter.parseGraphEdgeType(com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType) GraphEdgeType(com.intellij.vcs.log.graph.api.elements.GraphEdgeType) ArrayList(java.util.ArrayList) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) ArrayList(java.util.ArrayList) List(java.util.List) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 GraphEdge (com.intellij.vcs.log.graph.api.elements.GraphEdge)1 GraphEdgeType (com.intellij.vcs.log.graph.api.elements.GraphEdgeType)1 GraphNode (com.intellij.vcs.log.graph.api.elements.GraphNode)1 EdgeNodeCharConverter.parseGraphEdgeType (com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1