Source code: luna/LunaRootGraph.java
1 package luna;
2
3 import coltginy.*;
4 import giny.model.*;
5 import cern.colt.map.*;
6
7 public class LunaRootGraph extends ColtRootGraph {
8
9 /**
10 * The Nodes that are created, though they need not be are stored so has to allow
11 * modification of node values and to ensure node persistance, this may be later changed.
12 */
13 protected OpenIntObjectHashMap nodeIndexObjectMap;
14
15 /**
16 * The Edges that are created, though they need not be are stored so has to allow
17 * modification of edge values and to ensure edge persistance, this may be later changed.
18 */
19 protected OpenIntObjectHashMap edgeIndexObjectMap;
20
21
22 //-------------------------------------------------------------------------//
23 // Construction & initialization methods
24 //-------------------------------------------------------------------------//
25
26 /**
27 * Default constructor delegates to the int, int constructor with the default
28 * values ColtginyConstants.DEFAULT_NODE_CAPACITY and
29 * ColtginyConstants.DEFAULT_EDGE_CAPACITY.
30 */
31 public LunaRootGraph () {
32 this(
33 ColtginyConstants.DEFAULT_NODE_CAPACITY,
34 ColtginyConstants.DEFAULT_EDGE_CAPACITY
35 );
36 } // <init>()
37
38 /**
39 * int, int constructor calls {@link #initializeColtRootGraph( int, int )}.
40 */
41 public LunaRootGraph ( int node_capacity, int edge_capacity ) {
42 // This is the only Luna Specific Code
43 nodeIndexObjectMap = new OpenIntObjectHashMap( PrimeFinder.nextPrime( node_capacity ) );
44 edgeIndexObjectMap = new OpenIntObjectHashMap( PrimeFinder.nextPrime( edge_capacity ) );
45 // Back to ColtRootGraph
46 initializeColtRootGraph( node_capacity, edge_capacity );
47 } // <init>()
48
49
50 /**
51 * This implementation of the giny model will defer creation of Node objects
52 * as long as possible. This method creates the object corresponding to the
53 * given <i>valid</i> node index. Subsequent changes to this object must be
54 * reflected when this RootGraph is queried about the node or its index, and
55 * subsequent changes to the Node made via this RootGraph, including changes
56 * made using only its index, will be reflected when querying the returned
57 * Node. To accomplish this it is recommended that the returned Node be a
58 * SimpleColtNode or a subclass thereof, but this is not required.
59 * @param node_index a valid Node index in this RootGraph.
60 * @return a new Node that dynamically reflects all node data associated with
61 * the given index.
62 * @see SimpleColtNode
63 */
64 protected Node createNode ( int node_index ) {
65
66 if ( nodeIndexObjectMap.containsKey( node_index ) ) {
67 return ( Node )nodeIndexObjectMap.get( node_index );
68 } else {
69 LunaNode node = new LunaNode( node_index, this );
70 nodeIndexObjectMap.put( node_index, node );
71 return node;
72 }
73 }
74
75 /**
76 * This implementation of the giny model will defer creation of Edge objects
77 * as long as possible. This method creates the object corresponding to the
78 * given <i>valid</i> edge index. Subsequent changes to this object must be
79 * reflected when this RootGraph is queried about the edge or its index, and
80 * subsequent changes to the Edge made via this RootGraph, including changes
81 * made using only its index, will be reflected when querying the returned
82 * Edge. To accomplish this it is recommended that the returned Edge be a
83 * SimpleColtEdge or a subclass thereof, but this is not required.
84 * @param edge_index a valid Edge index in this RootGraph.
85 * @return a new Edge that dynamically reflects all edge data associated with
86 * the given index.
87 * @see SimpleColtEdge
88 */
89 protected Edge createEdge ( int edge_index ) {
90
91 if ( edgeIndexObjectMap.containsKey( edge_index ) ) {
92 return ( Edge )edgeIndexObjectMap.get( edge_index );
93 } else {
94 LunaEdge edge = new LunaEdge( edge_index, this );
95 edgeIndexObjectMap.put( edge_index, edge );
96 return edge;
97 }
98 }
99
100 }