本文整理汇总了Java中org.apache.commons.collections15.Factory类的典型用法代码示例。如果您正苦于以下问题:Java Factory类的具体用法?Java Factory怎么用?Java Factory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Factory类属于org.apache.commons.collections15包,在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initAlgo
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
@Override
public void initAlgo() {
if (graphModel == null) {
throw new RuntimeException(
"The GraphModel for this layout cannot be null!");
}
graph = graphModel.getGraphVisible();
circleNodeDataMap = LazyMap.decorate(
new HashMap<Node, CircleNodeData>(),
new Factory<CircleNodeData>() {
public CircleNodeData create() {
return new CircleNodeData();
}
});
nodeOrderedList = new ArrayList<Node>();
for (Node n : graph.getNodes())
nodeOrderedList.add(n);
if (LayoutLoader.VERBOSE_LAYOUT)
Cuttlefish.debug(this, "Layout initialized.");
}
示例2: setup
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
@Override
public void setup() {
this.graph = new DirectedSparseMultigraph<Vertex, Edge>();
this.edgeWeights = new HashMap<Edge, Number>();
this.edgeFactory = new Factory<Integer>() {
int i = 0;
public Integer create() {
return i++;
}
};
this.disambiguatedSurfaceForms = new BitSet(repList.size());
for (int i = 0; i < repList.size(); i++) {
if (repList.get(i).getCandidates().size() <= 1) {
this.disambiguatedSurfaceForms.set(i);
}
}
buildMainGraph();
}
示例3: setup
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
@Override
public void setup() {
this.graph = new DirectedSparseMultigraph<Vertex, Edge>();
this.edgeWeights = new HashMap<Edge, Number>();
this.edgeFactory = new Factory<Integer>() {
int i = 0;
public Integer create() {
return i++;
}
};
for (SurfaceForm sf : repList) {
SurfaceForm clone = (SurfaceForm) sf.clone();
this.origList.add(clone);
}
this.disambiguatedSurfaceForms = new BitSet(repList.size());
for (int i = 0; i < repList.size(); i++) {
if (repList.get(i).getCandidates().size() <= 1) {
this.disambiguatedSurfaceForms.set(i);
}
}
buildMainGraph();
}
示例4: setup
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
@Override
public void setup() {
this.graph = new DirectedSparseMultigraph<Vertex, Edge>();
this.edgeWeights = new HashMap<Edge, Number>();
this.edgeFactory = new Factory<Integer>() {
int i = 0;
public Integer create() {
return i++;
}
};
// List<SurfaceForm> list = new LinkedList<SurfaceForm>();
// for (SurfaceForm r : this.repList) {
// list.add((SurfaceForm) r.clone());
// }
// Collections.sort(list);
// this.repList = list;
this.disambiguatedSurfaceForms = new BitSet(repList.size());
for (int i = 0; i < repList.size(); i++) {
if (repList.get(i).getCandidates().size() <= 1) {
this.disambiguatedSurfaceForms.set(i);
}
}
buildMainGraph();
}
示例5: setup
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
public void setup() {
this.graph = new DirectedSparseMultigraph<Vertex, Edge>();
this.edgeWeights = new HashMap<Edge, Number>();
this.edgeFactory = new Factory<Integer>() {
int i = 0;
public Integer create() {
return i++;
}
};
List<SurfaceForm> list = new LinkedList<SurfaceForm>();
for (SurfaceForm r : this.repList) {
list.add((SurfaceForm) r.clone());
}
Collections.sort(list);
this.repList = list;
this.disambiguatedSurfaceForms = new BitSet(repList.size());
for (int i = 0; i < repList.size(); i++) {
if (repList.get(i).getCandidates().size() <= 1) {
this.disambiguatedSurfaceForms.set(i);
}
}
buildMainGraph();
}
示例6: getInstance
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
* Factory method that performs validation.
* <p/>
* Creates a Factory that will return a clone of the same prototype object
* each time the factory is used. The prototype will be cloned using one of these
* techniques (in order):
* <ul>
* <li>public clone method
* <li>public copy constructor
* <li>serialization clone
* <ul>
*
* @param prototype the object to clone each time in the factory
* @return the <code>prototype</code> factory
* @throws IllegalArgumentException if the prototype is null
* @throws IllegalArgumentException if the prototype cannot be cloned
*/
public static <T> Factory<T> getInstance(T prototype) {
if (prototype == null) {
return ConstantFactory.NULL_INSTANCE;
}
try {
Method method = prototype.getClass().getMethod("clone", null);
return new PrototypeCloneFactory<T>(prototype, method);
} catch (NoSuchMethodException ex) {
try {
prototype.getClass().getConstructor(new Class[]{prototype.getClass()});
return new InstantiateFactory<T>((Class<T>) prototype.getClass(), new Class[]{prototype.getClass()}, new Object[]{prototype});
} catch (NoSuchMethodException ex2) {
if (prototype instanceof Serializable) {
return new PrototypeSerializationFactory((Serializable) prototype);
}
}
}
throw new IllegalArgumentException("The prototype must be cloneable via a public clone method");
}
示例7: getInstance
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
* Factory method that performs validation.
*
* @param classToInstantiate the class to instantiate, not null
* @param paramTypes the constructor parameter types
* @param args the constructor arguments
* @return a new instantiate factory
*/
public static <T> Factory<T> getInstance(Class<T> classToInstantiate, Class[] paramTypes, Object[] args) {
if (classToInstantiate == null) {
throw new IllegalArgumentException("Class to instantiate must not be null");
}
if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) {
throw new IllegalArgumentException("Parameter types must match the arguments");
}
if (paramTypes == null || paramTypes.length == 0) {
return new InstantiateFactory<T>(classToInstantiate);
} else {
paramTypes = (Class[]) paramTypes.clone();
args = (Object[]) args.clone();
return new InstantiateFactory<T>(classToInstantiate, paramTypes, args);
}
}
示例8: RoleGraphViewer
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/** Creates a new instance of SimpleGraphView */
public RoleGraphViewer() {
// Graph<V, E> where V is the type of the vertices and E is the type of
// the edges
g = new SparseMultigraph<Integer, String>();
nodeCount = 0;
edgeCount = 0;
vertexFactory = new Factory<Integer>() { // My vertex factory
public Integer create() {
return nodeCount++;
}
};
edgeFactory = new Factory<String>() { // My edge factory
public String create() {
return "E" + edgeCount++;
}
};
}
示例9: GraphViewerPanelManager
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
public GraphViewerPanelManager(TopologyManagerFrame frame, String projectType, File projectPath, TopologyViewerConfigManager viewerConfigPath,
File graphmlFile, Factory<G> factory, JTabbedPane tabbedPane,
GraphType graphType, GraphViewerPanelFactory graphViewerPanelFactory) throws Exception {
this.frame = frame;
this.projectPath = projectPath;
this.graphType = graphType;
this.viewerConfigManager = viewerConfigPath;
versionDir = new File(new File(graphmlFile.getParent()).getParent());
// TODO remove this Hardcode
this.deviceXmlPath = versionDir;
this.graphmlFileName = graphmlFile;
this.factory = factory;
this.tabbedPane = tabbedPane;
entireGraph = factory.create();
viewerConfig = viewerConfigManager.getTopologyViewerConfType();
this.layout="FRLayout";
this.graphViewerPanelFactory = graphViewerPanelFactory;
}
示例10: Lattice2DGenerator
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
* Creates a generator of {@code row_count} x {@code col_count} lattices
* with the specified parameters.
*
* @param graph_factory used to create the {@code Graph} for the lattice
* @param vertex_factory used to create the lattice vertices
* @param edge_factory used to create the lattice edges
* @param row_count the number of rows in the lattice
* @param col_count the number of columns in the lattice
* @param isToroidal if true, the created lattice wraps from top to bottom and left to right
*/
public Lattice2DGenerator(Factory<? extends Graph<V,E>> graph_factory, Factory<V> vertex_factory,
Factory<E> edge_factory, int row_count, int col_count, boolean isToroidal)
{
if (row_count < 2 || col_count < 2)
{
throw new IllegalArgumentException("Row and column counts must each be at least 2.");
}
this.row_count = row_count;
this.col_count = col_count;
this.is_toroidal = isToroidal;
this.graph_factory = graph_factory;
this.vertex_factory = vertex_factory;
this.edge_factory = edge_factory;
this.is_directed = (graph_factory.create().getDefaultEdgeType() == EdgeType.DIRECTED);
}
示例11: BarabasiAlbertGenerator
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
* Constructs a new instance of the generator.
* @param init_vertices number of unconnected 'seed' vertices that the graph should start with
* @param numEdgesToAttach the number of edges that should be attached from the
* new vertex to pre-existing vertices at each time step
* @param directed specifies whether the graph and edges to be created should be directed or not
* @param parallel specifies whether the algorithm permits parallel edges
* @param seed random number seed
*/
public BarabasiAlbertGenerator(Factory<Graph<V,E>> graphFactory,
Factory<V> vertexFactory, Factory<E> edgeFactory,
int init_vertices, int numEdgesToAttach,
int seed, Set<V> seedVertices)
{
assert init_vertices > 0 : "Number of initial unconnected 'seed' vertices " +
"must be positive";
assert numEdgesToAttach > 0 : "Number of edges to attach " +
"at each time step must be positive";
mNumEdgesToAttachPerStep = numEdgesToAttach;
mRandom = new Random(seed);
this.graphFactory = graphFactory;
this.vertexFactory = vertexFactory;
this.edgeFactory = edgeFactory;
this.init_vertices = init_vertices;
initialize(seedVertices);
}
示例12: ErdosRenyiGenerator
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
*
* @param numVertices number of vertices graph should have
* @param p Connection's probability between 2 vertices
*/
public ErdosRenyiGenerator(Factory<UndirectedGraph<V,E>> graphFactory,
Factory<V> vertexFactory, Factory<E> edgeFactory,
int numVertices,double p)
{
if (numVertices <= 0) {
throw new IllegalArgumentException("A positive # of vertices must be specified.");
}
mNumVertices = numVertices;
if (p < 0 || p > 1) {
throw new IllegalArgumentException("p must be between 0 and 1.");
}
this.graphFactory = graphFactory;
this.vertexFactory = vertexFactory;
this.edgeFactory = edgeFactory;
mEdgeConnectionProbability = p;
mRandom = new Random();
}
示例13: toUndirected
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
/**
* Transforms <code>graph</code> (which may be of any directionality)
* into an undirected graph. (This may be useful for
* visualization tasks).
* Specifically:
* <ul>
* <li/>Vertices are copied from <code>graph</code>.
* <li/>Directed edges are 'converted' into a single new undirected edge in the new graph.
* <li/>Each undirected edge (if any) in <code>graph</code> is 'recreated' with a new undirected edge in the new
* graph if <code>create_new</code> is true, or copied from <code>graph</code> otherwise.
* </ul>
*
* @param graph the graph to be transformed
* @param create_new specifies whether existing undirected edges are to be copied or recreated
* @param graph_factory used to create the new graph object
* @param edge_factory used to create new edges
* @return the transformed <code>Graph</code>
*/
public static <V,E> UndirectedGraph<V,E> toUndirected(Graph<V,E> graph,
Factory<UndirectedGraph<V,E>> graph_factory,
Factory<E> edge_factory, boolean create_new)
{
UndirectedGraph<V,E> out = graph_factory.create();
for (V v : graph.getVertices())
out.addVertex(v);
for (E e : graph.getEdges())
{
Pair<V> endpoints = graph.getEndpoints(e);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
E to_add;
if (graph.getEdgeType(e) == EdgeType.DIRECTED || create_new)
to_add = edge_factory.create();
else
to_add = e;
out.addEdge(to_add, v1, v2, EdgeType.UNDIRECTED);
}
return out;
}
示例14: createAddEdge
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected E createAddEdge(StringTokenizer st, V v1,
EdgeType directed, Graph<V,E> g, List<V> id, Factory<E> edge_factory)
{
int vid2 = Integer.parseInt(st.nextToken()) - 1;
V v2;
if (id != null)
v2 = id.get(vid2);
else
v2 = (V)new Integer(vid2);
E e = edge_factory.create();
// don't error-check this: let the graph implementation do whatever it's going to do
// (add the edge, replace the existing edge, throw an exception--depends on the graph implementation)
g.addEdge(e, v1, v2, directed);
return e;
}
示例15: read
import org.apache.commons.collections15.Factory; //导入依赖的package包/类
public void read(Graph<V,E> graph, String file, Factory<V> vf, Factory<E> ef) throws ParserConfigurationException, SAXException, IOException{
//Step 1 we make a new GraphML Reader. We want an Undirected Graph of type node and edge.
GraphMLReader<Graph<V,E>, V,E> gmlr = new GraphMLReader<Graph<V,E>, V,E>(vf, ef);
//Here we read in our graph. filename is our .graphml file, and graph is where we will store our graph.
gmlr.load(file, graph);
BidiMap<V, String> vertex_ids = gmlr.getVertexIDs(); //The vertexIDs are stored in a BidiMap.
Map<String, GraphMLMetadata<V>> vertex_color = gmlr.getVertexMetadata(); //Our vertex Metadata is stored in a map.
Map<String, GraphMLMetadata<E>> edge_meta = gmlr.getEdgeMetadata(); // Our edge Metadata is stored in a map.
// Here we iterate through our vertices, n, and we set the value and the color of our nodes from the data we have
// in the vertex_ids map and vertex_color map.
for (V n : graph.getVertices())
{
//n.setValue(vertex_ids.get(n)); //Set the value of the node to the vertex_id which was read in from the GraphML Reader.
//n.setColor(vertex_color.get("d0").transformer.transform(n)); // Set the color, which we get from the Map vertex_color. //Let's print out the data so we can get a good understanding of what we've got going on.
//System.out.println("ID: "+n.getID()+", Value: "+n.getValue()+", Color: "+n.getColor());
}
// Just as we added the vertices to the graph, we add the edges as well.
for (E e : graph.getEdges())
{
//e.setValue(edge_meta.get("d1").transformer.transform(e)); //Set the edge's value.
//System.out.println("Edge ID: "+e.getID());
}
}