Coverage details for edu.uci.ics.jung.graph.impl.BipartiteEdge

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 /*
11  * Created on Aug 15, 2003
12  *
13  */
14 package edu.uci.ics.jung.graph.impl;
15  
16 import edu.uci.ics.jung.exceptions.FatalException;
17 import edu.uci.ics.jung.graph.ArchetypeEdge;
18 import edu.uci.ics.jung.graph.ArchetypeGraph;
19 import edu.uci.ics.jung.utils.Pair;
20  
21 /**
22  * A simple extension of the UndirectedSparseEdge, except
23  * with careful bounds checking. The constructor throws
24  * a FatalException if its vertices are not in two classes
25  * of a BipartiteGraph. (In fact, the Vertices must come in
26  * the order CLASSA, CLASSB).
27  *
28  * @author danyelf
29  */
30 public class BipartiteEdge extends UndirectedSparseEdge {
31  
32     /**
33      * The BipartiteEdge constructor.
34      * @param a a Vertex from a BipartiteGraph in CLASSA
35      * @param b a Vertex from the same BipartiteGraph in CLASSB
36      */
37     public BipartiteEdge(BipartiteVertex a, BipartiteVertex b) {
3864        super(a, b);
3964        BipartiteGraph g = (BipartiteGraph) a.getGraph();
40  
4164        boolean aInA = g.getAllVertices(BipartiteGraph.CLASSA).contains(a);
4264        boolean bInB = g.getAllVertices(BipartiteGraph.CLASSB).contains(b);
43  
4464        if (!(aInA && bInB))
452            throw new FatalException("Tried to create edge that isn't bipartite!");
4662    }
47  
48     public ArchetypeEdge copy(ArchetypeGraph newGraph) {
4913        if (newGraph == this.getGraph())
500            throw new IllegalArgumentException(
51                 "Source and destination " + "graphs must be different");
52  
5313        Pair ends = getEndpoints();
54  
5513        BipartiteVertex eFrom =
56             (BipartiteVertex) ends.getFirst();
5713        BipartiteVertex eTo =
58             (BipartiteVertex) ends.getSecond();
59  
6013        BipartiteVertex from = (BipartiteVertex) eFrom.getEqualVertex(newGraph);
6113        BipartiteVertex to = (BipartiteVertex) eTo.getEqualVertex(newGraph);
62  
6313        if (from == null || to == null)
640            throw new IllegalArgumentException(
65                 "Cannot create edge: source edge's incident "
66                     + "vertices have no equivalents in target graph");
67  
6813        if (from.getGraph() != newGraph) {
690            throw new FatalException("Unexpected error: 'from' vertex is not in target graph");
70         }
7113        if (to.getGraph() != newGraph) {
720            throw new FatalException("Unexpected error: 'to' vertex is not in target graph");
73         }
7413        if (eFrom.getGraph() == from.getGraph()) {
750            throw new FatalException("Unexpected error: 'from' and 'to' vertices are not in same graph");
76         }
77  
78         BipartiteEdge e;
79         try {
8013            e = (BipartiteEdge) this.clone();
810        } catch (CloneNotSupportedException cnse) {
820            throw new FatalException("Can't copy edge", cnse);
8313        }
84         
8513        e.m_Graph = null;
8613        e.mFrom = from;
8713        e.mTo = to;
8813        ((BipartiteGraph) newGraph).addBipartiteEdge(e);
8913        e.importUserData(this);
9013        return e;
91  
92     }
93  
94 }

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.