Search code examples
javagraphgraphstream

How to Detect if Multiple Nodes Exist in GraphStream


This is a pretty obscure question since I don't see many people fawning over GraphStream, but does anyone know how to detect if a node exists in the graph if it has been inserted?

For example, if I write

graph.addNode(vertex1);

I get an error. If I do the same thing and write

graph.addNode(vertex1);

This is because vertex1 already exists in the graph. I can't find anything in GraphStream's documentation here and I can't find an answer anywhere I look. Any help would be much appreciated.


Solution

  • From what I see in the Documentation :

    Throws: IdAlreadyInUseException - If strict checking is enabled the identifier is already used.

    You should be able to find out if an identifier is used by checking the returned value of getNode(vertex1.getId()).

    getNode(String id) :

    Returns: The searched node or null if not found.