com.graphhopper.config.TurnCostsConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphhopper-core Show documentation
Show all versions of graphhopper-core Show documentation
GraphHopper is a fast and memory efficient Java road routing engine
working seamlessly with OpenStreetMap data.
package com.graphhopper.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Set;
public class TurnCostsConfig {
public static final int INFINITE_U_TURN_COSTS = -1;
private int uTurnCosts = INFINITE_U_TURN_COSTS;
private List vehicleTypes;
// ensure that no typos can occur like motor_car vs motorcar or bike vs bicycle
private static final Set ALL_SUPPORTED = Set.of(
"agricultural", "atv", "auto_rickshaw",
"bdouble", "bicycle", "bus", "caravan", "carpool", "coach", "delivery", "destination",
"emergency", "foot", "golf_cart", "goods", "hazmat", "hgv", "hgv:trailer", "hov",
"minibus", "mofa", "moped", "motorcar", "motorcycle", "motor_vehicle", "motorhome",
"nev", "ohv", "psv", "residents",
"share_taxi", "small_electric_vehicle", "speed_pedelec",
"taxi", "trailer", "tourist_bus");
public static TurnCostsConfig car() {
return new TurnCostsConfig(List.of("motorcar", "motor_vehicle"));
}
public static TurnCostsConfig bike() {
return new TurnCostsConfig(List.of("bicycle"));
}
// jackson
public TurnCostsConfig() {
}
public TurnCostsConfig(List vehicleTypes) {
this.vehicleTypes = check(vehicleTypes);
}
public TurnCostsConfig(List vehicleTypes, int uTurnCost) {
this.vehicleTypes = check(vehicleTypes);
this.uTurnCosts = uTurnCost;
}
public void setVehicleTypes(List vehicleTypes) {
this.vehicleTypes = check(vehicleTypes);
}
List check(List restrictions) {
if (restrictions == null || restrictions.isEmpty())
throw new IllegalArgumentException("turn_costs cannot have empty vehicle_types");
for (String r : restrictions) {
if (!ALL_SUPPORTED.contains(r))
throw new IllegalArgumentException("Currently we do not support the restriction: " + r);
}
return restrictions;
}
@JsonProperty("vehicle_types")
public List getVehicleTypes() {
check(vehicleTypes);
return vehicleTypes;
}
public TurnCostsConfig setUTurnCosts(int uTurnCosts) {
this.uTurnCosts = uTurnCosts;
return this;
}
@JsonProperty("u_turn_costs")
public int getUTurnCosts() {
return uTurnCosts;
}
@Override
public String toString() {
return "vehicleTypes=" + vehicleTypes + ", uTurnCosts=" + uTurnCosts;
}
}