tags:

views:

108

answers:

1

I have to create a graph with its self-defined node type and the nodes & connections are read from a txt file one by one.

The file format is like this: startNode attibutes endNode.

Every time I read one line, I created 2 node objects: startNode & endNode. and add edge between them..

However, the startNode may exist in several lines..

e.g. V1 ... V2 ; V1 ... V3

Therefore, I have to check whether my graph has contained the node before I add edges..and I should use the vertex in graphs instead of the node newly created..

Does jung have any built-in method to solve this problem? Or any suggestions?

A: 

JUNG considers the vertices (and edges) different as long as they are referenced to different objects. If you create two vertex objects with same properties, they will be considered as different vertices and you will be able to insert both of them into the graph. JUNG doesn't have an equals method that you can override (to check the vertex object's properties) to perform a check whether two vertex objects are the same or not. Therefore you need to manually maintain the list of vertices (and edges) in your graph to avoid adding a vertex you already have in your graph. However you can easily do that with a HashMap (if your graph is not too big).

jaxvy