MATSIM
ArrayFastRouterDelegate.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * ArrayFastRouterDelegate.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2012 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.router;
22 
28 
29 /*package*/ class ArrayFastRouterDelegate extends AbstractFastRouterDelegate {
30 
31  private final ArrayRoutingNetwork network;
32  private final NodeData[] nodeData;
33  private boolean isInitialized = false;
34 
35  /*package*/ ArrayFastRouterDelegate(final Dijkstra dijkstra, final NodeDataFactory nodeDataFactory,
36  final ArrayRoutingNetwork network) {
37  super(dijkstra, nodeDataFactory);
38  this.network = network;
39  this.nodeData = new NodeData[network.getNodes().size()];
40  }
41 
42  @Override
43  public final void initialize() {
44  // lazy initialization
45  if (!isInitialized) {
46  for (Node node : this.network.getNodes().values()) {
47  int index = ((ArrayRoutingNetworkNode) node).getArrayIndex();
48  this.nodeData[index] = nodeDataFactory.createNodeData();
49  }
50 
51  this.isInitialized = true;
52  }
53  }
54 
55  /*
56  * The NodeData is taken from the array.
57  */
58  public NodeData getData(final Node n) {
59  ArrayRoutingNetworkNode routingNetworkNode = (ArrayRoutingNetworkNode) n;
60  return this.nodeData[routingNetworkNode.getArrayIndex()];
61  }
62 }