Search in sources :

Example 6 with GraphNode

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

the class BekBaseController method convertToDelegate.

@Nullable
@Override
protected GraphElement convertToDelegate(@NotNull GraphElement graphElement) {
    if (graphElement instanceof GraphEdge) {
        Integer upIndex = ((GraphEdge) graphElement).getUpNodeIndex();
        Integer downIndex = ((GraphEdge) graphElement).getDownNodeIndex();
        Integer convertedUpIndex = upIndex == null ? null : myBekIntMap.getUsualIndex(upIndex);
        Integer convertedDownIndex = downIndex == null ? null : myBekIntMap.getUsualIndex(downIndex);
        return new GraphEdge(convertedUpIndex, convertedDownIndex, ((GraphEdge) graphElement).getTargetId(), ((GraphEdge) graphElement).getType());
    } else if (graphElement instanceof GraphNode) {
        return new GraphNode(myBekIntMap.getUsualIndex((((GraphNode) graphElement).getNodeIndex())), ((GraphNode) graphElement).getType());
    }
    return null;
}
Also used : GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) GraphEdge(com.intellij.vcs.log.graph.api.elements.GraphEdge) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GraphNode

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

the class LinearGraphParser method parseLine.

/**
   * Example input line:
   * 0_U|-1_U 2_D
   */
public static Pair<Pair<Integer, GraphNode>, List<String>> parseLine(@NotNull String line, int lineNumber) {
    int separatorIndex = nextSeparatorIndex(line, 0);
    Pair<Integer, Character> pair = parseNumberWithChar(line.substring(0, separatorIndex));
    GraphNode graphNode = new GraphNode(lineNumber, parseGraphNodeType(pair.second));
    String[] edges = line.substring(separatorIndex + 2).split("\\s");
    List<String> normalEdges = ContainerUtil.mapNotNull(edges, new Function<String, String>() {

        @Nullable
        @Override
        public String fun(String s) {
            if (s.isEmpty())
                return null;
            return s;
        }
    });
    return Pair.create(Pair.create(pair.first, graphNode), normalEdges);
}
Also used : GraphNode(com.intellij.vcs.log.graph.api.elements.GraphNode) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode 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 9 with GraphNode

use of com.intellij.vcs.log.graph.api.elements.GraphNode 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 10 with GraphNode

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

Aggregations

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