Home Wiki Blog Forum GEXF.net

Gephi forums

Community support

getNode() and contains() inconsistency

Please use a mailing-list, see http://gephi.org/developers/

getNode() and contains() inconsistency

Postby Maldoran » 15 Apr 2014 15:56

Hi, I'm trying to create my first plugin but I encountered a strange problem. I want to temporarily remove some nodes from graph, save them to a list, do something with the graph and finally take them back to the graph. Here is a simplified code which shows the problem.

Code: Select all
      UndirectedGraph g1 = gm.getUndirectedGraph();
      List<Node> list = new ArrayList<Node>();
      Node a = g1.getNode(24);
      Node b = g1.getNode(25);

      list.add(a);
      g1.removeNode(a);

      list.add(b);
      g1.removeNode(b);

      for (Node nodeToRestore : list) {
        g1.addNode(nodeToRestore);

        System.out.println(nodeToRestore.getId());
        System.out.println(g1.contains(nodeToRestore));
        System.out.println(g1.getNode(nodeToRestore.getId()));
      }


The result of this part of code is following

Code: Select all
24
true
null
25
true
null


And my question is: why the getNode() method returns null while the contains() method confirms presence of the node in the graph (and even the addNode() method returns true, which means the node was succesfully added).

Thank you for any response.
Maldoran
 
Posts: 2
Joined: 14 Apr 2014 19:25

Re: getNode() and contains() inconsistency

Postby Maldoran » 21 Apr 2014 22:46

Hi, when I was trying to figure it out, I found out that the problem occures when I am trying to re-add node. Check the code below:

Code: Select all
   
Node newNode = gm.factory().newNode("54");
graph.addNode(newNode);
System.out.println(graph.contains(newNode));
System.out.println(graph.getNode(newNode.getId()));

graph.removeNode(newNode);
System.out.println(graph.contains(newNode));
System.out.println(graph.getNode(newNode.getId()));
   
graph.addNode(newNode);
System.out.println(graph.contains(newNode));
System.out.println(graph.getNode(newNode.getId()));


The output is:
true
54
false
null
true
null


Does it help to track the problem? Can anybody help me now please? Thank you very much.
Maldoran
 
Posts: 2
Joined: 14 Apr 2014 19:25


Return to Development

Who is online

Users browsing this forum: No registered users and 0 guests

sports medicine portsmouth nh where to buy metronidazole