Coverage details for edu.uci.ics.jung.utils.TypedVertexGenerator

LineHitsSource
1 /*
2  * Created on Apr 3, 2004
3  *
4  * Copyright (c) 2004, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.utils;
13  
14 import java.util.Collection;
15  
16 import edu.uci.ics.jung.exceptions.FatalException;
17 import edu.uci.ics.jung.graph.ArchetypeGraph;
18 import edu.uci.ics.jung.graph.Graph;
19 import edu.uci.ics.jung.graph.Vertex;
20 import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
21 import edu.uci.ics.jung.graph.impl.SimpleDirectedSparseVertex;
22 import edu.uci.ics.jung.graph.impl.SimpleSparseVertex;
23 import edu.uci.ics.jung.graph.impl.SimpleUndirectedSparseVertex;
24 import edu.uci.ics.jung.graph.impl.SparseVertex;
25 import edu.uci.ics.jung.graph.impl.UndirectedSparseVertex;
26  
27  
28 /**
29  * Generates vertices according to the edge requirements
30  * submitted to the constructor. This implementation
31  * respects edge direction (directed, undirected, mixed)
32  * as well as edge multiplicity (parallel edges). See the
33  * constructor for a list of the vertex types.
34  *
35  * @author Joshua O'Madadhain
36  */
37 public class TypedVertexGenerator implements VertexGenerator
38 {
39     protected Object type;
40  
41     /**
42      * if true, generated vertices won't support parallel edges
43      */
44     protected boolean simple;
45     
467    protected final static Object UNDIRECTED = "UNDIRECTED";
477    protected final static Object DIRECTED = "DIRECTED";
487    protected final static Object MIXED = "MIXED";
49 // protected final static Object TREE = "TREE";
50     
51     /**
52      * Determines the type of vertices that this generator will
53      * create, according to the edge requirements specified
54      * in the constructor:
55      *
56      * <ol>
57      * <li/>undirected, no parallel edges - creates @link{SimpleUndirectedSparseVertex}
58      * <li/>directed, no parallel edges - creates @link{SimpleDirectedSparseVertex}
59      * <li/>mixed (directed and undirected), no parallel edges - creates @link{SimpleSparseVertex}
60      * <li/>undirected, parallel edges allowed - creates @link{UndirectedSparseVertex}
61      * <li/>directed, parallel edges allowed - creates @link{DirectedSparseVertex}
62      * <li/>mixed, parallel edges allowed - creates @link{SparseVertex}
63      * </ol>
64      *
65      */
66     public TypedVertexGenerator(Collection edge_requirements)
6726    {
6826        if (edge_requirements.contains(Graph.UNDIRECTED_EDGE))
699            type = UNDIRECTED;
7017        else if (edge_requirements.contains(Graph.DIRECTED_EDGE))
716            type = DIRECTED;
72         else // mixed directed/undirected graph
7311            type = MIXED;
74         
7526        simple = edge_requirements.contains(Graph.NOT_PARALLEL_EDGE);
76         
77 // if (edge_requirements.contains(TreePredicate.getInstance()))
78 // type = TREE;
7926    }
80     
81     public TypedVertexGenerator(ArchetypeGraph g)
82     {
8313        this(g.getEdgeConstraints());
8413    }
85     
86     /**
87      * Creates a vertex whose type is determined by the requirements
88      * specified in the constructor.
89      *
90      * @see edu.uci.ics.jung.utils.VertexGenerator#create()
91      */
92     public Vertex create()
93     {
9475        if (type == UNDIRECTED)
95         {
9620            if (simple)
9717                return new SimpleUndirectedSparseVertex();
98             else
993                return new UndirectedSparseVertex();
100         }
10155        else if (type == DIRECTED)
102         {
1036            if (simple)
1045                return new SimpleDirectedSparseVertex();
105             else
1061                return new DirectedSparseVertex();
107         }
10849        else if (type == MIXED)
109         {
11049            if (simple)
1111                return new SimpleSparseVertex();
112             else
11348                return new SparseVertex();
114         }
115 // else if (type == TREE)
116 // {
117 // return new SimpleSparseTreeVertex();
118 // }
119         else
120         {
1210            throw new FatalException("Internal error: unrecognized vertex type");
122         }
123     }
124 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.