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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations