# Coverage details for edu.uci.ics.jung.graph.impl.KPartiteSparseGraph

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Created on Mar 29, 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.graph.impl;`
13 |  | ``
14 |  | `import java.util.Collection;`
15 |  | `import java.util.Iterator;`
16 |  | ``
17 |  | `import org.apache.commons.collections.Predicate;`
18 |  | `import org.apache.commons.collections.functors.OnePredicate;`
19 |  | ``
20 |  | `import edu.uci.ics.jung.graph.Edge;`
21 |  | `import edu.uci.ics.jung.graph.Graph;`
22 |  | `import edu.uci.ics.jung.graph.KPartiteGraph;`
23 |  | `import edu.uci.ics.jung.graph.Vertex;`
24 |  | `import edu.uci.ics.jung.graph.predicates.KPartiteEdgePredicate;`
25 |  | `import edu.uci.ics.jung.utils.SubsetManager;`
26 |  | ``
27 |  | ``
28 |  | `/**`
29 |  | `* An implementation of KPartiteGraph based on SparseGraph.`
30 |  | `* This implementation optionally creates a subset for each partition`
31 |  | `* specified in the constructor.`
32 |  | `*`
33 |  | `* <p>Vertex constraints imposed by this class: predicates in`
34 |  | `* <code>partitions</code> constructor argument</p>`
35 |  | `* <p>Edge constraints imposed by this class:`
36 |  | `* <code>KPartiteEdgePredicate(partitions)</code></p>`
37 |  | `*`
38 |  | `* @author Joshua O'Madadhain`
39 |  | `*/`
40 |  | `public class KPartiteSparseGraph extends SparseGraph implements KPartiteGraph`
41 |  | `{`
42 |  | `protected Collection partitions;`
43 |  | ``
44 |  | `/**`
45 |  | `* Creates a KPartiteSparseGraph whose partitions are specified by`
46 |  | `* the predicates in the <code>partitions</code> array. If the`
47 |  | `* <code>subsets</code> argument is true, creates a subset for`
48 |  | `* each partition.`
49 |  | `*/`
50 |  | `public KPartiteSparseGraph(Collection partitions, boolean subsets)`
51 |  | `{`
52 | 18 | `super();`
53 | 18 | `if (partitions.size() < 2)`
54 | 0 | `throw new IllegalArgumentException("Constructor must " +`
55 |  | `"specify >= 2 vertex partition predicates");`
56 | 18 | `this.partitions = partitions;`
57 |  | ``
58 |  | `// each vertex added must satisfy exactly 1 partition-specific predicate`
59 | 18 | `getVertexConstraints().add(OnePredicate.getInstance(partitions));`
60 |  | ``
61 |  | `// each edge added must connect vertices in distinct partitions`
62 |  | `// user_edge_requirements.add(new KPartiteEdgePredicate(partitions));`
63 | 18 | `getEdgeConstraints().add(new KPartiteEdgePredicate(partitions));`
64 |  | ``
65 |  | `// create a subset for each vertex predicate`
66 | 18 | `if (subsets)`
67 |  | `{`
68 | 18 | `SubsetManager sm = SubsetManager.getInstance(this);`
69 | 18 | `for (Iterator p_iter = partitions.iterator(); p_iter.hasNext(); )`
70 | 36 | `sm.addVertexSubset((Predicate)p_iter.next());`
71 |  | `}`
72 | 18 | `}`
73 |  | ``
74 |  | `/**`
75 |  | `* <p>`
76 |  | `* Creates a new <code>KPartiteSparseGraph</code> which contains all the`
77 |  | `* vertices and edges in <code>g</code>. The new graph contains all the`
78 |  | `* user data from the original graph and its components.`
79 |  | `* </p>`
80 |  | `* <p>`
81 |  | `* This method performs no tagging or structural conversion. If`
82 |  | `* <code>g</code> is not compatible with the constraints specified by`
83 |  | `* <code>partitions</code>, this constructor will throw an`
84 |  | `* <code>IllegalArgumentException</code>. Thus, each vertex in`
85 |  | `* <code>g</code> must be a member of exactly one partition, and each edge`
86 |  | `* must join vertices in distinct partitions.`
87 |  | `* </p>`
88 |  | `*/`
89 |  | `public KPartiteSparseGraph(Graph g, Collection partitions, boolean subsets)`
90 |  | `{`
91 | 4 | `this(partitions, subsets);`
92 |  | ``
93 | 4 | `addAllNotInitializers(getEdgeConstraints(), g.getEdgeConstraints());`
94 | 4 | `addAllNotInitializers(getVertexConstraints(), g.getVertexConstraints());`
95 | 4 | `for (Iterator iter = g.getVertices().iterator(); iter.hasNext();)`
96 |  | `{`
97 | 16 | `Vertex av = (Vertex) iter.next();`
98 | 16 | `av.copy(this);`
99 |  | `}`
100 |  | ``
101 | 3 | `for (Iterator iter = g.getEdges().iterator(); iter.hasNext();)`
102 |  | `{`
103 | 8 | `Edge ae = (Edge) iter.next();`
104 | 8 | `ae.copy(this);`
105 |  | `}`
106 |  | ``
107 | 1 | `this.importUserData(g);`
108 | 1 | `}`
109 |  | ``
110 |  | `public Collection getPartitions()`
111 |  | `{`
112 | 3 | `return partitions;`
113 |  | `}`
114 |  | `}`

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.