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

Line | Hits | Source
--- | --- | ---
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 |  | ``
46 | 7 | `protected final static Object UNDIRECTED = "UNDIRECTED";`
47 | 7 | `protected final static Object DIRECTED = "DIRECTED";`
48 | 7 | `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)`
67 | 26 | `{`
68 | 26 | `if (edge_requirements.contains(Graph.UNDIRECTED_EDGE))`
69 | 9 | `type = UNDIRECTED;`
70 | 17 | `else if (edge_requirements.contains(Graph.DIRECTED_EDGE))`
71 | 6 | `type = DIRECTED;`
72 |  | `else // mixed directed/undirected graph`
73 | 11 | `type = MIXED;`
74 |  | ``
75 | 26 | `simple = edge_requirements.contains(Graph.NOT_PARALLEL_EDGE);`
76 |  | ``
77 |  | `// if (edge_requirements.contains(TreePredicate.getInstance()))`
78 |  | `// type = TREE;`
79 | 26 | `}`
80 |  | ``
81 |  | `public TypedVertexGenerator(ArchetypeGraph g)`
82 |  | `{`
83 | 13 | `this(g.getEdgeConstraints());`
84 | 13 | `}`
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 |  | `{`
94 | 75 | `if (type == UNDIRECTED)`
95 |  | `{`
96 | 20 | `if (simple)`
97 | 17 | `return new SimpleUndirectedSparseVertex();`
98 |  | `else`
99 | 3 | `return new UndirectedSparseVertex();`
100 |  | `}`
101 | 55 | `else if (type == DIRECTED)`
102 |  | `{`
103 | 6 | `if (simple)`
104 | 5 | `return new SimpleDirectedSparseVertex();`
105 |  | `else`
106 | 1 | `return new DirectedSparseVertex();`
107 |  | `}`
108 | 49 | `else if (type == MIXED)`
109 |  | `{`
110 | 49 | `if (simple)`
111 | 1 | `return new SimpleSparseVertex();`
112 |  | `else`
113 | 48 | `return new SparseVertex();`
114 |  | `}`
115 |  | `// else if (type == TREE)`
116 |  | `// {`
117 |  | `// return new SimpleSparseTreeVertex();`
118 |  | `// }`
119 |  | `else`
120 |  | `{`
121 | 0 | `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.