Do you think that we could extend the "automagic" for Attributable to also write/read maps?
We have this increasingly in our code. One instance is PrepareForSimImpl#createAndAddVehiclesForEveryNetworkMode, which then calls VehicleUtils#insertVehicleIdIntoAttributes, which finally puts a Map into the Attributes.
This works, but is not written to file.
It seems to me that we could write something like
<attribute name="modeVehicles" class="java.util.Map????"> car="321_car" bike="321_bike" etc.</attribute>
This would use the same specification as XML attributes, i.e. no commas between key=value pairs.
Presumably, this would work first for Map<String,String>, and eventually we might be able to also make it work for Map<String,Number>.
What do you think? We might try to implement this ourselves, but would like to have your input on possible roadblocks that we are overlooking. Thanks a lot.
That would be nice, but it is difficult. The main issue is that the generic type parameters (key and value types) are not available at run time. I find assuming all maps are Map<String, String> dangerous, as surely users will not expect it.
A solution would be to add attribute converters for “typed” collection types, such as the ones from Trove, which are already in MATSim’s classpath.
Another solution would be to map to an instance of Attributes. That way, you would have:
I think that this would require an extension to the dtd, but it looks much cleaner in my opinion. Is there any argument to preferring a Map type to that solution?