Find Nodes in a Graph [message #558190] |
Fri, 10 September 2010 09:31  |
Eclipse User |
|
|
|
I am currently using Zest to create a graphic representation of a model as part of a GUI I'm making. It creates a Graph object by doing an in-depth search of the model.
public void makeGraph(DNode node, GraphNode father) //the DNode class is dependent on the project I'm working on, not Zest itself.
{
GraphNode newNode = new GraphNode(graph, SWT.NONE, node.getNodeName();
if(father!=null)
new GraphConnection(graph, SWT.NONE, newNode, father);
/* some actions irrelevant to the matter at hand */
for(DNode comp: node.children())
makeGraph(comp, newNode);
}
Unfortunately, the search method will often find the same node twice; to avoid creating duplicates, I need a way to check if the node already exists within the graph.
My first idea was to do something like this:
public void makeGraph(DNode node, GraphNode father)
{
if(graph.getNodes().contains(node.getNodeName())
/* the node already exists; just add a connection to it. */
else
/* New node; create it, connect to it, call makeGraph() for its children. */
Unfortunately, that didn't work either. I'm not sure why, but the "if" was never answered positively, and I still ended up with a lot of duplicates.
So I'm left wondering...How does one actually check if a node exists in a Graph?
|
|
|
|
|
|
|
|
Re: Find Nodes in a Graph [message #559641 is a reply to message #559620] |
Fri, 17 September 2010 09:36  |
Eclipse User |
|
|
|
No Real Name wrote on Fri, 17 September 2010 14:11 | OK, found the problem by accident while adding comments to the program: Because of modifications I had made to the program's structure, graph.appLayout() got called before I created the nodes.
|
Great - and thanks for telling your solution!
|
|
|
Powered by
FUDForum. Page generated in 0.04675 seconds