getNode() and contains() inconsistency

Please use a mailing-list, see http://gephi.org/developers/
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Maldoran
Posts:2
Joined:14 Apr 2014 18:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
getNode() and contains() inconsistency

Post by Maldoran » 15 Apr 2014 14: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 18:25
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: getNode() and contains() inconsistency

Post by Maldoran » 21 Apr 2014 21: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.

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable