MATSIM
MapBasedDataContainerProvider.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MapBasedDataContainerProvider.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2013 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.trafficmonitoring;
22 
23 import org.matsim.api.core.v01.Id;
25 
26 import java.util.Map;
27 
28 class MapBasedDataContainerProvider implements DataContainerProvider {
29 
30  private final Map<Id<Link>, TravelTimeData> linkData;
31  private final TravelTimeDataFactory ttDataFactory;
32 
33  public MapBasedDataContainerProvider(Map<Id<Link>, TravelTimeData> linkData, TravelTimeDataFactory ttDataFactory) {
34  this.linkData = linkData;
35  this.ttDataFactory = ttDataFactory;
36  }
37 
38  @Override
39  public TravelTimeData getTravelTimeData(final Id<Link> linkId, final boolean createIfMissing) {
40  TravelTimeData data = this.linkData.get(linkId);
41  if ((null == data) && createIfMissing) {
42  data = this.ttDataFactory.createTravelTimeData(linkId) ;
43  this.linkData.put(linkId, data);
44  }
45  return data;
46  }
47 
48  @Override
49  public TravelTimeData getTravelTimeData(Link link, boolean createIfMissing) {
50  return this.getTravelTimeData(link.getId(), createIfMissing);
51  }
52 
53 }