Search in sources :

Example 11 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge 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)

Example 12 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class PrintElementGeneratorImpl method getDownShortEdges.

@NotNull
@Override
protected List<ShortEdge> getDownShortEdges(int rowIndex) {
    NullableFunction<GraphEdge, Integer> endPosition = createEndPositionFunction(rowIndex);
    List<ShortEdge> result = new ArrayList<>();
    List<GraphElement> visibleElements = getSortedVisibleElementsInRow(rowIndex);
    for (int startPosition = 0; startPosition < visibleElements.size(); startPosition++) {
        GraphElement element = visibleElements.get(startPosition);
        if (element instanceof GraphNode) {
            int nodeIndex = ((GraphNode) element).getNodeIndex();
            for (GraphEdge edge : myLinearGraph.getAdjacentEdges(nodeIndex, EdgeFilter.ALL)) {
                if (isEdgeDown(edge, nodeIndex)) {
                    Integer endPos = endPosition.fun(edge);
                    if (endPos != null)
                        result.add(new ShortEdge(edge, startPosition, endPos));
                }
            }
        }
        if (element instanceof GraphEdge) {
            GraphEdge edge = (GraphEdge) element;
            Integer endPos = endPosition.fun(edge);
            if (endPos != null)
                result.add(new ShortEdge(edge, startPosition, endPos));
        }
    }
    return result;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class PrintElementGeneratorImpl method getSimpleRowElements.

@NotNull
@Override
protected List<SimpleRowElement> getSimpleRowElements(int visibleRowIndex) {
    List<SimpleRowElement> result = new SmartList<>();
    List<GraphElement> sortedVisibleElementsInRow = getSortedVisibleElementsInRow(visibleRowIndex);
    for (int position = 0; position < sortedVisibleElementsInRow.size(); position++) {
        GraphElement element = sortedVisibleElementsInRow.get(position);
        if (element instanceof GraphNode) {
            result.add(new SimpleRowElement(element, RowElementType.NODE, position));
        }
        if (element instanceof GraphEdge) {
            GraphEdge edge = (GraphEdge) element;
            RowElementType arrowType = getArrowType(edge, visibleRowIndex);
            if (arrowType != null) {
                result.add(new SimpleRowElement(edge, arrowType, position));
            }
        }
    }
    return result;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) SmartList(com.intellij.util.SmartList) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class PrintElementGeneratorImpl method getSortedVisibleElementsInRow.

@NotNull
private List<GraphElement> getSortedVisibleElementsInRow(int rowIndex) {
    List<GraphElement> graphElements = myCache.get(rowIndex);
    if (graphElements != null) {
        return graphElements;
    }
    List<GraphElement> result = new ArrayList<>();
    result.add(myLinearGraph.getGraphNode(rowIndex));
    for (GraphEdge edge : myEdgesInRowGenerator.getEdgesInRow(rowIndex)) {
        if (isEdgeVisibleInRow(edge, rowIndex))
            result.add(edge);
    }
    addSpecialEdges(result, rowIndex);
    Collections.sort(result, myGraphElementComparator);
    myCache.put(rowIndex, result);
    return result;
}
Also used : GraphElement(com.intellij.vcs.log.graph.api.elements.GraphElement) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with GraphEdge

use of com.intellij.vcs.log.graph.api.elements.GraphEdge in project intellij-community by JetBrains.

the class LinearBekGraph method expandEdge.

public Collection<GraphEdge> expandEdge(@NotNull final GraphEdge edge) {
    Set<GraphEdge> result = ContainerUtil.newHashSet();
    assert edge.getType() == GraphEdgeType.DOTTED;
    myDottedEdges.removeEdge(edge);
    Integer tail = edge.getUpNodeIndex();
    Integer firstChild = edge.getDownNodeIndex();
    assert tail != null : "Collapsed from to an unloaded node";
    assert firstChild != null : "Collapsed edge to an unloaded node";
    List<GraphEdge> downDottedEdges = myHiddenEdges.getAdjacentEdges(tail, EdgeFilter.NORMAL_DOWN);
    List<GraphEdge> upDottedEdges = myHiddenEdges.getAdjacentEdges(firstChild, EdgeFilter.NORMAL_UP);
    for (GraphEdge e : ContainerUtil.concat(downDottedEdges, upDottedEdges)) {
        myHiddenEdges.removeEdge(e);
        if (e.getType() == GraphEdgeType.DOTTED) {
            result.addAll(expandEdge(e));
        } else {
            result.add(e);
        }
    }
    return result;
}
Also used : GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge)

Aggregations

GraphEdge (com.intellij.vcs.log.graph.api.elements.GraphEdge)15 GraphNode (com.intellij.vcs.log.graph.api.elements.GraphNode)9 GraphElement (com.intellij.vcs.log.graph.api.elements.GraphElement)5 NormalEdge (com.intellij.vcs.log.graph.utils.NormalEdge)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 PrintElementWithGraphElement (com.intellij.vcs.log.graph.impl.print.elements.PrintElementWithGraphElement)2 ArrayList (java.util.ArrayList)2 Pair (com.intellij.openapi.util.Pair)1 SmartList (com.intellij.util.SmartList)1 GraphEdgeType (com.intellij.vcs.log.graph.api.elements.GraphEdgeType)1 TerminalEdgePrintElement (com.intellij.vcs.log.graph.impl.print.elements.TerminalEdgePrintElement)1 EdgeNodeCharConverter.parseGraphEdgeType (com.intellij.vcs.log.graph.parser.EdgeNodeCharConverter.parseGraphEdgeType)1 LinearGraphUtils.asNormalEdge (com.intellij.vcs.log.graph.utils.LinearGraphUtils.asNormalEdge)1 List (java.util.List)1 PriorityQueue (java.util.PriorityQueue)1