简体   繁体   English

如何使用Java API删除graphstream的节点?

[英]How to remove nodes with java API for graphstream?

I currently use the Graphstream API for Java for my project. 我目前在我的项目中使用Graphstream API for Java。

I wan't to delete or add Nodes on command. 我不会在命令中删除或添加节点。 With JFrame & co. 与JFrame&co。 I initialized a console so I can just insert "addNode()" or "removeNode(id)" in order to get the result. 我初始化了一个控制台,所以我可以只插入“ addNode()”或“ removeNode(id)”以获得结果。

A Interface shows the nodes with a number next to them(the ID). 接口显示节点旁边有一个数字(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. 当我删除一个节点时,我希望所有具有较高ID的节点都更改其ID,但是我没有找到一种方法来更改一个节点的ID。

Fe I have: Fe我有:

    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. 我希望将1,2更改为0,1,而无需重新初始化完整的图形。

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. 不幸的是,我只能访问.getID(),不能以这种方式进行操作。

Thanks 谢谢

Nodes ids are strings and they are immutable (no renaming, no setId() ). 节点ID是字符串,并且是不可变的(无重命名,无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. 索引是整数,并且与图中的任意节点相对应,它们与id无关。

When you do graph.addNode(0) , the integer is converted to the string "0" . 当您执行graph.addNode(0) ,该整数将转换为字符串 "0" Then when you do graph.removeNode(0), you are removing a node that was indexed as the first of the list of nodes. 然后,当执行graph.removeNode(0)时,将删除索引为节点列表中第一个节点的节点。 But it does have to be the node this id "0" . 但是它确实必须是该节点的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") ). 只要图中有节点( graph.removeNode(0) ),就可以删除索引(整数)为0的节点,但是只能删除一次ID为"0"节点一次( graph.removeNode("0") )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM