I am pretty confused on how to implement some JUNG classes. I am trying to create a graph with "KleinbergSmallWorldGenerator" but I am not really sure how to initialize properly.
My code:
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();
}
I get "java.lang.NullPointerException" even if I do graph_factory.create();
Help me understand; Thanks!
Example:
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++);
}
}
And then you call for example this
Graph<Integer, String> Eppstein = new EppsteinPowerLawGenerator<Integer,String>(new GraphFactory(), new VertexFactory(), new EdgeFactory(), 100, 400, 100).create();