Coverage details for edu.uci.ics.jung.graph.predicates.ParallelEdgePredicate

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 * Created on Mar 8, 2004
11 */
12 package edu.uci.ics.jung.graph.predicates;
13  
14 import java.util.Iterator;
15 import java.util.Set;
16  
17 import edu.uci.ics.jung.graph.ArchetypeEdge;
18 import edu.uci.ics.jung.graph.DirectedEdge;
19 import edu.uci.ics.jung.graph.Edge;
20 import edu.uci.ics.jung.graph.UndirectedEdge;
21 import edu.uci.ics.jung.graph.Vertex;
22 import edu.uci.ics.jung.utils.Pair;
23  
24 /**
25  * <p>A predicate that checks to see whether the specified edge
26  * is parallel to any other edge. A negation of this predicate
27  * may be used as an edge constraint that will prevent the
28  * constrained graph from accepting parallel edges. This
29  * predicate is probably not appropriate for use as a subset
30  * specification.</p>
31  *
32  * <p>Two distinct edges are considered to be <i>parallel</i> to one another
33  * if the following conditions hold:
34  * <ul>
35  * <li/>the edges are both directed or both undirected
36  * <li/>if undirected, the incident vertex sets for each edge are the same
37  * <li/>if directed, the edges have the same source vertex and the same
38  * destination vertex
39  * </ul>
40  * </p>
41  *
42  * @author Joshua O'Madadhain
43  */
44 public class ParallelEdgePredicate extends EdgePredicate
45 {
46     private static ParallelEdgePredicate instance;
47     private static final String message = "ParallelEdgePredicate";
48     
49     protected ParallelEdgePredicate()
50     {
5168        super();
5268    }
53     
54     public static ParallelEdgePredicate getInstance()
55     {
56211        if (instance == null)
5768            instance = new ParallelEdgePredicate();
58211        return instance;
59     }
60  
61     public String toString()
62     {
630        return message;
64     }
65     
66     /**
67      * <p>Returns <code>true</code> if there exists an
68      * edge which is parallel to the specified edge.</p>
69      *
70      * @see Vertex#findEdgeSet(Vertex)
71      */
72     public boolean evaluateEdge(ArchetypeEdge ae)
73     {
74148056        Edge e = (Edge)ae;
75148056        Pair endpoints = e.getEndpoints();
76148056        Vertex u = (Vertex)(endpoints.getFirst());
77148056        Vertex v = (Vertex)(endpoints.getSecond());
78148056        Set s = u.findEdgeSet(v);
79148056        if (isDirected(e))
803717            return evaluateDirectedEdge((DirectedEdge)e, s.iterator());
81         else
82144339            return evaluateUndirectedEdge((UndirectedEdge)e, s.iterator());
83     }
84     
85     protected boolean evaluateDirectedEdge(DirectedEdge de, Iterator s_iter)
86     {
873752        while (s_iter.hasNext())
88         {
8948            Edge f = (Edge)s_iter.next();
9048            if (de != f && isDirected(f))
91             {
9213                DirectedEdge df = (DirectedEdge)f;
9313                if ((df.getSource() == de.getSource()) &&
94                     (df.getDest() == de.getDest()))
9513                    return true;
96             }
97         }
983704        return false;
99     }
100     
101     protected boolean evaluateUndirectedEdge(UndirectedEdge ue, Iterator s_iter)
102     {
103144389        while (s_iter.hasNext())
104         {
10557            Edge f = (Edge)s_iter.next();
10657            if (ue != f && !isDirected(f))
107             {
1087                if (f.getIncidentVertices().equals(ue.getIncidentVertices()))
1097                    return true;
110             }
111         }
112144332        return false;
113     }
114     
115     protected boolean isDirected(Edge e)
116     {
117148087        if (e instanceof DirectedEdge)
1183737            return true;
119144350        else if (e instanceof UndirectedEdge)
120144350            return false;
121         else
1220            throw new IllegalArgumentException(e + "is neither directed nor undirected");
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.