0
votes

I currently use the Graphstream API for Java for my project.

I wan't to delete or add Nodes on command. With JFrame & co. I initialized a console so I can just insert "addNode()" or "removeNode(id)" in order to get the result.

A Interface shows the nodes with a number next to them(the ID).

When I delete one node, I want all nodes with higher ID to change their ID, but I did not figure out a way jet to change the ID of one node.

F.e. I have:

    graph.addNode(0);
    graph.addNode(1);
    graph.addNode(2);

When deleting a Node:

    graph.removeNode(0);

I want 1,2 to be changed to 0,1 without reinitializing the complete graph.

Is there a way to achieve this behaviour? I thought about something like:

    graph.getNode(1).setID(0);

Unfortunately I have only access to .getID() and can't manipulate it this way.

Thanks

1

1 Answers

0
votes

Nodes ids are strings and they are immutable (no renaming, no setId()).

Now what you are doing in your example is different. You are using the index-based access to the nodes. Indices are integers and correspond to arbitrary nodes in the graph, they are not associated to the ids.

When you do graph.addNode(0), the integer is converted to the string "0". Then when you do graph.removeNode(0), you are removing a node that was indexed as the first of the list of nodes. But it does have to be the node this id "0".

You can remove nodes with index (integer) 0 as long as there are nodes in the graph (graph.removeNode(0)) but you can only remove the one node with id "0" once (graph.removeNode("0")).