diff --git a/contribs/application/src/main/avro/network.avsc b/contribs/application/src/main/avro/network.avsc new file mode 100644 index 00000000000..63464a3ad56 --- /dev/null +++ b/contribs/application/src/main/avro/network.avsc @@ -0,0 +1,96 @@ +{ + "namespace": "org.matsim.application.avro", + "type": "record", + "name": "AvroNetwork", + "fields": [ + { + "name": "crs", + "type": "string", + "doc": "Coordinate reference system" + }, + { + "type": { + "type": "array", + "items": "string" + }, + "name": "nodeId" + }, + { + "type": { + "type": "array", + "items": "float" + }, + "name": "nodeCoordinates" + }, + { + "name": "nodeAttributes", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "modes", + "type": { + "type": "array", + "items": "string" + } + }, + { + "type": { + "type": "array", + "items": "string" + }, + "name": "linkId" + }, + { + "type": { + "type": "array", + "items": "float" + }, + "name": "length" + }, + { + "type": { + "type": "array", + "items": "float" + }, + "name": "freespeed" + }, + { + "type": { + "type": "array", + "items": "float" + }, + "name": "capacity" + }, + { + "type": { + "type": "array", + "items": "float" + }, + "name": "permlanes" + }, + { + "type": { + "type": "array", + "items": "int" + }, + "name": "allowedModes" + }, + { + "type": { + "type": "array", + "items": "string" + }, + "name": "from" + }, + { + "type": { + "type": "array", + "items": "string" + }, + "name": "to" + } + ] +} diff --git a/contribs/application/src/main/java/org/matsim/application/avro/AvroNetwork.java b/contribs/application/src/main/java/org/matsim/application/avro/AvroNetwork.java new file mode 100644 index 00000000000..4069a828f3a --- /dev/null +++ b/contribs/application/src/main/java/org/matsim/application/avro/AvroNetwork.java @@ -0,0 +1,1730 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package org.matsim.application.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; + +@org.apache.avro.specific.AvroGenerated +public class AvroNetwork extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = -1583840499910541618L; + + + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"AvroNetwork\",\"namespace\":\"org.matsim.application.avro\",\"fields\":[{\"name\":\"crs\",\"type\":\"string\",\"doc\":\"Coordinate reference system\"},{\"name\":\"nodeId\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"nodeCoordinates\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"nodeAttributes\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"modes\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"linkId\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"length\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"freespeed\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"capacity\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"permlanes\",\"type\":{\"type\":\"array\",\"items\":\"float\"}},{\"name\":\"allowedModes\",\"type\":{\"type\":\"array\",\"items\":\"int\"}},{\"name\":\"from\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"to\",\"type\":{\"type\":\"array\",\"items\":\"string\"}}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + + private static final SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder<>(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder<>(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this AvroNetwork to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a AvroNetwork from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a AvroNetwork instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class + */ + public static AvroNetwork fromByteBuffer( + java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + /** Coordinate reference system */ + private java.lang.CharSequence crs; + private java.util.List nodeId; + private java.util.List nodeCoordinates; + private java.util.List nodeAttributes; + private java.util.List modes; + private java.util.List linkId; + private java.util.List length; + private java.util.List freespeed; + private java.util.List capacity; + private java.util.List permlanes; + private java.util.List allowedModes; + private java.util.List from; + private java.util.List to; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public AvroNetwork() {} + + /** + * All-args constructor. + * @param crs Coordinate reference system + * @param nodeId The new value for nodeId + * @param nodeCoordinates The new value for nodeCoordinates + * @param nodeAttributes The new value for nodeAttributes + * @param modes The new value for modes + * @param linkId The new value for linkId + * @param length The new value for length + * @param freespeed The new value for freespeed + * @param capacity The new value for capacity + * @param permlanes The new value for permlanes + * @param allowedModes The new value for allowedModes + * @param from The new value for from + * @param to The new value for to + */ + public AvroNetwork(java.lang.CharSequence crs, java.util.List nodeId, java.util.List nodeCoordinates, java.util.List nodeAttributes, java.util.List modes, java.util.List linkId, java.util.List length, java.util.List freespeed, java.util.List capacity, java.util.List permlanes, java.util.List allowedModes, java.util.List from, java.util.List to) { + this.crs = crs; + this.nodeId = nodeId; + this.nodeCoordinates = nodeCoordinates; + this.nodeAttributes = nodeAttributes; + this.modes = modes; + this.linkId = linkId; + this.length = length; + this.freespeed = freespeed; + this.capacity = capacity; + this.permlanes = permlanes; + this.allowedModes = allowedModes; + this.from = from; + this.to = to; + } + + @Override + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } + + @Override + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + + // Used by DatumWriter. Applications should not call. + @Override + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return crs; + case 1: return nodeId; + case 2: return nodeCoordinates; + case 3: return nodeAttributes; + case 4: return modes; + case 5: return linkId; + case 6: return length; + case 7: return freespeed; + case 8: return capacity; + case 9: return permlanes; + case 10: return allowedModes; + case 11: return from; + case 12: return to; + default: throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + // Used by DatumReader. Applications should not call. + @Override + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: crs = (java.lang.CharSequence)value$; break; + case 1: nodeId = (java.util.List)value$; break; + case 2: nodeCoordinates = (java.util.List)value$; break; + case 3: nodeAttributes = (java.util.List)value$; break; + case 4: modes = (java.util.List)value$; break; + case 5: linkId = (java.util.List)value$; break; + case 6: length = (java.util.List)value$; break; + case 7: freespeed = (java.util.List)value$; break; + case 8: capacity = (java.util.List)value$; break; + case 9: permlanes = (java.util.List)value$; break; + case 10: allowedModes = (java.util.List)value$; break; + case 11: from = (java.util.List)value$; break; + case 12: to = (java.util.List)value$; break; + default: throw new IndexOutOfBoundsException("Invalid index: " + field$); + } + } + + /** + * Gets the value of the 'crs' field. + * @return Coordinate reference system + */ + public java.lang.CharSequence getCrs() { + return crs; + } + + + /** + * Sets the value of the 'crs' field. + * Coordinate reference system + * @param value the value to set. + */ + public void setCrs(java.lang.CharSequence value) { + this.crs = value; + } + + /** + * Gets the value of the 'nodeId' field. + * @return The value of the 'nodeId' field. + */ + public java.util.List getNodeId() { + return nodeId; + } + + + /** + * Sets the value of the 'nodeId' field. + * @param value the value to set. + */ + public void setNodeId(java.util.List value) { + this.nodeId = value; + } + + /** + * Gets the value of the 'nodeCoordinates' field. + * @return The value of the 'nodeCoordinates' field. + */ + public java.util.List getNodeCoordinates() { + return nodeCoordinates; + } + + + /** + * Sets the value of the 'nodeCoordinates' field. + * @param value the value to set. + */ + public void setNodeCoordinates(java.util.List value) { + this.nodeCoordinates = value; + } + + /** + * Gets the value of the 'nodeAttributes' field. + * @return The value of the 'nodeAttributes' field. + */ + public java.util.List getNodeAttributes() { + return nodeAttributes; + } + + + /** + * Sets the value of the 'nodeAttributes' field. + * @param value the value to set. + */ + public void setNodeAttributes(java.util.List value) { + this.nodeAttributes = value; + } + + /** + * Gets the value of the 'modes' field. + * @return The value of the 'modes' field. + */ + public java.util.List getModes() { + return modes; + } + + + /** + * Sets the value of the 'modes' field. + * @param value the value to set. + */ + public void setModes(java.util.List value) { + this.modes = value; + } + + /** + * Gets the value of the 'linkId' field. + * @return The value of the 'linkId' field. + */ + public java.util.List getLinkId() { + return linkId; + } + + + /** + * Sets the value of the 'linkId' field. + * @param value the value to set. + */ + public void setLinkId(java.util.List value) { + this.linkId = value; + } + + /** + * Gets the value of the 'length' field. + * @return The value of the 'length' field. + */ + public java.util.List getLength() { + return length; + } + + + /** + * Sets the value of the 'length' field. + * @param value the value to set. + */ + public void setLength(java.util.List value) { + this.length = value; + } + + /** + * Gets the value of the 'freespeed' field. + * @return The value of the 'freespeed' field. + */ + public java.util.List getFreespeed() { + return freespeed; + } + + + /** + * Sets the value of the 'freespeed' field. + * @param value the value to set. + */ + public void setFreespeed(java.util.List value) { + this.freespeed = value; + } + + /** + * Gets the value of the 'capacity' field. + * @return The value of the 'capacity' field. + */ + public java.util.List getCapacity() { + return capacity; + } + + + /** + * Sets the value of the 'capacity' field. + * @param value the value to set. + */ + public void setCapacity(java.util.List value) { + this.capacity = value; + } + + /** + * Gets the value of the 'permlanes' field. + * @return The value of the 'permlanes' field. + */ + public java.util.List getPermlanes() { + return permlanes; + } + + + /** + * Sets the value of the 'permlanes' field. + * @param value the value to set. + */ + public void setPermlanes(java.util.List value) { + this.permlanes = value; + } + + /** + * Gets the value of the 'allowedModes' field. + * @return The value of the 'allowedModes' field. + */ + public java.util.List getAllowedModes() { + return allowedModes; + } + + + /** + * Sets the value of the 'allowedModes' field. + * @param value the value to set. + */ + public void setAllowedModes(java.util.List value) { + this.allowedModes = value; + } + + /** + * Gets the value of the 'from' field. + * @return The value of the 'from' field. + */ + public java.util.List getFrom() { + return from; + } + + + /** + * Sets the value of the 'from' field. + * @param value the value to set. + */ + public void setFrom(java.util.List value) { + this.from = value; + } + + /** + * Gets the value of the 'to' field. + * @return The value of the 'to' field. + */ + public java.util.List getTo() { + return to; + } + + + /** + * Sets the value of the 'to' field. + * @param value the value to set. + */ + public void setTo(java.util.List value) { + this.to = value; + } + + /** + * Creates a new AvroNetwork RecordBuilder. + * @return A new AvroNetwork RecordBuilder + */ + public static org.matsim.application.avro.AvroNetwork.Builder newBuilder() { + return new org.matsim.application.avro.AvroNetwork.Builder(); + } + + /** + * Creates a new AvroNetwork RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new AvroNetwork RecordBuilder + */ + public static org.matsim.application.avro.AvroNetwork.Builder newBuilder(org.matsim.application.avro.AvroNetwork.Builder other) { + if (other == null) { + return new org.matsim.application.avro.AvroNetwork.Builder(); + } else { + return new org.matsim.application.avro.AvroNetwork.Builder(other); + } + } + + /** + * Creates a new AvroNetwork RecordBuilder by copying an existing AvroNetwork instance. + * @param other The existing instance to copy. + * @return A new AvroNetwork RecordBuilder + */ + public static org.matsim.application.avro.AvroNetwork.Builder newBuilder(org.matsim.application.avro.AvroNetwork other) { + if (other == null) { + return new org.matsim.application.avro.AvroNetwork.Builder(); + } else { + return new org.matsim.application.avro.AvroNetwork.Builder(other); + } + } + + /** + * RecordBuilder for AvroNetwork instances. + */ + @org.apache.avro.specific.AvroGenerated + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + /** Coordinate reference system */ + private java.lang.CharSequence crs; + private java.util.List nodeId; + private java.util.List nodeCoordinates; + private java.util.List nodeAttributes; + private java.util.List modes; + private java.util.List linkId; + private java.util.List length; + private java.util.List freespeed; + private java.util.List capacity; + private java.util.List permlanes; + private java.util.List allowedModes; + private java.util.List from; + private java.util.List to; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$, MODEL$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(org.matsim.application.avro.AvroNetwork.Builder other) { + super(other); + if (isValidValue(fields()[0], other.crs)) { + this.crs = data().deepCopy(fields()[0].schema(), other.crs); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.nodeId)) { + this.nodeId = data().deepCopy(fields()[1].schema(), other.nodeId); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.nodeCoordinates)) { + this.nodeCoordinates = data().deepCopy(fields()[2].schema(), other.nodeCoordinates); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + if (isValidValue(fields()[3], other.nodeAttributes)) { + this.nodeAttributes = data().deepCopy(fields()[3].schema(), other.nodeAttributes); + fieldSetFlags()[3] = other.fieldSetFlags()[3]; + } + if (isValidValue(fields()[4], other.modes)) { + this.modes = data().deepCopy(fields()[4].schema(), other.modes); + fieldSetFlags()[4] = other.fieldSetFlags()[4]; + } + if (isValidValue(fields()[5], other.linkId)) { + this.linkId = data().deepCopy(fields()[5].schema(), other.linkId); + fieldSetFlags()[5] = other.fieldSetFlags()[5]; + } + if (isValidValue(fields()[6], other.length)) { + this.length = data().deepCopy(fields()[6].schema(), other.length); + fieldSetFlags()[6] = other.fieldSetFlags()[6]; + } + if (isValidValue(fields()[7], other.freespeed)) { + this.freespeed = data().deepCopy(fields()[7].schema(), other.freespeed); + fieldSetFlags()[7] = other.fieldSetFlags()[7]; + } + if (isValidValue(fields()[8], other.capacity)) { + this.capacity = data().deepCopy(fields()[8].schema(), other.capacity); + fieldSetFlags()[8] = other.fieldSetFlags()[8]; + } + if (isValidValue(fields()[9], other.permlanes)) { + this.permlanes = data().deepCopy(fields()[9].schema(), other.permlanes); + fieldSetFlags()[9] = other.fieldSetFlags()[9]; + } + if (isValidValue(fields()[10], other.allowedModes)) { + this.allowedModes = data().deepCopy(fields()[10].schema(), other.allowedModes); + fieldSetFlags()[10] = other.fieldSetFlags()[10]; + } + if (isValidValue(fields()[11], other.from)) { + this.from = data().deepCopy(fields()[11].schema(), other.from); + fieldSetFlags()[11] = other.fieldSetFlags()[11]; + } + if (isValidValue(fields()[12], other.to)) { + this.to = data().deepCopy(fields()[12].schema(), other.to); + fieldSetFlags()[12] = other.fieldSetFlags()[12]; + } + } + + /** + * Creates a Builder by copying an existing AvroNetwork instance + * @param other The existing instance to copy. + */ + private Builder(org.matsim.application.avro.AvroNetwork other) { + super(SCHEMA$, MODEL$); + if (isValidValue(fields()[0], other.crs)) { + this.crs = data().deepCopy(fields()[0].schema(), other.crs); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.nodeId)) { + this.nodeId = data().deepCopy(fields()[1].schema(), other.nodeId); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.nodeCoordinates)) { + this.nodeCoordinates = data().deepCopy(fields()[2].schema(), other.nodeCoordinates); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.nodeAttributes)) { + this.nodeAttributes = data().deepCopy(fields()[3].schema(), other.nodeAttributes); + fieldSetFlags()[3] = true; + } + if (isValidValue(fields()[4], other.modes)) { + this.modes = data().deepCopy(fields()[4].schema(), other.modes); + fieldSetFlags()[4] = true; + } + if (isValidValue(fields()[5], other.linkId)) { + this.linkId = data().deepCopy(fields()[5].schema(), other.linkId); + fieldSetFlags()[5] = true; + } + if (isValidValue(fields()[6], other.length)) { + this.length = data().deepCopy(fields()[6].schema(), other.length); + fieldSetFlags()[6] = true; + } + if (isValidValue(fields()[7], other.freespeed)) { + this.freespeed = data().deepCopy(fields()[7].schema(), other.freespeed); + fieldSetFlags()[7] = true; + } + if (isValidValue(fields()[8], other.capacity)) { + this.capacity = data().deepCopy(fields()[8].schema(), other.capacity); + fieldSetFlags()[8] = true; + } + if (isValidValue(fields()[9], other.permlanes)) { + this.permlanes = data().deepCopy(fields()[9].schema(), other.permlanes); + fieldSetFlags()[9] = true; + } + if (isValidValue(fields()[10], other.allowedModes)) { + this.allowedModes = data().deepCopy(fields()[10].schema(), other.allowedModes); + fieldSetFlags()[10] = true; + } + if (isValidValue(fields()[11], other.from)) { + this.from = data().deepCopy(fields()[11].schema(), other.from); + fieldSetFlags()[11] = true; + } + if (isValidValue(fields()[12], other.to)) { + this.to = data().deepCopy(fields()[12].schema(), other.to); + fieldSetFlags()[12] = true; + } + } + + /** + * Gets the value of the 'crs' field. + * Coordinate reference system + * @return The value. + */ + public java.lang.CharSequence getCrs() { + return crs; + } + + + /** + * Sets the value of the 'crs' field. + * Coordinate reference system + * @param value The value of 'crs'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setCrs(java.lang.CharSequence value) { + validate(fields()[0], value); + this.crs = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'crs' field has been set. + * Coordinate reference system + * @return True if the 'crs' field has been set, false otherwise. + */ + public boolean hasCrs() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'crs' field. + * Coordinate reference system + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearCrs() { + crs = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'nodeId' field. + * @return The value. + */ + public java.util.List getNodeId() { + return nodeId; + } + + + /** + * Sets the value of the 'nodeId' field. + * @param value The value of 'nodeId'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setNodeId(java.util.List value) { + validate(fields()[1], value); + this.nodeId = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'nodeId' field has been set. + * @return True if the 'nodeId' field has been set, false otherwise. + */ + public boolean hasNodeId() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'nodeId' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearNodeId() { + nodeId = null; + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'nodeCoordinates' field. + * @return The value. + */ + public java.util.List getNodeCoordinates() { + return nodeCoordinates; + } + + + /** + * Sets the value of the 'nodeCoordinates' field. + * @param value The value of 'nodeCoordinates'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setNodeCoordinates(java.util.List value) { + validate(fields()[2], value); + this.nodeCoordinates = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'nodeCoordinates' field has been set. + * @return True if the 'nodeCoordinates' field has been set, false otherwise. + */ + public boolean hasNodeCoordinates() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'nodeCoordinates' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearNodeCoordinates() { + nodeCoordinates = null; + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'nodeAttributes' field. + * @return The value. + */ + public java.util.List getNodeAttributes() { + return nodeAttributes; + } + + + /** + * Sets the value of the 'nodeAttributes' field. + * @param value The value of 'nodeAttributes'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setNodeAttributes(java.util.List value) { + validate(fields()[3], value); + this.nodeAttributes = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'nodeAttributes' field has been set. + * @return True if the 'nodeAttributes' field has been set, false otherwise. + */ + public boolean hasNodeAttributes() { + return fieldSetFlags()[3]; + } + + + /** + * Clears the value of the 'nodeAttributes' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearNodeAttributes() { + nodeAttributes = null; + fieldSetFlags()[3] = false; + return this; + } + + /** + * Gets the value of the 'modes' field. + * @return The value. + */ + public java.util.List getModes() { + return modes; + } + + + /** + * Sets the value of the 'modes' field. + * @param value The value of 'modes'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setModes(java.util.List value) { + validate(fields()[4], value); + this.modes = value; + fieldSetFlags()[4] = true; + return this; + } + + /** + * Checks whether the 'modes' field has been set. + * @return True if the 'modes' field has been set, false otherwise. + */ + public boolean hasModes() { + return fieldSetFlags()[4]; + } + + + /** + * Clears the value of the 'modes' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearModes() { + modes = null; + fieldSetFlags()[4] = false; + return this; + } + + /** + * Gets the value of the 'linkId' field. + * @return The value. + */ + public java.util.List getLinkId() { + return linkId; + } + + + /** + * Sets the value of the 'linkId' field. + * @param value The value of 'linkId'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setLinkId(java.util.List value) { + validate(fields()[5], value); + this.linkId = value; + fieldSetFlags()[5] = true; + return this; + } + + /** + * Checks whether the 'linkId' field has been set. + * @return True if the 'linkId' field has been set, false otherwise. + */ + public boolean hasLinkId() { + return fieldSetFlags()[5]; + } + + + /** + * Clears the value of the 'linkId' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearLinkId() { + linkId = null; + fieldSetFlags()[5] = false; + return this; + } + + /** + * Gets the value of the 'length' field. + * @return The value. + */ + public java.util.List getLength() { + return length; + } + + + /** + * Sets the value of the 'length' field. + * @param value The value of 'length'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setLength(java.util.List value) { + validate(fields()[6], value); + this.length = value; + fieldSetFlags()[6] = true; + return this; + } + + /** + * Checks whether the 'length' field has been set. + * @return True if the 'length' field has been set, false otherwise. + */ + public boolean hasLength() { + return fieldSetFlags()[6]; + } + + + /** + * Clears the value of the 'length' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearLength() { + length = null; + fieldSetFlags()[6] = false; + return this; + } + + /** + * Gets the value of the 'freespeed' field. + * @return The value. + */ + public java.util.List getFreespeed() { + return freespeed; + } + + + /** + * Sets the value of the 'freespeed' field. + * @param value The value of 'freespeed'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setFreespeed(java.util.List value) { + validate(fields()[7], value); + this.freespeed = value; + fieldSetFlags()[7] = true; + return this; + } + + /** + * Checks whether the 'freespeed' field has been set. + * @return True if the 'freespeed' field has been set, false otherwise. + */ + public boolean hasFreespeed() { + return fieldSetFlags()[7]; + } + + + /** + * Clears the value of the 'freespeed' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearFreespeed() { + freespeed = null; + fieldSetFlags()[7] = false; + return this; + } + + /** + * Gets the value of the 'capacity' field. + * @return The value. + */ + public java.util.List getCapacity() { + return capacity; + } + + + /** + * Sets the value of the 'capacity' field. + * @param value The value of 'capacity'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setCapacity(java.util.List value) { + validate(fields()[8], value); + this.capacity = value; + fieldSetFlags()[8] = true; + return this; + } + + /** + * Checks whether the 'capacity' field has been set. + * @return True if the 'capacity' field has been set, false otherwise. + */ + public boolean hasCapacity() { + return fieldSetFlags()[8]; + } + + + /** + * Clears the value of the 'capacity' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearCapacity() { + capacity = null; + fieldSetFlags()[8] = false; + return this; + } + + /** + * Gets the value of the 'permlanes' field. + * @return The value. + */ + public java.util.List getPermlanes() { + return permlanes; + } + + + /** + * Sets the value of the 'permlanes' field. + * @param value The value of 'permlanes'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setPermlanes(java.util.List value) { + validate(fields()[9], value); + this.permlanes = value; + fieldSetFlags()[9] = true; + return this; + } + + /** + * Checks whether the 'permlanes' field has been set. + * @return True if the 'permlanes' field has been set, false otherwise. + */ + public boolean hasPermlanes() { + return fieldSetFlags()[9]; + } + + + /** + * Clears the value of the 'permlanes' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearPermlanes() { + permlanes = null; + fieldSetFlags()[9] = false; + return this; + } + + /** + * Gets the value of the 'allowedModes' field. + * @return The value. + */ + public java.util.List getAllowedModes() { + return allowedModes; + } + + + /** + * Sets the value of the 'allowedModes' field. + * @param value The value of 'allowedModes'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setAllowedModes(java.util.List value) { + validate(fields()[10], value); + this.allowedModes = value; + fieldSetFlags()[10] = true; + return this; + } + + /** + * Checks whether the 'allowedModes' field has been set. + * @return True if the 'allowedModes' field has been set, false otherwise. + */ + public boolean hasAllowedModes() { + return fieldSetFlags()[10]; + } + + + /** + * Clears the value of the 'allowedModes' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearAllowedModes() { + allowedModes = null; + fieldSetFlags()[10] = false; + return this; + } + + /** + * Gets the value of the 'from' field. + * @return The value. + */ + public java.util.List getFrom() { + return from; + } + + + /** + * Sets the value of the 'from' field. + * @param value The value of 'from'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setFrom(java.util.List value) { + validate(fields()[11], value); + this.from = value; + fieldSetFlags()[11] = true; + return this; + } + + /** + * Checks whether the 'from' field has been set. + * @return True if the 'from' field has been set, false otherwise. + */ + public boolean hasFrom() { + return fieldSetFlags()[11]; + } + + + /** + * Clears the value of the 'from' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearFrom() { + from = null; + fieldSetFlags()[11] = false; + return this; + } + + /** + * Gets the value of the 'to' field. + * @return The value. + */ + public java.util.List getTo() { + return to; + } + + + /** + * Sets the value of the 'to' field. + * @param value The value of 'to'. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder setTo(java.util.List value) { + validate(fields()[12], value); + this.to = value; + fieldSetFlags()[12] = true; + return this; + } + + /** + * Checks whether the 'to' field has been set. + * @return True if the 'to' field has been set, false otherwise. + */ + public boolean hasTo() { + return fieldSetFlags()[12]; + } + + + /** + * Clears the value of the 'to' field. + * @return This builder. + */ + public org.matsim.application.avro.AvroNetwork.Builder clearTo() { + to = null; + fieldSetFlags()[12] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public AvroNetwork build() { + try { + AvroNetwork record = new AvroNetwork(); + record.crs = fieldSetFlags()[0] ? this.crs : (java.lang.CharSequence) defaultValue(fields()[0]); + record.nodeId = fieldSetFlags()[1] ? this.nodeId : (java.util.List) defaultValue(fields()[1]); + record.nodeCoordinates = fieldSetFlags()[2] ? this.nodeCoordinates : (java.util.List) defaultValue(fields()[2]); + record.nodeAttributes = fieldSetFlags()[3] ? this.nodeAttributes : (java.util.List) defaultValue(fields()[3]); + record.modes = fieldSetFlags()[4] ? this.modes : (java.util.List) defaultValue(fields()[4]); + record.linkId = fieldSetFlags()[5] ? this.linkId : (java.util.List) defaultValue(fields()[5]); + record.length = fieldSetFlags()[6] ? this.length : (java.util.List) defaultValue(fields()[6]); + record.freespeed = fieldSetFlags()[7] ? this.freespeed : (java.util.List) defaultValue(fields()[7]); + record.capacity = fieldSetFlags()[8] ? this.capacity : (java.util.List) defaultValue(fields()[8]); + record.permlanes = fieldSetFlags()[9] ? this.permlanes : (java.util.List) defaultValue(fields()[9]); + record.allowedModes = fieldSetFlags()[10] ? this.allowedModes : (java.util.List) defaultValue(fields()[10]); + record.from = fieldSetFlags()[11] ? this.from : (java.util.List) defaultValue(fields()[11]); + record.to = fieldSetFlags()[12] ? this.to : (java.util.List) defaultValue(fields()[12]); + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter + WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader + READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override protected boolean hasCustomCoders() { return true; } + + @Override public void customEncode(org.apache.avro.io.Encoder out) + throws java.io.IOException + { + out.writeString(this.crs); + + long size0 = this.nodeId.size(); + out.writeArrayStart(); + out.setItemCount(size0); + long actualSize0 = 0; + for (java.lang.CharSequence e0: this.nodeId) { + actualSize0++; + out.startItem(); + out.writeString(e0); + } + out.writeArrayEnd(); + if (actualSize0 != size0) + throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + "."); + + long size1 = this.nodeCoordinates.size(); + out.writeArrayStart(); + out.setItemCount(size1); + long actualSize1 = 0; + for (java.lang.Float e1: this.nodeCoordinates) { + actualSize1++; + out.startItem(); + out.writeFloat(e1); + } + out.writeArrayEnd(); + if (actualSize1 != size1) + throw new java.util.ConcurrentModificationException("Array-size written was " + size1 + ", but element count was " + actualSize1 + "."); + + long size2 = this.nodeAttributes.size(); + out.writeArrayStart(); + out.setItemCount(size2); + long actualSize2 = 0; + for (java.lang.CharSequence e2: this.nodeAttributes) { + actualSize2++; + out.startItem(); + out.writeString(e2); + } + out.writeArrayEnd(); + if (actualSize2 != size2) + throw new java.util.ConcurrentModificationException("Array-size written was " + size2 + ", but element count was " + actualSize2 + "."); + + long size3 = this.modes.size(); + out.writeArrayStart(); + out.setItemCount(size3); + long actualSize3 = 0; + for (java.lang.CharSequence e3: this.modes) { + actualSize3++; + out.startItem(); + out.writeString(e3); + } + out.writeArrayEnd(); + if (actualSize3 != size3) + throw new java.util.ConcurrentModificationException("Array-size written was " + size3 + ", but element count was " + actualSize3 + "."); + + long size4 = this.linkId.size(); + out.writeArrayStart(); + out.setItemCount(size4); + long actualSize4 = 0; + for (java.lang.CharSequence e4: this.linkId) { + actualSize4++; + out.startItem(); + out.writeString(e4); + } + out.writeArrayEnd(); + if (actualSize4 != size4) + throw new java.util.ConcurrentModificationException("Array-size written was " + size4 + ", but element count was " + actualSize4 + "."); + + long size5 = this.length.size(); + out.writeArrayStart(); + out.setItemCount(size5); + long actualSize5 = 0; + for (java.lang.Float e5: this.length) { + actualSize5++; + out.startItem(); + out.writeFloat(e5); + } + out.writeArrayEnd(); + if (actualSize5 != size5) + throw new java.util.ConcurrentModificationException("Array-size written was " + size5 + ", but element count was " + actualSize5 + "."); + + long size6 = this.freespeed.size(); + out.writeArrayStart(); + out.setItemCount(size6); + long actualSize6 = 0; + for (java.lang.Float e6: this.freespeed) { + actualSize6++; + out.startItem(); + out.writeFloat(e6); + } + out.writeArrayEnd(); + if (actualSize6 != size6) + throw new java.util.ConcurrentModificationException("Array-size written was " + size6 + ", but element count was " + actualSize6 + "."); + + long size7 = this.capacity.size(); + out.writeArrayStart(); + out.setItemCount(size7); + long actualSize7 = 0; + for (java.lang.Float e7: this.capacity) { + actualSize7++; + out.startItem(); + out.writeFloat(e7); + } + out.writeArrayEnd(); + if (actualSize7 != size7) + throw new java.util.ConcurrentModificationException("Array-size written was " + size7 + ", but element count was " + actualSize7 + "."); + + long size8 = this.permlanes.size(); + out.writeArrayStart(); + out.setItemCount(size8); + long actualSize8 = 0; + for (java.lang.Float e8: this.permlanes) { + actualSize8++; + out.startItem(); + out.writeFloat(e8); + } + out.writeArrayEnd(); + if (actualSize8 != size8) + throw new java.util.ConcurrentModificationException("Array-size written was " + size8 + ", but element count was " + actualSize8 + "."); + + long size9 = this.allowedModes.size(); + out.writeArrayStart(); + out.setItemCount(size9); + long actualSize9 = 0; + for (java.lang.Integer e9: this.allowedModes) { + actualSize9++; + out.startItem(); + out.writeInt(e9); + } + out.writeArrayEnd(); + if (actualSize9 != size9) + throw new java.util.ConcurrentModificationException("Array-size written was " + size9 + ", but element count was " + actualSize9 + "."); + + long size10 = this.from.size(); + out.writeArrayStart(); + out.setItemCount(size10); + long actualSize10 = 0; + for (java.lang.CharSequence e10: this.from) { + actualSize10++; + out.startItem(); + out.writeString(e10); + } + out.writeArrayEnd(); + if (actualSize10 != size10) + throw new java.util.ConcurrentModificationException("Array-size written was " + size10 + ", but element count was " + actualSize10 + "."); + + long size11 = this.to.size(); + out.writeArrayStart(); + out.setItemCount(size11); + long actualSize11 = 0; + for (java.lang.CharSequence e11: this.to) { + actualSize11++; + out.startItem(); + out.writeString(e11); + } + out.writeArrayEnd(); + if (actualSize11 != size11) + throw new java.util.ConcurrentModificationException("Array-size written was " + size11 + ", but element count was " + actualSize11 + "."); + + } + + @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) + throws java.io.IOException + { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.crs = in.readString(this.crs instanceof Utf8 ? (Utf8)this.crs : null); + + long size0 = in.readArrayStart(); + java.util.List a0 = this.nodeId; + if (a0 == null) { + a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("nodeId").schema()); + this.nodeId = a0; + } else a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); + for ( ; 0 < size0; size0 = in.arrayNext()) { + for ( ; size0 != 0; size0--) { + java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null); + e0 = in.readString(e0 instanceof Utf8 ? (Utf8)e0 : null); + a0.add(e0); + } + } + + long size1 = in.readArrayStart(); + java.util.List a1 = this.nodeCoordinates; + if (a1 == null) { + a1 = new SpecificData.Array((int)size1, SCHEMA$.getField("nodeCoordinates").schema()); + this.nodeCoordinates = a1; + } else a1.clear(); + SpecificData.Array ga1 = (a1 instanceof SpecificData.Array ? (SpecificData.Array)a1 : null); + for ( ; 0 < size1; size1 = in.arrayNext()) { + for ( ; size1 != 0; size1--) { + java.lang.Float e1 = (ga1 != null ? ga1.peek() : null); + e1 = in.readFloat(); + a1.add(e1); + } + } + + long size2 = in.readArrayStart(); + java.util.List a2 = this.nodeAttributes; + if (a2 == null) { + a2 = new SpecificData.Array((int)size2, SCHEMA$.getField("nodeAttributes").schema()); + this.nodeAttributes = a2; + } else a2.clear(); + SpecificData.Array ga2 = (a2 instanceof SpecificData.Array ? (SpecificData.Array)a2 : null); + for ( ; 0 < size2; size2 = in.arrayNext()) { + for ( ; size2 != 0; size2--) { + java.lang.CharSequence e2 = (ga2 != null ? ga2.peek() : null); + e2 = in.readString(e2 instanceof Utf8 ? (Utf8)e2 : null); + a2.add(e2); + } + } + + long size3 = in.readArrayStart(); + java.util.List a3 = this.modes; + if (a3 == null) { + a3 = new SpecificData.Array((int)size3, SCHEMA$.getField("modes").schema()); + this.modes = a3; + } else a3.clear(); + SpecificData.Array ga3 = (a3 instanceof SpecificData.Array ? (SpecificData.Array)a3 : null); + for ( ; 0 < size3; size3 = in.arrayNext()) { + for ( ; size3 != 0; size3--) { + java.lang.CharSequence e3 = (ga3 != null ? ga3.peek() : null); + e3 = in.readString(e3 instanceof Utf8 ? (Utf8)e3 : null); + a3.add(e3); + } + } + + long size4 = in.readArrayStart(); + java.util.List a4 = this.linkId; + if (a4 == null) { + a4 = new SpecificData.Array((int)size4, SCHEMA$.getField("linkId").schema()); + this.linkId = a4; + } else a4.clear(); + SpecificData.Array ga4 = (a4 instanceof SpecificData.Array ? (SpecificData.Array)a4 : null); + for ( ; 0 < size4; size4 = in.arrayNext()) { + for ( ; size4 != 0; size4--) { + java.lang.CharSequence e4 = (ga4 != null ? ga4.peek() : null); + e4 = in.readString(e4 instanceof Utf8 ? (Utf8)e4 : null); + a4.add(e4); + } + } + + long size5 = in.readArrayStart(); + java.util.List a5 = this.length; + if (a5 == null) { + a5 = new SpecificData.Array((int)size5, SCHEMA$.getField("length").schema()); + this.length = a5; + } else a5.clear(); + SpecificData.Array ga5 = (a5 instanceof SpecificData.Array ? (SpecificData.Array)a5 : null); + for ( ; 0 < size5; size5 = in.arrayNext()) { + for ( ; size5 != 0; size5--) { + java.lang.Float e5 = (ga5 != null ? ga5.peek() : null); + e5 = in.readFloat(); + a5.add(e5); + } + } + + long size6 = in.readArrayStart(); + java.util.List a6 = this.freespeed; + if (a6 == null) { + a6 = new SpecificData.Array((int)size6, SCHEMA$.getField("freespeed").schema()); + this.freespeed = a6; + } else a6.clear(); + SpecificData.Array ga6 = (a6 instanceof SpecificData.Array ? (SpecificData.Array)a6 : null); + for ( ; 0 < size6; size6 = in.arrayNext()) { + for ( ; size6 != 0; size6--) { + java.lang.Float e6 = (ga6 != null ? ga6.peek() : null); + e6 = in.readFloat(); + a6.add(e6); + } + } + + long size7 = in.readArrayStart(); + java.util.List a7 = this.capacity; + if (a7 == null) { + a7 = new SpecificData.Array((int)size7, SCHEMA$.getField("capacity").schema()); + this.capacity = a7; + } else a7.clear(); + SpecificData.Array ga7 = (a7 instanceof SpecificData.Array ? (SpecificData.Array)a7 : null); + for ( ; 0 < size7; size7 = in.arrayNext()) { + for ( ; size7 != 0; size7--) { + java.lang.Float e7 = (ga7 != null ? ga7.peek() : null); + e7 = in.readFloat(); + a7.add(e7); + } + } + + long size8 = in.readArrayStart(); + java.util.List a8 = this.permlanes; + if (a8 == null) { + a8 = new SpecificData.Array((int)size8, SCHEMA$.getField("permlanes").schema()); + this.permlanes = a8; + } else a8.clear(); + SpecificData.Array ga8 = (a8 instanceof SpecificData.Array ? (SpecificData.Array)a8 : null); + for ( ; 0 < size8; size8 = in.arrayNext()) { + for ( ; size8 != 0; size8--) { + java.lang.Float e8 = (ga8 != null ? ga8.peek() : null); + e8 = in.readFloat(); + a8.add(e8); + } + } + + long size9 = in.readArrayStart(); + java.util.List a9 = this.allowedModes; + if (a9 == null) { + a9 = new SpecificData.Array((int)size9, SCHEMA$.getField("allowedModes").schema()); + this.allowedModes = a9; + } else a9.clear(); + SpecificData.Array ga9 = (a9 instanceof SpecificData.Array ? (SpecificData.Array)a9 : null); + for ( ; 0 < size9; size9 = in.arrayNext()) { + for ( ; size9 != 0; size9--) { + java.lang.Integer e9 = (ga9 != null ? ga9.peek() : null); + e9 = in.readInt(); + a9.add(e9); + } + } + + long size10 = in.readArrayStart(); + java.util.List a10 = this.from; + if (a10 == null) { + a10 = new SpecificData.Array((int)size10, SCHEMA$.getField("from").schema()); + this.from = a10; + } else a10.clear(); + SpecificData.Array ga10 = (a10 instanceof SpecificData.Array ? (SpecificData.Array)a10 : null); + for ( ; 0 < size10; size10 = in.arrayNext()) { + for ( ; size10 != 0; size10--) { + java.lang.CharSequence e10 = (ga10 != null ? ga10.peek() : null); + e10 = in.readString(e10 instanceof Utf8 ? (Utf8)e10 : null); + a10.add(e10); + } + } + + long size11 = in.readArrayStart(); + java.util.List a11 = this.to; + if (a11 == null) { + a11 = new SpecificData.Array((int)size11, SCHEMA$.getField("to").schema()); + this.to = a11; + } else a11.clear(); + SpecificData.Array ga11 = (a11 instanceof SpecificData.Array ? (SpecificData.Array)a11 : null); + for ( ; 0 < size11; size11 = in.arrayNext()) { + for ( ; size11 != 0; size11--) { + java.lang.CharSequence e11 = (ga11 != null ? ga11.peek() : null); + e11 = in.readString(e11 instanceof Utf8 ? (Utf8)e11 : null); + a11.add(e11); + } + } + + } else { + for (int i = 0; i < 13; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.crs = in.readString(this.crs instanceof Utf8 ? (Utf8)this.crs : null); + break; + + case 1: + long size0 = in.readArrayStart(); + java.util.List a0 = this.nodeId; + if (a0 == null) { + a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("nodeId").schema()); + this.nodeId = a0; + } else a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); + for ( ; 0 < size0; size0 = in.arrayNext()) { + for ( ; size0 != 0; size0--) { + java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null); + e0 = in.readString(e0 instanceof Utf8 ? (Utf8)e0 : null); + a0.add(e0); + } + } + break; + + case 2: + long size1 = in.readArrayStart(); + java.util.List a1 = this.nodeCoordinates; + if (a1 == null) { + a1 = new SpecificData.Array((int)size1, SCHEMA$.getField("nodeCoordinates").schema()); + this.nodeCoordinates = a1; + } else a1.clear(); + SpecificData.Array ga1 = (a1 instanceof SpecificData.Array ? (SpecificData.Array)a1 : null); + for ( ; 0 < size1; size1 = in.arrayNext()) { + for ( ; size1 != 0; size1--) { + java.lang.Float e1 = (ga1 != null ? ga1.peek() : null); + e1 = in.readFloat(); + a1.add(e1); + } + } + break; + + case 3: + long size2 = in.readArrayStart(); + java.util.List a2 = this.nodeAttributes; + if (a2 == null) { + a2 = new SpecificData.Array((int)size2, SCHEMA$.getField("nodeAttributes").schema()); + this.nodeAttributes = a2; + } else a2.clear(); + SpecificData.Array ga2 = (a2 instanceof SpecificData.Array ? (SpecificData.Array)a2 : null); + for ( ; 0 < size2; size2 = in.arrayNext()) { + for ( ; size2 != 0; size2--) { + java.lang.CharSequence e2 = (ga2 != null ? ga2.peek() : null); + e2 = in.readString(e2 instanceof Utf8 ? (Utf8)e2 : null); + a2.add(e2); + } + } + break; + + case 4: + long size3 = in.readArrayStart(); + java.util.List a3 = this.modes; + if (a3 == null) { + a3 = new SpecificData.Array((int)size3, SCHEMA$.getField("modes").schema()); + this.modes = a3; + } else a3.clear(); + SpecificData.Array ga3 = (a3 instanceof SpecificData.Array ? (SpecificData.Array)a3 : null); + for ( ; 0 < size3; size3 = in.arrayNext()) { + for ( ; size3 != 0; size3--) { + java.lang.CharSequence e3 = (ga3 != null ? ga3.peek() : null); + e3 = in.readString(e3 instanceof Utf8 ? (Utf8)e3 : null); + a3.add(e3); + } + } + break; + + case 5: + long size4 = in.readArrayStart(); + java.util.List a4 = this.linkId; + if (a4 == null) { + a4 = new SpecificData.Array((int)size4, SCHEMA$.getField("linkId").schema()); + this.linkId = a4; + } else a4.clear(); + SpecificData.Array ga4 = (a4 instanceof SpecificData.Array ? (SpecificData.Array)a4 : null); + for ( ; 0 < size4; size4 = in.arrayNext()) { + for ( ; size4 != 0; size4--) { + java.lang.CharSequence e4 = (ga4 != null ? ga4.peek() : null); + e4 = in.readString(e4 instanceof Utf8 ? (Utf8)e4 : null); + a4.add(e4); + } + } + break; + + case 6: + long size5 = in.readArrayStart(); + java.util.List a5 = this.length; + if (a5 == null) { + a5 = new SpecificData.Array((int)size5, SCHEMA$.getField("length").schema()); + this.length = a5; + } else a5.clear(); + SpecificData.Array ga5 = (a5 instanceof SpecificData.Array ? (SpecificData.Array)a5 : null); + for ( ; 0 < size5; size5 = in.arrayNext()) { + for ( ; size5 != 0; size5--) { + java.lang.Float e5 = (ga5 != null ? ga5.peek() : null); + e5 = in.readFloat(); + a5.add(e5); + } + } + break; + + case 7: + long size6 = in.readArrayStart(); + java.util.List a6 = this.freespeed; + if (a6 == null) { + a6 = new SpecificData.Array((int)size6, SCHEMA$.getField("freespeed").schema()); + this.freespeed = a6; + } else a6.clear(); + SpecificData.Array ga6 = (a6 instanceof SpecificData.Array ? (SpecificData.Array)a6 : null); + for ( ; 0 < size6; size6 = in.arrayNext()) { + for ( ; size6 != 0; size6--) { + java.lang.Float e6 = (ga6 != null ? ga6.peek() : null); + e6 = in.readFloat(); + a6.add(e6); + } + } + break; + + case 8: + long size7 = in.readArrayStart(); + java.util.List a7 = this.capacity; + if (a7 == null) { + a7 = new SpecificData.Array((int)size7, SCHEMA$.getField("capacity").schema()); + this.capacity = a7; + } else a7.clear(); + SpecificData.Array ga7 = (a7 instanceof SpecificData.Array ? (SpecificData.Array)a7 : null); + for ( ; 0 < size7; size7 = in.arrayNext()) { + for ( ; size7 != 0; size7--) { + java.lang.Float e7 = (ga7 != null ? ga7.peek() : null); + e7 = in.readFloat(); + a7.add(e7); + } + } + break; + + case 9: + long size8 = in.readArrayStart(); + java.util.List a8 = this.permlanes; + if (a8 == null) { + a8 = new SpecificData.Array((int)size8, SCHEMA$.getField("permlanes").schema()); + this.permlanes = a8; + } else a8.clear(); + SpecificData.Array ga8 = (a8 instanceof SpecificData.Array ? (SpecificData.Array)a8 : null); + for ( ; 0 < size8; size8 = in.arrayNext()) { + for ( ; size8 != 0; size8--) { + java.lang.Float e8 = (ga8 != null ? ga8.peek() : null); + e8 = in.readFloat(); + a8.add(e8); + } + } + break; + + case 10: + long size9 = in.readArrayStart(); + java.util.List a9 = this.allowedModes; + if (a9 == null) { + a9 = new SpecificData.Array((int)size9, SCHEMA$.getField("allowedModes").schema()); + this.allowedModes = a9; + } else a9.clear(); + SpecificData.Array ga9 = (a9 instanceof SpecificData.Array ? (SpecificData.Array)a9 : null); + for ( ; 0 < size9; size9 = in.arrayNext()) { + for ( ; size9 != 0; size9--) { + java.lang.Integer e9 = (ga9 != null ? ga9.peek() : null); + e9 = in.readInt(); + a9.add(e9); + } + } + break; + + case 11: + long size10 = in.readArrayStart(); + java.util.List a10 = this.from; + if (a10 == null) { + a10 = new SpecificData.Array((int)size10, SCHEMA$.getField("from").schema()); + this.from = a10; + } else a10.clear(); + SpecificData.Array ga10 = (a10 instanceof SpecificData.Array ? (SpecificData.Array)a10 : null); + for ( ; 0 < size10; size10 = in.arrayNext()) { + for ( ; size10 != 0; size10--) { + java.lang.CharSequence e10 = (ga10 != null ? ga10.peek() : null); + e10 = in.readString(e10 instanceof Utf8 ? (Utf8)e10 : null); + a10.add(e10); + } + } + break; + + case 12: + long size11 = in.readArrayStart(); + java.util.List a11 = this.to; + if (a11 == null) { + a11 = new SpecificData.Array((int)size11, SCHEMA$.getField("to").schema()); + this.to = a11; + } else a11.clear(); + SpecificData.Array ga11 = (a11 instanceof SpecificData.Array ? (SpecificData.Array)a11 : null); + for ( ; 0 < size11; size11 = in.arrayNext()) { + for ( ; size11 != 0; size11--) { + java.lang.CharSequence e11 = (ga11 != null ? ga11.peek() : null); + e11 = in.readString(e11 instanceof Utf8 ? (Utf8)e11 : null); + a11.add(e11); + } + } + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} + + + + + + + + + + diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateAvroNetwork.java b/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateAvroNetwork.java new file mode 100644 index 00000000000..bd25fcfea38 --- /dev/null +++ b/contribs/application/src/main/java/org/matsim/application/prepare/network/CreateAvroNetwork.java @@ -0,0 +1,223 @@ +package org.matsim.application.prepare.network; + +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import org.apache.avro.file.CodecFactory; +import org.apache.avro.file.DataFileWriter; +import org.apache.avro.io.DatumWriter; +import org.apache.avro.specific.SpecificDatumWriter; +import org.locationtech.jts.geom.Geometry; +import org.matsim.api.core.v01.Coord; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.Node; +import org.matsim.application.CommandSpec; +import org.matsim.application.MATSimAppCommand; +import org.matsim.application.avro.AvroNetwork; +import org.matsim.application.options.CrsOptions; +import org.matsim.application.options.InputOptions; +import org.matsim.application.options.OutputOptions; +import org.matsim.application.options.ShpOptions; +import org.matsim.core.scenario.ProjectionUtils; +import org.matsim.core.utils.geometry.CoordinateTransformation; +import org.matsim.core.utils.geometry.geotools.MGC; +import org.matsim.core.utils.geometry.transformations.TransformationFactory; +import org.matsim.core.utils.io.IOUtils; +import picocli.CommandLine; + +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.regex.Pattern; + + +@CommandLine.Command(name = "network-avro", description = "Create avro representation of a network.") +@CommandSpec(requireNetwork = true, produces = "network.avro") +public class CreateAvroNetwork implements MATSimAppCommand { + @CommandLine.Mixin + private InputOptions input = InputOptions.ofCommand(CreateAvroNetwork.class); + @CommandLine.Mixin + private OutputOptions output = OutputOptions.ofCommand(CreateAvroNetwork.class); + @CommandLine.Mixin + private ShpOptions shp; + @CommandLine.Mixin + private CrsOptions crs = new CrsOptions(null, "EPSG:4326"); + + @CommandLine.Option(names = "--match-id", description = "Pattern to filter links by id") + private String matchId; + + @CommandLine.Option(names = "--mode-filter", split = ",", defaultValue = "car,freight,drt", + description = "Only keep links if they have one of the specified modes. Specify 'none' to disable.") + private Set modes; + + @CommandLine.Option(names = "--precision", description = "Number of decimals places", defaultValue = "6") + private int precision; + + @CommandLine.Option(names = "--with-properties", description = "Put network attributes as properties into the geojson.") + private boolean withProperties; + + @CommandLine.Option(names = "--filter-properties", description = "Only include listed properties in the output.") + private Set filterProperties; + + public static void main(String[] args) { + new CreateAvroNetwork().execute(args); + } + + @Override + public Integer call() throws Exception { + + Network network = input.getNetwork(); + + String networkCrs = ProjectionUtils.getCRS(input.getNetwork()); + if (crs.getInputCRS() != null) + networkCrs = crs.getInputCRS(); + + if (networkCrs == null) { + throw new IllegalArgumentException("Network coordinate system is neither in the xml nor given as option."); + } + + + AvroNetwork avro = new AvroNetwork(); + avro.setCrs(networkCrs); + + Predicate filter = link -> true; + + if (shp.isDefined()) { + Geometry geom = shp.getGeometry(); + CoordinateTransformation ct = shp.createTransformation(networkCrs); + + filter = link -> geom.contains(MGC.coord2Point(ct.transform(link.getFromNode().getCoord()))) || + geom.contains(MGC.coord2Point(ct.transform(link.getToNode().getCoord()))); + } + + if (matchId != null) { + Pattern p = Pattern.compile(matchId); + filter = filter.and(link -> p.matcher(link.getId().toString()).matches()); + } + + // At least one of the specified modes needs to be contained + if (!modes.isEmpty() && !modes.equals(Set.of("none"))) { + filter = filter.and(link -> modes.stream().anyMatch(m -> link.getAllowedModes().contains(m))); + } + +// AvroNetwork.getClassSchema().addProp(); + + convert(avro, network, TransformationFactory.getCoordinateTransformation(networkCrs, this.crs.getTargetCRS()), filter); + + writeAvro(avro, output.getPath().toFile()); + + return 0; + } + + /** + * Converts the given network to a GeoJson representation. + * + * @param avro the AvroNetwork to write to + * @param network the network to convert + * @param ct the coordinate transformation to use + * @param filter the filter to apply to the links + */ + private void convert(AvroNetwork avro, Network network, CoordinateTransformation ct, Predicate filter) { + + // Node atteibues + List nodeCoords = new ArrayList<>(); + List nodeIds = new ArrayList<>(); + Set nodeAttributes = new LinkedHashSet<>(); + + + for (Node node : network.getNodes().values()) { + Coord from = ct.transform(node.getCoord()); + double xCoord = round(from.getX()); + double yCoord = round(from.getY()); + nodeCoords.add((float) xCoord); + nodeCoords.add((float) yCoord); + + String nodeId = node.getId().toString(); + nodeIds.add(nodeId); + nodeAttributes.addAll(node.getAttributes().getAsMap().keySet()); + } + + // Set the node attributes + avro.setNodeCoordinates(nodeCoords); + avro.setNodeId(nodeIds); + avro.setNodeAttributes(nodeAttributes.stream().toList()); + + + // Link attributes + List lengths = new ArrayList<>(); + List freeSpeeds = new ArrayList<>(); + List capacities = new ArrayList<>(); + List permLanes = new ArrayList<>(); + List ids = new ArrayList<>(); + List froms = new ArrayList<>(); + List tos = new ArrayList<>(); + List allowedModes = new ArrayList<>(); + + Object2IntMap modeMapping = new Object2IntLinkedOpenHashMap<>(); + + for (Link link : network.getLinks().values()) { + if (!filter.test(link)) + continue; + + lengths.add((float) link.getLength()); + freeSpeeds.add((float) link.getFreespeed()); + capacities.add((float) link.getCapacity()); + permLanes.add((float) link.getNumberOfLanes()); + + String m = String.join(",", link.getAllowedModes()); + allowedModes.add(modeMapping.computeIfAbsent(m, k -> modeMapping.size())); + + ids.add(link.getId().toString()); + froms.add(link.getFromNode().getId().toString()); + tos.add(link.getToNode().getId().toString()); + } + + // Set the mapping which assigns an integer to each possible allowed mode entry + avro.setModes(modeMapping.keySet().stream().toList()); + + // Set the link attributes + avro.setLength(lengths); + avro.setFreespeed(freeSpeeds); + avro.setCapacity(capacities); + avro.setPermlanes(permLanes); + avro.setAllowedModes(allowedModes); + + avro.setLinkId(ids); + avro.setFrom(froms); + avro.setTo(tos); + } + + /** + * Writes the given data to the given file. + * + * @param avroNetwork the data to write + * @param output the file to write to + */ + private void writeAvro(AvroNetwork avroNetwork, File output) { + DatumWriter datumWriter = new SpecificDatumWriter<>(AvroNetwork.class); + try (DataFileWriter dataFileWriter = new DataFileWriter<>(datumWriter)) { + dataFileWriter.setCodec(CodecFactory.deflateCodec(9)); + dataFileWriter.create(avroNetwork.getSchema(), IOUtils.getOutputStream(IOUtils.getFileUrl(output.toString()), false)); + dataFileWriter.append(avroNetwork); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + /** + * Round to desired precision. + */ + private double round(double x) { + BigDecimal d = BigDecimal.valueOf(x).setScale(precision, RoundingMode.HALF_UP); + return d.doubleValue(); + } + +} diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/OverviewDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/OverviewDashboard.java index 089ee4c8ce9..4c0f2187c1a 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/OverviewDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/OverviewDashboard.java @@ -2,6 +2,7 @@ import org.matsim.application.analysis.LogFileAnalysis; import org.matsim.application.analysis.traffic.TrafficAnalysis; +import org.matsim.application.prepare.network.CreateAvroNetwork; import org.matsim.application.prepare.network.CreateGeoJsonNetwork; import org.matsim.simwrapper.Dashboard; import org.matsim.simwrapper.Header; @@ -35,6 +36,7 @@ public void configure(Header header, Layout layout) { viz.height = 7.5; viz.width = 2.0; +// viz.setShape(data.compute(CreateAvroNetwork.class, "network.avro", "--with-properties"), "id"); viz.setShape(data.compute(CreateGeoJsonNetwork.class, "network.geojson", "--with-properties"), "id"); viz.addDataset("traffic", data.compute(TrafficAnalysis.class, "traffic_stats_by_link_daily.csv"));