lundi 2 mars 2020

Check connections of nodes

This code checks if any startPoint has greater than or equal to 2 connections. Now, I am struggling with doing the same thing with the endpoints. There are two endpoints which can be accessed by getEndPoints().get(0) / getEndPoints().get(1). Each of them can also only have greater than or equal to 2 connections. However, to make a long story short, there can also be a case where there is only one endPoint. In this project there are normal tracks and switches. Normal tracks only have one endPoint while switches have two endpoints.

So I try to check this without limiting myself to one or two endpoints.

    // TODO: Check connections of endpoints
    List<Track> connections = edges.computeIfAbsent(track.getStartPoint(), x -> new ArrayList<>());
    if (connections.size() >= 2) {
        throw new LogicException("only one other track (normal track or track switch) can be "
                + "connected at any one point on a track");
    }

I hope I've made it reasonably clear. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire