MATSIM
VehicleReaderV1.java
Go to the documentation of this file.
1 package org.matsim.vehicles;
2 
3 import org.apache.logging.log4j.LogManager;
4 import org.apache.logging.log4j.Logger;
5 import org.matsim.api.core.v01.Id;
8 import org.xml.sax.Attributes;
9 
10 import java.util.Stack;
11 
12 final class VehicleReaderV1 extends MatsimXmlParser{
13  private static final Logger log = LogManager.getLogger(VehicleReaderV1.class) ;
14 
15  private final Vehicles vehicles;
16  private final VehiclesFactory builder;
17  private VehicleType currentVehType = null;
18 
19  VehicleReaderV1( final Vehicles vehicles ){
20  super(ValidationType.XSD_ONLY);
21  log.info("Using " + this.getClass().getName());
22  this.vehicles = vehicles;
23  this.builder = this.vehicles.getFactory();
24  }
25 
26  @Override
27  public void endTag( final String name, final String content, final Stack<String> context ){
28  if( VehicleSchemaV1Names.DESCRIPTION.equalsIgnoreCase( name ) && (content.trim().length() > 0) ){
29  this.currentVehType.setDescription( content.trim() );
30  } else if( VehicleSchemaV1Names.FUELTYPE.equalsIgnoreCase( name ) ){
31  VehicleUtils.setFuelType(this.currentVehType.getEngineInformation(), EngineInformation.FuelType.valueOf(content.trim()));
32  } else if( VehicleSchemaV1Names.VEHICLETYPE.equalsIgnoreCase( name ) ){
33  this.vehicles.addVehicleType( this.currentVehType );
34  this.currentVehType = null;
35  }
36  }
37 
38  @Override
39  public void startTag( final String name, final Attributes atts, final Stack<String> context ){
40  if( VehicleSchemaV1Names.VEHICLETYPE.equalsIgnoreCase( name ) ){
41  this.currentVehType = this.builder.createVehicleType( Id.create( atts.getValue( VehicleSchemaV1Names.ID ), VehicleType.class ) );
42  // In the old format there is no network mode, and everything was basically a car.
43  // Vehicle type does not contain a default network mode anymore, therefore we need to set it here.
44  this.currentVehType.setNetworkMode( TransportMode.car );
45 
46  } else if( VehicleSchemaV1Names.LENGTH.equalsIgnoreCase( name ) ){
47  this.currentVehType.setLength( Double.parseDouble( atts.getValue( VehicleSchemaV1Names.METER ) ) );
48  } else if( VehicleSchemaV1Names.WIDTH.equalsIgnoreCase( name ) ){
49  this.currentVehType.setWidth( Double.parseDouble( atts.getValue( VehicleSchemaV1Names.METER ) ) );
50  } else if( VehicleSchemaV1Names.MAXIMUMVELOCITY.equalsIgnoreCase( name ) ){
51  double val = Double.parseDouble( atts.getValue( VehicleSchemaV1Names.METERPERSECOND ) );
52  if( val == 1.0 ){
53  log.warn(
54  "The vehicle type's maximum velocity is set to 1.0 meter per second, is this really intended? vehicletype = " + this.currentVehType.getId().toString() );
55  }
56  this.currentVehType.setMaximumVelocity( val );
57  } else if( VehicleSchemaV1Names.SEATS.equalsIgnoreCase( name ) ){
58  this.currentVehType.getCapacity().setSeats( Integer.valueOf( atts.getValue( VehicleSchemaV1Names.PERSONS ) ) );
59  } else if( VehicleSchemaV1Names.STANDINGROOM.equalsIgnoreCase( name ) ){
60  this.currentVehType.getCapacity().setStandingRoom( Integer.valueOf( atts.getValue( VehicleSchemaV1Names.PERSONS ) ) );
61  } else if( VehicleSchemaV1Names.VOLUME.equalsIgnoreCase( name ) ) {
62  if(atts.getValue(VehicleSchemaV1Names.CUBICMETERS).contentEquals("INF")){
63  this.currentVehType.getCapacity().setVolumeInCubicMeters(Double.POSITIVE_INFINITY);
64  } else {
65  this.currentVehType.getCapacity().setVolumeInCubicMeters(Double.parseDouble(atts.getValue(VehicleSchemaV1Names.CUBICMETERS)));
66  }
67  } else if( VehicleSchemaV1Names.GASCONSUMPTION.equalsIgnoreCase( name ) ){
68  VehicleUtils.setFuelConsumption(this.currentVehType, Double.parseDouble( atts.getValue( VehicleSchemaV1Names.LITERPERMETER )) );
69  } else if( VehicleSchemaV1Names.VEHICLE.equalsIgnoreCase( name ) ){
70  Id<VehicleType> typeId = Id.create( atts.getValue( VehicleSchemaV1Names.TYPE ), VehicleType.class );
71  VehicleType type = this.vehicles.getVehicleTypes().get( typeId );
72  if( type == null ){
73  log.error( "VehicleType " + typeId + " does not exist." );
74  }
75  String idString = atts.getValue( VehicleSchemaV1Names.ID );
76  Id<Vehicle> id = Id.create( idString, Vehicle.class );
77  Vehicle v = this.builder.createVehicle( id, type );
78  this.vehicles.addVehicle( v );
79  } else if( VehicleSchemaV1Names.ACCESSTIME.equalsIgnoreCase( name ) ){
80  VehicleUtils.setAccessTime(this.currentVehType, Double.parseDouble( atts.getValue( VehicleSchemaV1Names.SECONDSPERPERSON ) ));
81  } else if( VehicleSchemaV1Names.EGRESSTIME.equalsIgnoreCase( name ) ){
82  VehicleUtils.setEgressTime(this.currentVehType, Double.parseDouble( atts.getValue( VehicleSchemaV1Names.SECONDSPERPERSON ) ));
83  } else if( VehicleSchemaV1Names.DOOROPERATION.equalsIgnoreCase( name ) ){
84  VehicleUtils.setDoorOperationMode(this.currentVehType, VehicleType.DoorOperationMode.valueOf((atts.getValue(VehicleSchemaV1Names.MODE )) ) );
85  } else if( VehicleSchemaV1Names.PASSENGERCAREQUIVALENTS.equalsIgnoreCase( name ) ){
86  this.currentVehType.setPcuEquivalents( Double.parseDouble( atts.getValue( VehicleSchemaV1Names.PCE ) ) );
87  }
88  }
89 
90 }
abstract void startTag(String name, Attributes atts, Stack< String > context)