com.graphhopper.util.CustomModel Maven / Gradle / Ivy
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.util;
import com.graphhopper.json.Statement;
import java.util.*;
/**
* This class is used in combination with CustomProfile.
*/
public class CustomModel {
public static final String KEY = "custom_model";
// e.g. 70 means that the time costs are 25€/hour and for the distance 0.5€/km (for trucks this is usually larger)
static double DEFAULT_DISTANCE_INFLUENCE = 70;
private Double distanceInfluence;
private double headingPenalty = Parameters.Routing.DEFAULT_HEADING_PENALTY;
private boolean internal;
private List speedStatements = new ArrayList<>();
private List priorityStatements = new ArrayList<>();
private Map areas = new HashMap<>();
public CustomModel() {
}
public CustomModel(CustomModel toCopy) {
this.headingPenalty = toCopy.headingPenalty;
this.distanceInfluence = toCopy.distanceInfluence;
// do not copy "internal"
speedStatements = deepCopy(toCopy.getSpeed());
priorityStatements = deepCopy(toCopy.getPriority());
areas.putAll(toCopy.getAreas());
}
/**
* This method is for internal usage only! Parsing a CustomModel is expensive and so we cache the result, which is
* especially important for fast landmark queries (hybrid mode). Now this method ensures that all server-side custom
* models are cached in a special internal cache which does not remove seldom accessed entries.
*/
public CustomModel internal() {
this.internal = true;
return this;
}
public boolean isInternal() {
return internal;
}
private T deepCopy(T originalObject) {
if (originalObject instanceof List) {
List