MATSIM
VehicleHouseholdMapping.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * VehicleHouseholdMapping
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2023 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 package org.matsim.households;
21 
22 import java.util.Map;
23 
24 import javax.annotation.Nullable;
25 
26 import org.matsim.api.core.v01.Id;
27 import org.matsim.api.core.v01.IdMap;
28 import org.matsim.vehicles.Vehicle;
29 
37 
38  private final Map<Id<Vehicle>, Household> vhMap = new IdMap<>(Vehicle.class);
39 
41  this.reinitialize(hhs);
42  }
43 
44  public void reinitialize(Households hhs) {
45  this.vhMap.clear();
46  for (Household h : hhs.getHouseholds().values()) {
47  for (Id<Vehicle> vehicle : h.getVehicleIds()) {
48  this.vhMap.put(vehicle, h);
49  }
50  }
51  }
52 
53  public @Nullable Household getHousehold(Id<Vehicle> vehicleId) {
54  return this.vhMap.get(vehicleId);
55  }
56 
57 }
Map< Id< Household >, Household > getHouseholds()
final Map< Id< Vehicle >, Household > vhMap