[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 583: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 639: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
Gephi forums •getNode() and contains() inconsistency
Page 1 of 1

getNode() and contains() inconsistency

Posted: 15 Apr 2014 14:56
by Maldoran
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.

Re: getNode() and contains() inconsistency

Posted: 21 Apr 2014 21:46
by Maldoran
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.