LinearGraph (@NotNull String in) { List<GraphNode> graphNodes = new ArrayList<>(); Map<GraphNode, List<String>> edges = new HashMap<>(); Int2IntMap nodeIdToNodeIndex = new Int2IntOpenHashMap(); for (String line : toLines(in)) { // parse input and create nodes ParsedLine graphNodePair = parseLine(line, graphNodes.size()); edges.put(graphNodePair.graphNode, graphNodePair.normalEdges); nodeIdToNodeIndex.put(graphNodePair.nodeId, graphNodes.size()); graphNodes.add(graphNodePair.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)) { NumberWithChar pairEdge = parseNumberWithChar(strEdge); GraphEdgeType type = parseGraphEdgeType(pairEdge.character); GraphEdge edge; switch (type) { case USUAL, DOTTED -> { assert nodeIdToNodeIndex.containsKey(pairEdge.nodeId); int downNodeIndex = nodeIdToNodeIndex.get(pairEdge.nodeId); edge = GraphEdge.createNormalEdge(graphNode.getNodeIndex(), downNodeIndex, type); } case NOT_LOAD_COMMIT, DOTTED_ARROW_DOWN, DOTTED_ARROW_UP -> edge = GraphEdge.createEdgeWithTargetId(graphNode.getNodeIndex(), pairEdge.nodeId, type); 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); }