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

LineHitsSource
1 /*
2  * Created on Sep 24, 2005
3  *
4  * Copyright (c) 2005, 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.utils;
13  
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.Map;
17 import java.util.Set;
18  
19 import edu.uci.ics.jung.graph.Edge;
20 import edu.uci.ics.jung.graph.Vertex;
21  
22 /**
23  * A class which creates and maintains indices for parallel edges.
24  * Parallel edges are defined here to be those edges of type <code>Edge</code>
25  * that are returned by <code>v.findEdgeSet(w)</code> for some
26  * <code>v</code> and <code>w</code>.
27  *
28  * <p>At this time, users are responsible for resetting the indices if changes to the
29  * graph make it appropriate.</p>
30  *
31  * @author Joshua O'Madadhain
32  * @author Tom Nelson
33  *
34  */
35 public class DefaultParallelEdgeIndexFunction implements ParallelEdgeIndexFunction
36 {
370    protected Map edge_index = new HashMap();
38     
390    private DefaultParallelEdgeIndexFunction() { }
40     
41     public static DefaultParallelEdgeIndexFunction getInstance() {
420        return new DefaultParallelEdgeIndexFunction();
43     }
44     /**
45      * Returns the index for the specified edge.
46      * Calculates the indices for <code>e</code> and for all edges parallel
47      * to <code>e</code>.
48      */
49     public int getIndex(Edge e)
50     {
510        Integer index = (Integer)edge_index.get(e);
520        if(index == null)
530            index = getIndex_internal(e);
540        return index.intValue();
55     }
56  
57     protected Integer getIndex_internal(Edge e)
58     {
590        Pair endpoints = e.getEndpoints();
600        Vertex u = (Vertex)(endpoints.getFirst());
610        Vertex v = (Vertex)(endpoints.getSecond());
620        Set commonEdgeSet = u.findEdgeSet(v);
630        int count = 0;
640        for(Iterator iterator=commonEdgeSet.iterator(); iterator.hasNext(); ) {
650            Edge other = (Edge)iterator.next();
660            if (e.equals(other) == false)
67             {
680                edge_index.put(other, new Integer(count));
690                count++;
70             }
71         }
720        Integer index = new Integer(count);
730        edge_index.put(e, index);
74         
750        return index;
76     }
77     
78     /**
79      * Resets the indices for this edge and its parallel edges.
80      * Should be invoked when an edge parallel to <code>e</code>
81      * has been added or removed.
82      * @param e
83      */
84     public void reset(Edge e)
85     {
860        getIndex_internal(e);
870    }
88     
89     /**
90      * Clears all edge indices for all edges in all graphs.
91      * Does not recalculate the indices.
92      */
93     public void reset()
94     {
950        edge_index.clear();
960    }
97 }

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.