Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | package edu.uci.ics.jung.utils; | |
11 | import java.util.Iterator; | |
12 | import edu.uci.ics.jung.algorithms.cluster.ClusterSet; | |
13 | import edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer; | |
14 | import edu.uci.ics.jung.graph.Edge; | |
15 | import edu.uci.ics.jung.graph.Graph; | |
16 | import edu.uci.ics.jung.graph.Vertex; | |
17 | /** | |
18 | * @author Scott White | |
19 | * | |
20 | */ | |
21 | 0 | public class GraphProperties { |
22 | ||
23 | /** | |
24 | * Checks to see whether the graph is connected. | |
25 | * @param g the graph | |
26 | * @return Return true if yes, false if no | |
27 | */ | |
28 | public static boolean isConnected(Graph g) { | |
29 | 0 | WeakComponentClusterer wc = new WeakComponentClusterer(); |
30 | 0 | ClusterSet cs = wc.extract(g); |
31 | 0 | return cs.size() == 1; |
32 | } | |
33 | ||
34 | /** | |
35 | * Checks to see whether the graphs is simple (that is, whether it contains | |
36 | * parallel edges and self-loops). | |
37 | * @param g the graph | |
38 | * @return true if yes, false if no | |
39 | */ | |
40 | public static boolean isSimple(Graph g) { | |
41 | 0 | return !containsSelfLoops(g) && !containsParallelEdges(g); |
42 | } | |
43 | ||
44 | /** | |
45 | * Checks to see whether the graphs contains self-loops | |
46 | * @param g the graph | |
47 | * @return true if yes, false if no | |
48 | */ | |
49 | public static boolean containsSelfLoops(Graph g) { | |
50 | 0 | for (Iterator vIt = g.getVertices().iterator(); vIt.hasNext();) { |
51 | 0 | Vertex v = (Vertex) vIt.next(); |
52 | 0 | if (v.findEdge(v) != null) { |
53 | 0 | return true; |
54 | } | |
55 | } | |
56 | 0 | return false; |
57 | } | |
58 | ||
59 | /** | |
60 | * Checks to see whether the graphs contains parallel edges | |
61 | * @param g the graph | |
62 | * @return true if yes, false if no | |
63 | */ | |
64 | public static boolean containsParallelEdges(Graph g) { | |
65 | 0 | for (Iterator eIt = g.getEdges().iterator(); eIt.hasNext();) { |
66 | 0 | Edge e = (Edge) eIt.next(); |
67 | 0 | Pair endpoints = e.getEndpoints(); |
68 | 0 | Vertex anEndPoint = (Vertex) endpoints.getFirst(); |
69 | 0 | Vertex anotherEndPoint = (Vertex) endpoints.getSecond(); |
70 | 0 | if (anEndPoint.findEdgeSet(anotherEndPoint).size() > 1) { |
71 | 0 | return true; |
72 | } | |
73 | } | |
74 | 0 | return false; |
75 | } | |
76 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |