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

LineHitsSource
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  */
210public 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) {
290        WeakComponentClusterer wc = new WeakComponentClusterer();
300        ClusterSet cs = wc.extract(g);
310        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) {
410        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) {
500        for (Iterator vIt = g.getVertices().iterator(); vIt.hasNext();) {
510            Vertex v = (Vertex) vIt.next();
520            if (v.findEdge(v) != null) {
530                return true;
54             }
55         }
560        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) {
650        for (Iterator eIt = g.getEdges().iterator(); eIt.hasNext();) {
660            Edge e = (Edge) eIt.next();
670            Pair endpoints = e.getEndpoints();
680            Vertex anEndPoint = (Vertex) endpoints.getFirst();
690            Vertex anotherEndPoint = (Vertex) endpoints.getSecond();
700            if (anEndPoint.findEdgeSet(anotherEndPoint).size() > 1) {
710                return true;
72             }
73         }
740        return false;
75     }
76 }

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.