我对如何实现一些JUNG类感到很困惑。我正在尝试用“KleinbergSmallWorldGenerator”创建一个图形,但我不确定如何正确初始化。
我的代码:
Factory<? extends Graph<Integer, Integer>> graph_factory;
Factory<Integer> vertexFactory;
Factory<Integer> edgeFactory;
KleinbergSmallWorldGenerator<Integer,Integer> smallWorld;
public GraphView() {
smallWorld = new KleinbergSmallWorldGenerator<Integer,Integer>(graph_factory, vertexFactory, edgeFactory, 20, 3) ;
Graph2 = smallWorld.create();
}
即使我graph_factory.create();
帮助我理解;谢谢!
答案 0 :(得分:1)
graph_factory
,vertexFactory
和edgeFactory
都是null
。这是因为他们使用their initial value, per the JLS。
在构造函数中,我想你想传递这些对象的实例,而不是在你的无参数构造函数中初始化它们。
答案 1 :(得分:0)
示例:
static class GraphFactory implements Factory<Graph<Integer,String>> {
public Graph<Integer,String> create() {
return new SparseMultigraph<Integer,String>();
}
}
static class VertexFactory implements Factory<Integer> {
int a = 0;
public Integer create() {
return a++;
}
}
static class EdgeFactory implements Factory<String> {
char aa = 'a';
public String create() {
return Character.toString(aa++);
}
}
然后你召集这个例子
Graph<Integer, String> Eppstein = new EppsteinPowerLawGenerator<Integer,String>(new GraphFactory(), new VertexFactory(), new EdgeFactory(), 100, 400, 100).create();