
Hi programmers, I'd like to add a method like Coord.moveTo(int lat, int long) to set new values in an existing Coord. To do that I have to remove the final attribute from the latitude and longitude fields. Is that known to cause problems? If not, the method could also be used to simplify removeShortArcs (we could drop the IdentityHashMap replacements and other stuff around that) Gerd -- View this message in context: http://gis.19327.n5.nabble.com/final-fields-in-Coord-tp5783182.html Sent from the Mkgmap Development mailing list archive at Nabble.com.

On 28/10/13 17:34, GerdP wrote:
To do that I have to remove the final attribute from the latitude and longitude fields. Is that known to cause problems?
Coord is used as the key of a Map in lots of places. If you change the lat or long then that also changes the hashCode and will cause a bug whenever the Coord is changed between put() and or get() on the Map. While your change may not do that it, it becomes a bug waiting to happen later on when someone else makes another change, so it is a bad idea from that point of view. I can see why you want to do it though. Do you only need to move things that are really CoordNodes? ..Steve

Hi Steve,
Coord is used as the key of a Map in lots of places.
If you change the lat or long then that also changes the hashCode and will cause a bug whenever the Coord is changed between put() and or get() on the Map.
OK, that seems to be a good argument against it, but on the other hand I think we always use IdentityHashMap because we want to find the same instance, not just an equal point, at least in StyledConverter (where I want to use the moveTo() method.
While your change may not do that it, it becomes a bug waiting to happen later on when someone else makes another change, so it is a bad idea from that point of view. I can see why you want to do it though. Do you only need to move things that are really CoordNodes?
no, I am working on a new version of the frigRoundabout method. I think it works quite good, but I can change it to also use the replacements map like removeShortArcs. See attached patch. Missing: Code to make sure that an end-point of a way connected to a roundabout is not moved too much (creating a spike). Gerd

Hi Gerd
Coord is used as the key of a Map in lots of places.
If you change the lat or long then that also changes the hashCode and will cause a bug whenever the Coord is changed between put() and or get() on the Map.
OK, that seems to be a good argument against it, but on the other hand I think we always use IdentityHashMap because we want to find the same instance, not just an equal point, at least in StyledConverter (where I want to use the moveTo() method.
Elsewhere it is used in a regular hash map for example: MultiPolygonRelation.java Map<Coord, JoinedWay> outOfBboxPoints = new HashMap<Coord, JoinedWay>(); POIGeneratorHook.java Map<Coord, Integer> labelCoords = new HashMap<Coord, Integer>(); SeaGenerator.java Map<Coord, Way> beginMap = new HashMap<Coord, Way>(); BoundaryRelation.java Map<Coord, JoinedWay> outOfBboxPoints = new HashMap<Coord, JoinedWay>(); PrecompSeaSaver.java Map<Coord, Long> coordIds = new HashMap<Coord, Long>(); ..Steve

Hi Steve, yes, I agree that the replacements map is the safer solution. I'll post a 2nd version of the patch tomorrow. Gerd Steve Ratcliffe wrote
Hi Gerd
Coord is used as the key of a Map in lots of places.
If you change the lat or long then that also changes the hashCode and will cause a bug whenever the Coord is changed between put() and or get() on the Map.
OK, that seems to be a good argument against it, but on the other hand I think we always use IdentityHashMap because we want to find the same instance, not just an equal point, at least in StyledConverter (where I want to use the moveTo() method.
Elsewhere it is used in a regular hash map for example:
MultiPolygonRelation.java Map<Coord, JoinedWay> outOfBboxPoints = new HashMap<Coord, JoinedWay>(); POIGeneratorHook.java Map<Coord, Integer> labelCoords = new HashMap<Coord, Integer>(); SeaGenerator.java Map<Coord, Way> beginMap = new HashMap<Coord, Way>(); BoundaryRelation.java Map<Coord, JoinedWay> outOfBboxPoints = new HashMap<Coord, JoinedWay>(); PrecompSeaSaver.java Map<Coord, Long> coordIds = new HashMap<Coord, Long>();
..Steve _______________________________________________ mkgmap-dev mailing list
mkgmap-dev@.org
-- View this message in context: http://gis.19327.n5.nabble.com/final-fields-in-Coord-tp5783182p5783208.html Sent from the Mkgmap Development mailing list archive at Nabble.com.
participants (3)
-
Gerd Petermann
-
GerdP
-
Steve Ratcliffe