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