org.jgrapht.graph.DefaultEdge上的DefaultEdge方法getSource()
和方法受到保护。getTarget()
我应该如何访问org.jgrapht.graph.SimpleGraphedgeSet()
返回的每个边的源顶点和目标顶点?
下面的代码显示了正在发生的事情。
import java.util.Set;
import org.jgrapht.UndirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.SimpleGraph;
public class TestEdges
{
public static void main(String [] args)
{
UndirectedGraph<String, DefaultEdge> g =
new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
String A = "A";
String B = "B";
String C = "C";
// add the vertices
g.addVertex(A);
g.addVertex(B);
g.addVertex(C);
g.addEdge(A, B);
g.addEdge(B, C);
g.addEdge(A, C);
Set<DefaultEdge> edges = g.edgeSet();
for(DefaultEdge edge : edges) {
String v1 = edge.getSource(); // Error getSource() is protected method
String v2 = edge.getTarget(); // Error getTarget() is protected method
}
}
}