20 package org.matsim.vehicles;
22 import static java.util.Comparator.comparing;
23 import static java.util.stream.Collectors.toList;
25 import java.io.UncheckedIOException;
26 import java.util.ArrayList;
27 import java.util.List;
30 import org.apache.logging.log4j.LogManager;
31 import org.apache.logging.log4j.Logger;
45 private List<Tuple<String, String>>
atts =
new ArrayList<Tuple<String, String>>();
54 log.warn(
"VehiclesV1 is deprecated; Please use MatsimVehicleWriter to always write with the currently supported version");
59 public void writeFile(String filename)
throws UncheckedIOException {
72 this.
writeStartTag(VehicleSchemaV1Names.VEHICLEDEFINITIONS, atts);
75 this.
writeEndTag(VehicleSchemaV1Names.VEHICLEDEFINITIONS);
79 List<Vehicle> sortedVehicles = veh.values().stream().sorted(comparing(
Vehicle::getId)).collect(toList());
80 for (
Vehicle v : sortedVehicles) {
82 atts.add(this.
createTuple(VehicleSchemaV1Names.ID, v.getId().toString()));
83 atts.add(this.
createTuple(VehicleSchemaV1Names.TYPE, v.getType().getId().toString()));
89 List<VehicleType> sortedVehicleTypes = vts.values()
95 atts.add(this.
createTuple(VehicleSchemaV1Names.ID, vt.getId().toString()));
97 if (vt.getDescription() != null) {
100 this.
writeEndTag(VehicleSchemaV1Names.DESCRIPTION);
102 if (vt.getCapacity() != null) {
105 if (!Double.isNaN(vt.getLength())){
107 atts.add(this.
createTuple(VehicleSchemaV1Names.METER, Double.toString(vt.getLength())));
110 if (!Double.isNaN(vt.getWidth())){
112 atts.add(this.
createTuple(VehicleSchemaV1Names.METER, Double.toString(vt.getWidth())));
115 if (!Double.isNaN(vt.getMaximumVelocity()) && !Double.isInfinite(vt.getMaximumVelocity())){
117 atts.add(this.
createTuple(VehicleSchemaV1Names.METERPERSECOND, Double.toString(vt.getMaximumVelocity())));
118 this.
writeStartTag(VehicleSchemaV1Names.MAXIMUMVELOCITY, atts,
true);
120 if (vt.getEngineInformation() != null && !vt.getEngineInformation().getAttributes().isEmpty()) {
121 log.info(
"try to write EngineInformation for vehType" + vt.getId());
126 this.
writeStartTag(VehicleSchemaV1Names.ACCESSTIME, atts,
true);
129 this.
writeStartTag(VehicleSchemaV1Names.EGRESSTIME, atts,
true);
132 this.
writeStartTag(VehicleSchemaV1Names.DOOROPERATION, atts,
true);
134 atts.add(this.
createTuple(VehicleSchemaV1Names.PCE, vt.getPcuEquivalents()));
135 this.
writeStartTag(VehicleSchemaV1Names.PASSENGERCAREQUIVALENTS, atts,
true);
136 this.
writeEndTag(VehicleSchemaV1Names.VEHICLETYPE);
141 this.
writeStartTag(VehicleSchemaV1Names.ENGINEINFORMATION, null);
152 this.
writeStartTag(VehicleSchemaV1Names.GASCONSUMPTION, atts,
true);
154 this.
writeEndTag(VehicleSchemaV1Names.ENGINEINFORMATION);
159 if (cap.getSeats() != null) {
161 atts.add(this.
createTuple(VehicleSchemaV1Names.PERSONS, cap.getSeats()));
164 if (cap.getStandingRoom() != null) {
166 atts.add(this.
createTuple(VehicleSchemaV1Names.PERSONS, cap.getStandingRoom()));
167 this.
writeStartTag(VehicleSchemaV1Names.STANDINGROOM, atts,
true);
169 if( cap.getVolumeInCubicMeters() != null && !Double.isInfinite(cap.getVolumeInCubicMeters())) {
176 this.
writeStartTag(VehicleSchemaV1Names.FREIGHTCAPACITY, null);
178 atts.add(this.
createTuple(VehicleSchemaV1Names.CUBICMETERS, Double.toString(fc)));
180 this.
writeEndTag(VehicleSchemaV1Names.FREIGHTCAPACITY);
void writeCapacity(VehicleCapacity cap)
final void writeXmlHead()
static final String XMLNS
static final String DEFAULTSCHEMANAMESPACELOCATION
Map< Id< VehicleType >, VehicleType > getVehicleTypes()
static Double getFuelConsumption(VehicleType vehicleType)
void writeFile(String filename)
static double getAccessTime(VehicleType vehicleType)
static final String MATSIM_NAMESPACE
static double getEgressTime(VehicleType vehicleType)
final void writeContent(String content, boolean allowWhitespaces)
List< Tuple< String, String > > atts
void writeVehicleTypes(Map< Id< VehicleType >, VehicleType > vts)
Map< Id< Vehicle >, Vehicle > vehicles
final void openFile(final String filename)
final void writeStartTag(String tagname, List< Tuple< String, String >> attributes)
static String aboutToWrite(String what, String filename)
static Tuple< String, String > createTuple(String one, String two)
final Id< VehicleType > getId()
VehicleWriterV1(Vehicles vehicles)
static final String DEFAULT_DTD_LOCATION
Map< Id< Vehicle >, Vehicle > getVehicles()
static VehicleType.DoorOperationMode getDoorOperationMode(VehicleType vehicleType)
final void writeEndTag(String tagname)
Map< Id< VehicleType >, VehicleType > vehicleTypes
void writeVehicles(Map< Id< Vehicle >, Vehicle > veh)
void writeFreightCapacity(double fc)
void writeEngineInformation(EngineInformation ei)