0

I am trying to initialize each of the following where the Graph Object comes from the JUNG graph package (Factory comes from org.apache.commons.collections15):

        Factory<Graph<Integer, String>> graphFactory;
        Factory<Integer> vertexFactory;
        Factory<String> edgeFactory;

I need these three objects in the constructor of the BarabasiAlbertGenerator (click for JavaDoc) Object.

In my reading of the Factory Pattern, I see that it is used to pass off the instantiation of objects to subclasses. So, what I know is:

  1. There must be some class in the Jung Package that implements the Factory interface that can then instantiate the object I declare 'graphFactory'. Similarly for vertexFactory and edgeFactory

The question is (is what I am assuming correct as well) how do I instantiate these objects and which set of possible types could/would I use for instantiating each object?

CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216

1 Answers1

1

For the graphFactory, you can use the getFactory() static method on the class of graph that you want.

You will need to write instances of vertexFactory and edgeFactory.
You can use any type for vertex/edge, that's why they're generic (and that's why you have to specify how they're created). :)
Check out the sample code for examples.

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18
  • Thanks! Could you give a little more detail about the vertexFactory and edgeFactory? I am not quite sure what you mean by "write instances of vertexFactory and edgeFactory" – CodeKingPlusPlus Oct 08 '12 at 20:56
  • Also, where are these code examples for instantiating factories? – CodeKingPlusPlus Oct 08 '12 at 22:04
  • Try searching the code for "vertexfactory". They appear anywhere in the samples that a graph is being generated algorithmically (as opposed to retrieved from storage or built with explicit user-supplied add*() calls). – Joshua O'Madadhain Oct 19 '12 at 20:37