【发布时间】:2012-10-09 01:27:55
【问题描述】:
org.apache.commons.collections15.Factory中的java代码有什么用
- 是否有文档(我找不到任何有用的东西)
- 如何在 Java Jung 图形包中的 BarabasiAlbertGenerator 的构造函数中使用它来实例化以下类型的对象:
Factory<Integer>、Factory<String>? - 我怎样才能获得正常运行的 BarabasiAlbertGenerator。
这是我的代码,它只输出一个顶点。
Factory<Graph<String, Integer>> graphFactory = SparseGraph.getFactory();
Integer[] ints = {1};
String[] strs = {"12"};
Class[] typesStr = {String.class};
Class[] typesInt = {int.class};
Factory<String> vertexFactory = InstantiateFactory.getInstance(String.class, typesStr, strs);
Factory<Integer> edgeFactory = InstantiateFactory.getInstance(Integer.class, typesInt, ints);
HashSet<String> seedVertices = new HashSet();
for(int i = 0; i < 10; i++)
{
seedVertices.add("v"+i);
}
BarabasiAlbertGenerator<String, Integer> barabasiGen = new
BarabasiAlbertGenerator<String,Integer>(graphFactory, vertexFactory,
edgeFactory, seedVertices.size(), 1, seedVertices);
Graph g = barabasiGen.create();
我认为我的问题与我的 vertexFactory 和 edgeFactory 有关。在我看来,我的 vertexFactory 似乎只能创建值为 12 的顶点,而我的 edgeFactory 只能创建值为 1 的边。因此,该图将只有 1 个值为 12 的顶点。这个推理准确吗?
【问题讨论】:
标签: java factory apache-commons factory-pattern jung