Skip to content

Commit

Permalink
Remove the name property from vehicle parsers (graphhopper#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar authored Jan 19, 2024
1 parent ddb0471 commit 1046bae
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 113 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ protected OSMParsers buildOSMParsers(Map<String, String> vehiclesByName, List<St
if (encodingManager.hasEncodedValue(FootNetwork.KEY) && added.add(FootNetwork.KEY))
osmParsers.addRelationTagParser(relConfig -> 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))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,51 @@ 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
);
}

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
);
}

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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,8 +41,8 @@ public class CarAverageSpeedParser extends AbstractAverageSpeedParser implements
*/
protected final Map<String, Integer> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FootAccessParser extends AbstractAccessParser implements TagParser
protected Map<RouteNetwork, Integer> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,8 +15,8 @@ public class FootAverageSpeedParser extends AbstractAverageSpeedParser implement
static final int MEAN_SPEED = 5;
protected Map<RouteNetwork, Integer> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -25,8 +24,8 @@ public class FootPriorityParser implements TagParser {
protected EnumEncodedValue<RouteNetwork> footRouteEnc;
protected Map<RouteNetwork, Integer> 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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 1046bae

Please sign in to comment.