'How can I find an Object in a HashSet that fills a certain requirement

I am trying to connect two Nodes with edges, and in the incomplete "else if" statement I want to check if there already IS an edge connection between Nodes "a" and "b". If so, we will throw IllegalStateException, but if there is no edge connection we will make one. Each node works as a key in a HashMap which unlocks a HashSet of edges that the node has. So in the else if I want to look in Node a's HashSet of edges and see if there already exists an edge pointing towards node "b". Or vice versa. But I can't figure out what to put in the else if statement. I've tried to do aEdges.contains(Edge.getDestination().equals(b)).

I hope this explanation was somewhat helpful.

public void connect(Node a, Node b, String name, double weight) {

        if (nodes.containsKey(a) && nodes.containsKey(b)) {
            Set<EdgeRoute> aEdges = nodes.get(a);
            Set<EdgeRoute> bEdges = nodes.get(b);

            if (weight < 0) {
                throw new IllegalArgumentException();
            } else if() {
                throw new IllegalStateException();
            } else {
                aEdges.add(new EdgeRoute(b, name, weight));
                bEdges.add(new EdgeRoute(a, name, weight));
            }

        } else {
            throw new NoSuchElementException();
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source