| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | * Created on Apr 26, 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.graph.impl; | |
| 13 | ||
| 14 | import java.lang.ref.WeakReference; | |
| 15 | import java.util.Map; | |
| 16 | ||
| 17 | import edu.uci.ics.jung.exceptions.FatalException; | |
| 18 | import edu.uci.ics.jung.graph.ArchetypeGraph; | |
| 19 | import edu.uci.ics.jung.graph.Element; | |
| 20 | import edu.uci.ics.jung.utils.GeneralUtils; | |
| 21 | import edu.uci.ics.jung.utils.UserDataDelegate; | |
| 22 | ||
| 23 | /** | |
| 24 | * | |
| 25 | * @author Joshua O'Madadhain | |
| 26 | */ | |
| 27 | 178839 | public abstract class AbstractElement extends UserDataDelegate |
| 28 | //extends UnifiedUserData // Delegate | |
| 29 | implements Element, Cloneable | |
| 30 | { | |
| 31 | /** | |
| 32 | * The graph of which this vertex is an element. | |
| 33 | */ | |
| 34 | protected WeakReference m_Graph; | |
| 35 | ||
| 36 | /** | |
| 37 | * Used to define vertex equivalence. | |
| 38 | */ | |
| 39 | 178839 | protected int id = -1; |
| 40 | ||
| 41 | /** | |
| 42 | * @see Element#getGraph() | |
| 43 | */ | |
| 44 | public ArchetypeGraph getGraph() | |
| 45 | { | |
| 46 | 1759257 | if( m_Graph == null ) |
| 47 | 420990 | return null; |
| 48 | ||
| 49 | 1338267 | ArchetypeGraph g = (ArchetypeGraph) m_Graph.get(); |
| 50 | 1338267 | return g; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Attaches this vertex to the specified graph <code>g</code>. | |
| 55 | */ | |
| 56 | protected void addGraph_internal(AbstractArchetypeGraph g) { | |
| 57 | 180435 | if (m_Graph == null ) |
| 58 | { | |
| 59 | // List l = getRepositoryData(); | |
| 60 | 180435 | this.m_Graph = new WeakReference(g) ; |
| 61 | // updateRepository(l); | |
| 62 | } else { | |
| 63 | 0 | throw new FatalException("Internal error: element " + this + |
| 64 | " is already part of graph " + this.getGraph()); | |
| 65 | } | |
| 66 | 180435 | } |
| 67 | ||
| 68 | // private List getRepositoryData() | |
| 69 | // { | |
| 70 | // List list = new LinkedList(); | |
| 71 | // for (Iterator iter = this.getUserDatumKeyIterator(); iter.hasNext(); ) | |
| 72 | // { | |
| 73 | // Object key = iter.next(); | |
| 74 | // Object value = this.getUserDatum(key); | |
| 75 | // CopyAction copyact = this.getUserDatumCopyAction(key); | |
| 76 | // list.add(new Object[]{key, value, copyact}); | |
| 77 | // this.removeUserDatum(key); | |
| 78 | // } | |
| 79 | // return list; | |
| 80 | // } | |
| 81 | // | |
| 82 | // private void updateRepository(List l) | |
| 83 | // { | |
| 84 | // // re-insert all of the user data in l into repository; | |
| 85 | // // for some types of repository this is necessary to update | |
| 86 | // // element's "in-graph" status | |
| 87 | // for (Iterator iter = l.iterator(); iter.hasNext(); ) | |
| 88 | // { | |
| 89 | // Object[] kvc = (Object[])iter.next(); | |
| 90 | // this.addUserDatum(kvc[0], kvc[1], (CopyAction)kvc[2]); | |
| 91 | // } | |
| 92 | // } | |
| 93 | ||
| 94 | /** | |
| 95 | * Cleans up internal data structures after this | |
| 96 | * element is removed from a graph. | |
| 97 | */ | |
| 98 | protected void removeGraph_internal() | |
| 99 | { | |
| 100 | // List l = getRepositoryData(); | |
| 101 | 109781 | this.m_Graph = null; |
| 102 | // updateRepository(l); | |
| 103 | 109781 | } |
| 104 | ||
| 105 | /** | |
| 106 | * Returns the ID of this element. This method is not intended | |
| 107 | * for general user access. | |
| 108 | */ | |
| 109 | int getID() | |
| 110 | { | |
| 111 | 507642 | return this.id; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * @see java.lang.Object#hashCode() | |
| 116 | */ | |
| 117 | public int hashCode() | |
| 118 | { | |
| 119 | 8846345 | return GeneralUtils.hash(this.id); |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Adds (<code>getID()</code>,<code>this</code>) to the specified | |
| 124 | * Map. Checks to determine whether the map already contains an element with | |
| 125 | * such an index, and throws an IllegalArgumentException if it does. This is | |
| 126 | * used to test for the presence of an equivalent vertex/edge in a graph; | |
| 127 | * it's not subsumed by the "NotInGraph*Predicate" check contains() check | |
| 128 | * done in the validation step, because contains depends on equals() -> | |
| 129 | * getEquivalent{Edge,Vertex}() -> getGraph()...which returns null because | |
| 130 | * addGraph_internal has not yet been called. So this really is the only way | |
| 131 | * we can tell, at this point in the appropriate add() method, whether | |
| 132 | * there's an equivalent vertex/edge. | |
| 133 | */ | |
| 134 | void checkIDs(Map ids) | |
| 135 | { | |
| 136 | 180438 | Integer newIndex = new Integer(getID()); |
| 137 | 180438 | if (ids.containsKey(newIndex)) |
| 138 | 1 | throw new IllegalArgumentException( |
| 139 | "An equivalent element already exists in this graph"); | |
| 140 | 180437 | ids.put(newIndex, this); |
| 141 | 180437 | } |
| 142 | ||
| 143 | /** | |
| 144 | * Initializes all the data structures for this element. | |
| 145 | * (This is used on cloned elements, since | |
| 146 | * <code>clone()</code> copies some information that should | |
| 147 | * not be in the new element.) | |
| 148 | */ | |
| 149 | protected void initialize() | |
| 150 | { | |
| 151 | 64999 | m_Graph = null; |
| 152 | 64999 | } |
| 153 | ||
| 154 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |