From 1046bae920168bbd131b1404430e088de7a6cf3a Mon Sep 17 00:00:00 2001 From: Andi Date: Fri, 19 Jan 2024 14:11:33 +0100 Subject: [PATCH] Remove the name property from vehicle parsers (#2931) --- .../java/com/graphhopper/GraphHopper.java | 2 +- .../util/DefaultVehicleTagParserFactory.java | 2 +- .../routing/util/VehicleEncodedValues.java | 27 +++++++++-------- .../routing/util/VehicleTagParsers.java | 24 +++++++-------- .../util/parsers/BikeAccessParser.java | 2 +- .../util/parsers/BikeAverageSpeedParser.java | 5 ++-- .../util/parsers/BikePriorityParser.java | 7 ++--- .../routing/util/parsers/CarAccessParser.java | 4 +-- .../util/parsers/CarAverageSpeedParser.java | 5 ++-- .../util/parsers/FootAccessParser.java | 2 +- .../util/parsers/FootAverageSpeedParser.java | 5 ++-- .../util/parsers/FootPriorityParser.java | 5 ++-- .../parsers/MountainBikeAccessParser.java | 2 +- .../MountainBikeAverageSpeedParser.java | 5 ++-- .../parsers/MountainBikePriorityParser.java | 7 ++--- .../util/parsers/RacingBikeAccessParser.java | 2 +- .../parsers/RacingBikeAverageSpeedParser.java | 5 ++-- .../parsers/RacingBikePriorityParser.java | 7 ++--- .../util/parsers/RoadsAccessParser.java | 5 ++-- .../util/parsers/RoadsAverageSpeedParser.java | 7 ++--- .../graphhopper/reader/osm/OSMReaderTest.java | 29 +++++-------------- ...fficChangeWithNodeOrderingReusingTest.java | 2 +- .../util/parsers/CarTagParserTest.java | 8 ++--- .../util/parsers/FootTagParserTest.java | 11 +++---- .../util/parsers/HikeCustomModelTest.java | 3 +- .../util/parsers/RacingBikeTagParserTest.java | 4 +-- .../util/parsers/RoadsTagParserTest.java | 4 +-- .../routing/util/parsers/TagParsingTest.java | 10 +++---- 28 files changed, 88 insertions(+), 113 deletions(-) diff --git a/core/src/main/java/com/graphhopper/GraphHopper.java b/core/src/main/java/com/graphhopper/GraphHopper.java index 64ee5fd87f4..b89a19067aa 100644 --- a/core/src/main/java/com/graphhopper/GraphHopper.java +++ b/core/src/main/java/com/graphhopper/GraphHopper.java @@ -695,7 +695,7 @@ protected OSMParsers buildOSMParsers(Map vehiclesByName, List new OSMFootNetworkTagParser(encodingManager.getEnumEncodedValue(FootNetwork.KEY, RouteNetwork.class), relConfig)); } - String turnRestrictionKey = TurnRestriction.key(new PMap(vehicleStr).getString("name", name)); + String turnRestrictionKey = TurnRestriction.key(name); if (encodingManager.hasTurnEncodedValue(turnRestrictionKey) // need to make sure we do not add the same restriction parsers multiple times && osmParsers.getRestrictionTagParsers().stream().noneMatch(r -> r.getTurnRestrictionEnc().getName().equals(turnRestrictionKey))) { diff --git a/core/src/main/java/com/graphhopper/routing/util/DefaultVehicleTagParserFactory.java b/core/src/main/java/com/graphhopper/routing/util/DefaultVehicleTagParserFactory.java index 45acdef6bb3..aba279bcd43 100644 --- a/core/src/main/java/com/graphhopper/routing/util/DefaultVehicleTagParserFactory.java +++ b/core/src/main/java/com/graphhopper/routing/util/DefaultVehicleTagParserFactory.java @@ -26,7 +26,7 @@ public class DefaultVehicleTagParserFactory implements VehicleTagParserFactory { public VehicleTagParsers createParsers(EncodedValueLookup lookup, String name, PMap configuration) { if (name.equals(ROADS)) - return VehicleTagParsers.roads(lookup, configuration); + return VehicleTagParsers.roads(lookup); if (name.equals(CAR)) return VehicleTagParsers.car(lookup, configuration); if (name.equals(BIKE)) diff --git a/core/src/main/java/com/graphhopper/routing/util/VehicleEncodedValues.java b/core/src/main/java/com/graphhopper/routing/util/VehicleEncodedValues.java index 0d487e5ad5f..37f922190d3 100644 --- a/core/src/main/java/com/graphhopper/routing/util/VehicleEncodedValues.java +++ b/core/src/main/java/com/graphhopper/routing/util/VehicleEncodedValues.java @@ -36,7 +36,7 @@ public class VehicleEncodedValues { private final BooleanEncodedValue turnRestrictionEnc; public static VehicleEncodedValues foot(PMap properties) { - String name = properties.getString("name", "foot"); + String name = "foot"; int speedBits = properties.getInt("speed_bits", 4); double speedFactor = properties.getDouble("speed_factor", 1); boolean speedTwoDirections = properties.getBool("speed_two_directions", false); @@ -49,7 +49,18 @@ public static VehicleEncodedValues foot(PMap properties) { } public static VehicleEncodedValues bike(PMap properties) { - String name = properties.getString("name", "bike"); + return createBike(properties, "bike"); + } + + public static VehicleEncodedValues racingbike(PMap properties) { + return createBike(properties, "racingbike"); + } + + public static VehicleEncodedValues mountainbike(PMap properties) { + return createBike(properties, "mtb"); + } + + private static VehicleEncodedValues createBike(PMap properties, String name) { int speedBits = properties.getInt("speed_bits", 4); double speedFactor = properties.getDouble("speed_factor", 2); boolean speedTwoDirections = properties.getBool("speed_two_directions", false); @@ -61,16 +72,8 @@ public static VehicleEncodedValues bike(PMap properties) { return new VehicleEncodedValues(name, accessEnc, speedEnc, priorityEnc, turnRestrictionEnc); } - public static VehicleEncodedValues racingbike(PMap properties) { - return bike(new PMap(properties).putObject("name", properties.getString("name", "racingbike"))); - } - - public static VehicleEncodedValues mountainbike(PMap properties) { - return bike(new PMap(properties).putObject("name", properties.getString("name", "mtb"))); - } - public static VehicleEncodedValues car(PMap properties) { - String name = properties.getString("name", "car"); + String name = "car"; int speedBits = properties.getInt("speed_bits", 7); double speedFactor = properties.getDouble("speed_factor", 2); boolean turnCosts = properties.getBool("turn_costs", false); @@ -81,7 +84,7 @@ public static VehicleEncodedValues car(PMap properties) { } public static VehicleEncodedValues roads(PMap properties) { - String name = properties.getString("name", "roads"); + String name = "roads"; int speedBits = properties.getInt("speed_bits", 7); double speedFactor = properties.getDouble("speed_factor", 2); boolean speedTwoDirections = properties.getBool("speed_two_directions", true); diff --git a/core/src/main/java/com/graphhopper/routing/util/VehicleTagParsers.java b/core/src/main/java/com/graphhopper/routing/util/VehicleTagParsers.java index a051f86c36f..f0106f90450 100644 --- a/core/src/main/java/com/graphhopper/routing/util/VehicleTagParsers.java +++ b/core/src/main/java/com/graphhopper/routing/util/VehicleTagParsers.java @@ -31,10 +31,10 @@ public class VehicleTagParsers { private final TagParser speedParser; private final TagParser priorityParser; - public static VehicleTagParsers roads(EncodedValueLookup lookup, PMap properties) { + public static VehicleTagParsers roads(EncodedValueLookup lookup) { return new VehicleTagParsers( - new RoadsAccessParser(lookup, properties), - new RoadsAverageSpeedParser(lookup, properties), + new RoadsAccessParser(lookup), + new RoadsAverageSpeedParser(lookup), null ); } @@ -42,7 +42,7 @@ public static VehicleTagParsers roads(EncodedValueLookup lookup, PMap properties public static VehicleTagParsers car(EncodedValueLookup lookup, PMap properties) { return new VehicleTagParsers( new CarAccessParser(lookup, properties).init(properties.getObject("date_range_parser", new DateRangeParser())), - new CarAverageSpeedParser(lookup, properties), + new CarAverageSpeedParser(lookup), null ); } @@ -50,32 +50,32 @@ public static VehicleTagParsers car(EncodedValueLookup lookup, PMap properties) public static VehicleTagParsers bike(EncodedValueLookup lookup, PMap properties) { return new VehicleTagParsers( new BikeAccessParser(lookup, properties).init(properties.getObject("date_range_parser", new DateRangeParser())), - new BikeAverageSpeedParser(lookup, properties), - new BikePriorityParser(lookup, properties) + new BikeAverageSpeedParser(lookup), + new BikePriorityParser(lookup) ); } public static VehicleTagParsers racingbike(EncodedValueLookup lookup, PMap properties) { return new VehicleTagParsers( new RacingBikeAccessParser(lookup, properties).init(properties.getObject("date_range_parser", new DateRangeParser())), - new RacingBikeAverageSpeedParser(lookup, properties), - new RacingBikePriorityParser(lookup, properties) + new RacingBikeAverageSpeedParser(lookup), + new RacingBikePriorityParser(lookup) ); } public static VehicleTagParsers mtb(EncodedValueLookup lookup, PMap properties) { return new VehicleTagParsers( new MountainBikeAccessParser(lookup, properties).init(properties.getObject("date_range_parser", new DateRangeParser())), - new MountainBikeAverageSpeedParser(lookup, properties), - new MountainBikePriorityParser(lookup, properties) + new MountainBikeAverageSpeedParser(lookup), + new MountainBikePriorityParser(lookup) ); } public static VehicleTagParsers foot(EncodedValueLookup lookup, PMap properties) { return new VehicleTagParsers( new FootAccessParser(lookup, properties).init(properties.getObject("date_range_parser", new DateRangeParser())), - new FootAverageSpeedParser(lookup, properties), - new FootPriorityParser(lookup, properties) + new FootAverageSpeedParser(lookup), + new FootPriorityParser(lookup) ); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAccessParser.java index e67fbfe31e6..28ffbeb33c1 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAccessParser.java @@ -9,7 +9,7 @@ public class BikeAccessParser extends BikeCommonAccessParser { public BikeAccessParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "bike"))), + this(lookup.getBooleanEncodedValue(VehicleAccess.key("bike")), lookup.getBooleanEncodedValue(Roundabout.KEY)); blockPrivate(properties.getBool("block_private", true)); blockFords(properties.getBool("block_fords", false)); diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAverageSpeedParser.java index 53734484dd9..436c7936201 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeAverageSpeedParser.java @@ -1,12 +1,11 @@ package com.graphhopper.routing.util.parsers; import com.graphhopper.routing.ev.*; -import com.graphhopper.util.PMap; public class BikeAverageSpeedParser extends BikeCommonAverageSpeedParser { - public BikeAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "bike"))), + public BikeAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("bike")), lookup.getEnumEncodedValue(Smoothness.KEY, Smoothness.class), lookup.getDecimalEncodedValue(FerrySpeed.KEY)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/BikePriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/BikePriorityParser.java index 80d6a14e492..3c8266e323e 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/BikePriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/BikePriorityParser.java @@ -1,14 +1,13 @@ package com.graphhopper.routing.util.parsers; import com.graphhopper.routing.ev.*; -import com.graphhopper.util.PMap; public class BikePriorityParser extends BikeCommonPriorityParser { - public BikePriorityParser(EncodedValueLookup lookup, PMap properties) { + public BikePriorityParser(EncodedValueLookup lookup) { this( - lookup.getDecimalEncodedValue(VehiclePriority.key(properties.getString("name", "bike"))), - lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "bike"))), + lookup.getDecimalEncodedValue(VehiclePriority.key("bike")), + lookup.getDecimalEncodedValue(VehicleSpeed.key("bike")), lookup.getEnumEncodedValue(BikeNetwork.KEY, RouteNetwork.class) ); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/CarAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/CarAccessParser.java index e4832e5b170..7bf053d7990 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/CarAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/CarAccessParser.java @@ -34,7 +34,7 @@ public class CarAccessParser extends AbstractAccessParser implements TagParser { public CarAccessParser(EncodedValueLookup lookup, PMap properties) { this( - lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "car"))), + lookup.getBooleanEncodedValue(VehicleAccess.key("car")), lookup.getBooleanEncodedValue(Roundabout.KEY), properties, TransportationMode.CAR @@ -87,7 +87,7 @@ public WayAccess getAccess(ReaderWay way) { if (intendedValues.contains(firstValue) || // implied default is allowed only if foot and bicycle is not specified: firstValue.isEmpty() && !way.hasTag("foot") && !way.hasTag("bicycle") || - // if hgv is allowed than smaller trucks and cars are allowed too + // if hgv is allowed then smaller trucks and cars are allowed too way.hasTag("hgv", "yes")) return WayAccess.FERRY; } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/CarAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/CarAverageSpeedParser.java index 7262d02aca9..4ef43ed30ea 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/CarAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/CarAverageSpeedParser.java @@ -21,7 +21,6 @@ import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.FerrySpeedCalculator; import com.graphhopper.util.Helper; -import com.graphhopper.util.PMap; import java.util.HashMap; import java.util.HashSet; @@ -42,8 +41,8 @@ public class CarAverageSpeedParser extends AbstractAverageSpeedParser implements */ protected final Map defaultSpeedMap = new HashMap<>(); - public CarAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "car"))), + public CarAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("car")), lookup.getDecimalEncodedValue(FerrySpeed.KEY)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/FootAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/FootAccessParser.java index f52b64325b9..e2b87b8ac3a 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/FootAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/FootAccessParser.java @@ -37,7 +37,7 @@ public class FootAccessParser extends AbstractAccessParser implements TagParser protected Map routeMap = new HashMap<>(); public FootAccessParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "foot")))); + this(lookup.getBooleanEncodedValue(VehicleAccess.key("foot"))); blockPrivate(properties.getBool("block_private", true)); blockFords(properties.getBool("block_fords", false)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/FootAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/FootAverageSpeedParser.java index 9dd68d0e23d..0fb1942055d 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/FootAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/FootAverageSpeedParser.java @@ -3,7 +3,6 @@ import com.graphhopper.reader.ReaderWay; import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.FerrySpeedCalculator; -import com.graphhopper.util.PMap; import java.util.HashMap; import java.util.Map; @@ -16,8 +15,8 @@ public class FootAverageSpeedParser extends AbstractAverageSpeedParser implement static final int MEAN_SPEED = 5; protected Map routeMap = new HashMap<>(); - public FootAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "foot"))), + public FootAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("foot")), lookup.getDecimalEncodedValue(FerrySpeed.KEY)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/FootPriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/FootPriorityParser.java index fe7cd54bed2..abf3f840894 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/FootPriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/FootPriorityParser.java @@ -5,7 +5,6 @@ import com.graphhopper.routing.util.FerrySpeedCalculator; import com.graphhopper.routing.util.PriorityCode; import com.graphhopper.storage.IntsRef; -import com.graphhopper.util.PMap; import java.util.*; @@ -25,8 +24,8 @@ public class FootPriorityParser implements TagParser { protected EnumEncodedValue footRouteEnc; protected Map routeMap = new HashMap<>(); - public FootPriorityParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehiclePriority.key(properties.getString("name", "foot"))), + public FootPriorityParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehiclePriority.key("foot")), lookup.getEnumEncodedValue(FootNetwork.KEY, RouteNetwork.class) ); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java index ffa0672c005..64e855ec308 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java @@ -9,7 +9,7 @@ public class MountainBikeAccessParser extends BikeCommonAccessParser { public MountainBikeAccessParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "mtb"))), + this(lookup.getBooleanEncodedValue(VehicleAccess.key("mtb")), lookup.getBooleanEncodedValue(Roundabout.KEY)); blockPrivate(properties.getBool("block_private", true)); blockFords(properties.getBool("block_fords", false)); diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAverageSpeedParser.java index 4e060a729da..0c73a84b4c1 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAverageSpeedParser.java @@ -1,12 +1,11 @@ package com.graphhopper.routing.util.parsers; import com.graphhopper.routing.ev.*; -import com.graphhopper.util.PMap; public class MountainBikeAverageSpeedParser extends BikeCommonAverageSpeedParser { - public MountainBikeAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "mtb"))), + public MountainBikeAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("mtb")), lookup.getEnumEncodedValue(Smoothness.KEY, Smoothness.class), lookup.getDecimalEncodedValue(FerrySpeed.KEY)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java index d9687113480..f124c7d4d3c 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java @@ -3,7 +3,6 @@ import com.graphhopper.reader.ReaderWay; import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.PriorityCode; -import com.graphhopper.util.PMap; import java.util.TreeMap; @@ -12,9 +11,9 @@ public class MountainBikePriorityParser extends BikeCommonPriorityParser { - public MountainBikePriorityParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "mtb"))), - lookup.getDecimalEncodedValue(VehiclePriority.key(properties.getString("name", "mtb"))), + public MountainBikePriorityParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("mtb")), + lookup.getDecimalEncodedValue(VehiclePriority.key("mtb")), lookup.getEnumEncodedValue(BikeNetwork.KEY, RouteNetwork.class)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAccessParser.java index 5843c167e9d..6d0c34325b3 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAccessParser.java @@ -9,7 +9,7 @@ public class RacingBikeAccessParser extends BikeCommonAccessParser { public RacingBikeAccessParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "racingbike"))), + this(lookup.getBooleanEncodedValue(VehicleAccess.key("racingbike")), lookup.getBooleanEncodedValue(Roundabout.KEY)); blockPrivate(properties.getBool("block_private", true)); blockFords(properties.getBool("block_fords", false)); diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAverageSpeedParser.java index 8ac660b6027..dabc0f82aba 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikeAverageSpeedParser.java @@ -1,12 +1,11 @@ package com.graphhopper.routing.util.parsers; import com.graphhopper.routing.ev.*; -import com.graphhopper.util.PMap; public class RacingBikeAverageSpeedParser extends BikeCommonAverageSpeedParser { - public RacingBikeAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "racingbike"))), + public RacingBikeAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("racingbike")), lookup.getEnumEncodedValue(Smoothness.KEY, Smoothness.class), lookup.getDecimalEncodedValue(FerrySpeed.KEY)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java index 015bb712df4..9ead7ff7ea3 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java @@ -3,7 +3,6 @@ import com.graphhopper.reader.ReaderWay; import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.PriorityCode; -import com.graphhopper.util.PMap; import java.util.TreeMap; @@ -12,9 +11,9 @@ public class RacingBikePriorityParser extends BikeCommonPriorityParser { - public RacingBikePriorityParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehiclePriority.key(properties.getString("name", "racingbike"))), - lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "racingbike"))), + public RacingBikePriorityParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehiclePriority.key("racingbike")), + lookup.getDecimalEncodedValue(VehicleSpeed.key("racingbike")), lookup.getEnumEncodedValue(BikeNetwork.KEY, RouteNetwork.class)); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAccessParser.java index b73176e9472..e68a88bb171 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAccessParser.java @@ -6,7 +6,6 @@ import com.graphhopper.routing.ev.EncodedValueLookup; import com.graphhopper.routing.ev.VehicleAccess; import com.graphhopper.storage.IntsRef; -import com.graphhopper.util.PMap; /** * Access parser (boolean) for the 'roads' vehicle. Not to be confused with OSMRoadAccessParser that fills road_access @@ -15,8 +14,8 @@ public class RoadsAccessParser implements TagParser { private final BooleanEncodedValue accessEnc; - public RoadsAccessParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getBooleanEncodedValue(VehicleAccess.key(properties.getString("name", "roads")))); + public RoadsAccessParser(EncodedValueLookup lookup) { + this(lookup.getBooleanEncodedValue(VehicleAccess.key("roads"))); } public RoadsAccessParser(BooleanEncodedValue accessEnc) { diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAverageSpeedParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAverageSpeedParser.java index 9756c73f772..59b85b16dcc 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAverageSpeedParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/RoadsAverageSpeedParser.java @@ -2,18 +2,17 @@ import com.graphhopper.reader.ReaderWay; import com.graphhopper.routing.ev.DecimalEncodedValue; -import com.graphhopper.routing.ev.EncodedValueLookup; import com.graphhopper.routing.ev.EdgeIntAccess; +import com.graphhopper.routing.ev.EncodedValueLookup; import com.graphhopper.routing.ev.VehicleSpeed; import com.graphhopper.storage.IntsRef; -import com.graphhopper.util.PMap; public class RoadsAverageSpeedParser implements TagParser { private final DecimalEncodedValue avgSpeedEnc; private final double maxPossibleSpeed; - public RoadsAverageSpeedParser(EncodedValueLookup lookup, PMap properties) { - this(lookup.getDecimalEncodedValue(VehicleSpeed.key(properties.getString("name", "roads")))); + public RoadsAverageSpeedParser(EncodedValueLookup lookup) { + this(lookup.getDecimalEncodedValue(VehicleSpeed.key("roads"))); } public RoadsAverageSpeedParser(DecimalEncodedValue avgSpeedEnc) { diff --git a/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java b/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java index 7286f1cbcbf..5f98c2d4ada 100644 --- a/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java +++ b/core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java @@ -27,12 +27,14 @@ import com.graphhopper.reader.ReaderWay; import com.graphhopper.reader.dem.ElevationProvider; import com.graphhopper.reader.dem.SRTMProvider; -import com.graphhopper.reader.osm.conditional.DateRangeParser; import com.graphhopper.routing.OSMReaderConfig; import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.*; import com.graphhopper.routing.util.countryrules.CountryRuleFactory; -import com.graphhopper.routing.util.parsers.*; +import com.graphhopper.routing.util.parsers.CountryParser; +import com.graphhopper.routing.util.parsers.OSMBikeNetworkTagParser; +import com.graphhopper.routing.util.parsers.OSMMtbNetworkTagParser; +import com.graphhopper.routing.util.parsers.OSMRoadAccessParser; import com.graphhopper.storage.*; import com.graphhopper.storage.index.LocationIndex; import com.graphhopper.storage.index.Snap; @@ -696,35 +698,18 @@ public void testReadEleFromDataProvider() { @Test public void testTurnFlagCombination() { GraphHopper hopper = new GraphHopper(); - hopper.setVehicleEncodedValuesFactory((name, config) -> { - if (name.equals("truck")) { - return VehicleEncodedValues.car(new PMap(config).putObject("name", "truck")); - } else { - return new DefaultVehicleEncodedValuesFactory().createVehicleEncodedValues(name, config); - } - }); - hopper.setVehicleTagParserFactory((lookup, name, config) -> { - if (name.equals("truck")) { - return new VehicleTagParsers( - new CarAccessParser(lookup.getBooleanEncodedValue(VehicleAccess.key("truck")), lookup.getBooleanEncodedValue(Roundabout.KEY), config, TransportationMode.HGV) - .init(config.getObject("date_range_parser", new DateRangeParser())), - new CarAverageSpeedParser(lookup.getDecimalEncodedValue(VehicleSpeed.key("truck")), lookup.getDecimalEncodedValue(FerrySpeed.KEY)), - null - ); - } - return new DefaultVehicleTagParserFactory().createParsers(lookup, name, config); - }); hopper.setOSMFile(getClass().getResource("test-multi-profile-turn-restrictions.xml").getFile()). setGraphHopperLocation(dir). + setVehiclesString("roads|transportation_mode=HGV|turn_costs=true"). setProfiles( new Profile("bike").setVehicle("bike").setTurnCosts(true), new Profile("car").setVehicle("car").setTurnCosts(true), - new Profile("truck").setVehicle("truck").setTurnCosts(true) + new Profile("truck").setVehicle("roads").setTurnCosts(true) ). importOrLoad(); EncodingManager manager = hopper.getEncodingManager(); BooleanEncodedValue carTCEnc = manager.getTurnBooleanEncodedValue(TurnRestriction.key("car")); - BooleanEncodedValue truckTCEnc = manager.getTurnBooleanEncodedValue(TurnRestriction.key("truck")); + BooleanEncodedValue truckTCEnc = manager.getTurnBooleanEncodedValue(TurnRestriction.key("roads")); BooleanEncodedValue bikeTCEnc = manager.getTurnBooleanEncodedValue(TurnRestriction.key("bike")); Graph graph = hopper.getBaseGraph(); diff --git a/core/src/test/java/com/graphhopper/routing/TrafficChangeWithNodeOrderingReusingTest.java b/core/src/test/java/com/graphhopper/routing/TrafficChangeWithNodeOrderingReusingTest.java index ecbe98d9aee..7269e88fe5e 100644 --- a/core/src/test/java/com/graphhopper/routing/TrafficChangeWithNodeOrderingReusingTest.java +++ b/core/src/test/java/com/graphhopper/routing/TrafficChangeWithNodeOrderingReusingTest.java @@ -60,7 +60,7 @@ public Fixture(int maxDeviationPercentage) { BooleanEncodedValue accessEnc = VehicleAccess.create("car"); DecimalEncodedValue speedEnc = VehicleSpeed.create("car", 5, 5, false); em = EncodingManager.start().add(accessEnc).add(speedEnc).build(); - CarAverageSpeedParser carParser = new CarAverageSpeedParser(em, new PMap()); + CarAverageSpeedParser carParser = new CarAverageSpeedParser(em); osmParsers = new OSMParsers() .addWayTagParser(carParser); baseCHConfig = CHConfig.nodeBased("base", CustomModelParser.createFastestWeighting(accessEnc, speedEnc, em)); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/CarTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/CarTagParserTest.java index 6cb932e56d9..14b722696e1 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/CarTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/CarTagParserTest.java @@ -22,10 +22,8 @@ import com.graphhopper.reader.osm.conditional.DateRangeParser; import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.EncodingManager; -import com.graphhopper.routing.util.FerrySpeedCalculator; import com.graphhopper.routing.util.PriorityCode; import com.graphhopper.routing.util.WayAccess; -import com.graphhopper.storage.IntsRef; import com.graphhopper.util.Helper; import com.graphhopper.util.PMap; import org.junit.jupiter.api.Test; @@ -44,7 +42,7 @@ public class CarTagParserTest { private final EncodingManager em = createEncodingManager("car"); final CarAccessParser parser = createParser(em, new PMap("block_fords=true")); - final CarAverageSpeedParser speedParser = new CarAverageSpeedParser(em, new PMap("block_fords=true")); + final CarAverageSpeedParser speedParser = new CarAverageSpeedParser(em); private final BooleanEncodedValue roundaboutEnc = em.getBooleanEncodedValue(Roundabout.KEY); private final BooleanEncodedValue accessEnc = parser.getAccessEnc(); private final DecimalEncodedValue avSpeedEnc = speedParser.getAverageSpeedEnc(); @@ -610,7 +608,7 @@ public void testMaxValue() { .add(smallFactorSpeedEnc) .addTurnCostEncodedValue(TurnCost.create("car", 1)) .build(); - CarAverageSpeedParser speedParser = new CarAverageSpeedParser(em, new PMap()); + CarAverageSpeedParser speedParser = new CarAverageSpeedParser(em); ReaderWay way = new ReaderWay(1); way.setTag("highway", "motorway_link"); way.setTag("maxspeed", "60 mph"); @@ -692,7 +690,7 @@ public void testIssue_1256() { .add(lowFactorSpeedEnc) .build(); edgeIntAccess = new ArrayEdgeIntAccess(lowFactorEm.getIntsForFlags()); - new CarAverageSpeedParser(lowFactorEm, new PMap()).handleWayTags(edgeId, edgeIntAccess, way); + new CarAverageSpeedParser(lowFactorEm).handleWayTags(edgeId, edgeIntAccess, way); assertEquals(1, lowFactorSpeedEnc.getDecimal(false, edgeId, edgeIntAccess), .1); } diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java index ec2fb9bceef..becc43da25d 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/FootTagParserTest.java @@ -23,15 +23,16 @@ import com.graphhopper.routing.ev.*; import com.graphhopper.routing.util.AccessFilter; import com.graphhopper.routing.util.EncodingManager; -import com.graphhopper.routing.util.FerrySpeedCalculator; import com.graphhopper.routing.util.PriorityCode; import com.graphhopper.storage.BaseGraph; -import com.graphhopper.storage.IntsRef; import com.graphhopper.util.*; import org.junit.jupiter.api.Test; import java.text.DateFormat; -import java.util.*; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; import static com.graphhopper.routing.util.parsers.FootAverageSpeedParser.MEAN_SPEED; import static com.graphhopper.routing.util.parsers.FootAverageSpeedParser.SLOW_SPEED; @@ -54,8 +55,8 @@ public class FootTagParserTest { .add(carAccessEnc).add(carAvSpeedEnc) .build(); private final FootAccessParser accessParser = new FootAccessParser(encodingManager, new PMap()); - private final FootAverageSpeedParser speedParser = new FootAverageSpeedParser(encodingManager, new PMap()); - private final FootPriorityParser prioParser = new FootPriorityParser(encodingManager, new PMap()); + private final FootAverageSpeedParser speedParser = new FootAverageSpeedParser(encodingManager); + private final FootPriorityParser prioParser = new FootPriorityParser(encodingManager); public FootTagParserTest() { accessParser.init(new DateRangeParser()); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/HikeCustomModelTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/HikeCustomModelTest.java index 880bbcdc717..234f0a2576a 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/HikeCustomModelTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/HikeCustomModelTest.java @@ -14,7 +14,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.File; import java.io.InputStreamReader; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -39,7 +38,7 @@ public void setup() { for (TagParser p : VehicleTagParsers.foot(em, new PMap()).getTagParsers()) parsers.addWayTagParser(p); - for (TagParser p : VehicleTagParsers.roads(em, new PMap()).getTagParsers()) + for (TagParser p : VehicleTagParsers.roads(em).getTagParsers()) parsers.addWayTagParser(p); } diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java index 015d47977b6..a0ab5f29a2c 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java @@ -222,8 +222,8 @@ public void testPriority_avoidanceOfHighMaxSpeed() { .add(Smoothness.create()) .build(); List parsers = Arrays.asList( - new RacingBikeAverageSpeedParser(encodingManager, new PMap()), - new RacingBikePriorityParser(encodingManager, new PMap()) + new RacingBikeAverageSpeedParser(encodingManager), + new RacingBikePriorityParser(encodingManager) ); ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "tertiary"); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/RoadsTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/RoadsTagParserTest.java index bb68170c981..da394ece971 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/RoadsTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/RoadsTagParserTest.java @@ -17,7 +17,7 @@ class RoadsTagParserTest { private final RoadsAverageSpeedParser parser; public RoadsTagParserTest() { - parser = new RoadsAverageSpeedParser(encodingManager, new PMap()); + parser = new RoadsAverageSpeedParser(encodingManager); } @Test @@ -29,4 +29,4 @@ public void testSpeed() { assertTrue(encodingManager.getDecimalEncodedValue(VehicleSpeed.key("roads")).getDecimal(false, edgeId, edgeIntAccess) > 200); } -} \ No newline at end of file +} diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/TagParsingTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/TagParsingTest.java index 487dd396478..45b7087ea84 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/TagParsingTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/TagParsingTest.java @@ -55,8 +55,8 @@ public void testCombineRelations() { .add(bikeNetworkEnc) .add(Smoothness.create()) .build(); - BikePriorityParser bike1Parser = new BikePriorityParser(em, new PMap("name=bike1")); - BikePriorityParser bike2Parser = new BikePriorityParser(em, new PMap("name=bike2")) { + BikePriorityParser bike1Parser = new BikePriorityParser(bike1PriorityEnc, bike1SpeedEnc, bikeNetworkEnc); + BikePriorityParser bike2Parser = new BikePriorityParser(bike2PriorityEnc, bike2SpeedEnc, bikeNetworkEnc) { @Override public void handleWayTags(int edgeId, EdgeIntAccess intAccess, ReaderWay way, IntsRef relTags) { // accept less relations @@ -103,8 +103,8 @@ public void testMixBikeTypesAndRelationCombination() { .add(bikeNetworkEnc) .add(Smoothness.create()) .build(); - BikePriorityParser bikeTagParser = new BikePriorityParser(em, new PMap()); - MountainBikePriorityParser mtbTagParser = new MountainBikePriorityParser(em, new PMap()); + BikePriorityParser bikeTagParser = new BikePriorityParser(em); + MountainBikePriorityParser mtbTagParser = new MountainBikePriorityParser(em); OSMParsers osmParsers = new OSMParsers() .addRelationTagParser(relConfig -> new OSMBikeNetworkTagParser(bikeNetworkEnc, relConfig)) .addWayTagParser(new OSMRoadClassParser(em.getEnumEncodedValue(RoadClass.KEY, RoadClass.class))) @@ -176,4 +176,4 @@ public void testSharedEncodedValues() { assertTrue(accessEnc.getBool(false, edgeId, intAccess)); } -} \ No newline at end of file +}