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_loop() {
        BaseGraph graph = new BaseGraph.Builder(1).create();
        //   4
        //   |
        // 0-1-2
        //   |/
        //   3
        graph.edge(0, 1);
        graph.edge(1, 2);
        graph.edge(2, 3);
        graph.edge(3, 1);
        graph.edge(1, 4);
        LongFunction<Iterator<IntCursor>> edgesByWay = way -> IntArrayList.from(Math.toIntExact(way)).iterator();
        OSMRestrictionException e = assertThrows(OSMRestrictionException.class, () ->
                new WayToEdgeConverter(graph, edgesByWay).convertForViaWays(ways(0), ways(1, 2, 3), ways(4)));
        // So far we allow the via ways/edges to be in an arbitrary order, but do not allow multiple solutions.
        assertTrue(e.getMessage().contains("has member ways that do not form a unique path"), e.getMessage());
    }