diff --git a/core/src/main/java/com/graphhopper/routing/util/DataFlagEncoder.java b/core/src/main/java/com/graphhopper/routing/util/DataFlagEncoder.java index 8a7ab6642e5..4c564761c71 100644 --- a/core/src/main/java/com/graphhopper/routing/util/DataFlagEncoder.java +++ b/core/src/main/java/com/graphhopper/routing/util/DataFlagEncoder.java @@ -129,7 +129,7 @@ public DataFlagEncoder() { "delivery", "agricultural", "no" - ); + ); counter = 0; @@ -210,9 +210,9 @@ int getHighwayValue(ReaderWay way) { int getAccessValue(ReaderWay way) { int accessValue = 0; Integer tmpAccessValue = 0; - for (String restriction: restrictions) { + for (String restriction : restrictions) { tmpAccessValue = accessMap.get(way.getTag(restriction, "yes")); - if(tmpAccessValue != null && tmpAccessValue > accessValue){ + if (tmpAccessValue != null && tmpAccessValue > accessValue) { accessValue = tmpAccessValue; } } @@ -221,9 +221,9 @@ int getAccessValue(ReaderWay way) { } //TODO It is bad that it's a bit static right now. If anyone changes the accessMap this method won't work anymore... - public AccessValue getEdgeAccessValue(long flags){ + public AccessValue getEdgeAccessValue(long flags) { int accessValue = (int) accessEncoder.getValue(flags); - switch (accessValue){ + switch (accessValue) { case 0: return AccessValue.ACCESSIBLE; case 5: @@ -355,6 +355,9 @@ public String getHighwayAsString(EdgeIteratorState edge) { } public double[] getHighwaySpeedMap(Map map) { + if (map == null) + throw new IllegalArgumentException("Map cannot be null when calling getHighwaySpeedMap"); + double[] res = new double[highwayMap.size()]; for (Entry e : map.entrySet()) { Integer integ = highwayMap.get(e.getKey()); @@ -575,7 +578,7 @@ public ConfigMap readStringMap(PMap weightingMap) { return cMap; } - public enum AccessValue{ + public enum AccessValue { ACCESSIBLE, EVENTUALLY_ACCESSIBLE, diff --git a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java index 1b61c5401ba..ca960eebbf7 100644 --- a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java +++ b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java @@ -38,10 +38,9 @@ */ public class GenericWeighting extends AbstractWeighting { /** - * Converting to seconds is not necessary but makes adding other penalties easier (e.g. turn - * costs or traffic light costs etc) + * Convert to milliseconds for correct calcMillis. */ - protected final static double SPEED_CONV = 3.6; + private final static double SPEED_CONV = 3600; private final double headingPenalty; private final long headingPenaltyMillis; private final double maxSpeed; diff --git a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java index fdee2b9909a..dde67760969 100644 --- a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java +++ b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java @@ -41,14 +41,14 @@ * @author Peter Karich */ public class GenericWeightingTest { - private final EncodingManager em = new EncodingManager("generic"); - private final DataFlagEncoder encoder = (DataFlagEncoder) em.getEncoder("generic"); + private final DataFlagEncoder encoder = new DataFlagEncoder(); + private final EncodingManager em = new EncodingManager(encoder); private Graph graph; - private final double edgeWeight = 566; + private final double edgeWeight = 566111; @Before - public void setup() { + public void setUp() { ReaderWay way = new ReaderWay(27l); way.setTag("highway", "primary"); way.setTag("maxspeed", "10"); @@ -98,4 +98,12 @@ public void testBlockedByShape() { instance.setGraph(graph); assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); } + + @Test + public void testCalcTime() { + ConfigMap cMap = encoder.readStringMap(new PMap()); + GenericWeighting weighting = new GenericWeighting(encoder, cMap); + EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1); + assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1); + } }