public EdgeResult convertForViaWays(LongArrayList fromWays, LongArrayList viaWays, LongArrayList toWays) throws OSMRestrictionException {
        if (fromWays.isEmpty() || toWays.isEmpty() || viaWays.isEmpty())
            throw new IllegalArgumentException("There must be at least one from-, via- and to-way");
        if (fromWays.size() > 1 && toWays.size() > 1)
            throw new IllegalArgumentException("There can only be multiple from- or to-ways, but not both");
        List<IntArrayList> solutions = new ArrayList<>();
        for (LongCursor fromWay : fromWays)
            for (LongCursor toWay : toWays)
                findEdgeChain(fromWay.value, viaWays, toWay.value, solutions);
        if (solutions.size() < fromWays.size() * toWays.size())
            throw new OSMRestrictionException("has disconnected member ways");
        else if (solutions.size() > fromWays.size() * toWays.size())
            throw new OSMRestrictionException("has member ways that do not form a unique path");
        return buildResult(solutions, new EdgeResult(fromWays.size(), viaWays.size(), toWays.size()));
    }
@Test
    void convertForViaWays_multipleEdgesForViaWay_oppositeDirection() throws OSMRestrictionException {
        BaseGraph graph = new BaseGraph.Builder(1).create();
        graph.edge(0, 1);
        graph.edge(1, 2);
        graph.edge(2, 3);
        graph.edge(3, 4);
        LongFunction<Iterator<IntCursor>> edgesByWay = way -> {
            if (way == 0) return IntArrayList.from(0).iterator();
                // way 1 is split into the two edges 2, 1 (the wrong order)
                // Accepting an arbitrary order is important, because OSM ways are generally split into multiple edges
                // and a via-way might be pointing in the 'wrong' direction.
            else if (way == 1) return IntArrayList.from(2, 1).iterator();
            else if (way == 2) return IntArrayList.from(3).iterator();
            else throw new IllegalArgumentException();
        };
        WayToEdgeConverter.EdgeResult edgeResult = new WayToEdgeConverter(graph, edgesByWay).convertForViaWays(ways(0), ways(1), ways(2));
        assertEquals(IntArrayList.from(1, 2), edgeResult.getViaEdges());
        assertEquals(IntArrayList.from(1, 2, 3), edgeResult.getNodes());
    }