< Summary

Class:Itinero.Profiles.RouterDbProfileConfiguration
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Profiles/RouterDbProfileConfiguration.cs
Covered lines:12
Uncovered lines:24
Coverable lines:36
Total lines:67
Line coverage:33.3% (12 of 36)
Covered branches:1
Total branches:6
Branch coverage:16.6% (1 of 6)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
GetProfileNames()100%10%
HasProfile(...)100%10%
AddProfiles(...)0%20%
TryGetProfileHandlerEdgeTypesCache(...)50%270%
UpdateEdgeTypeMap()0%20%
get_Profiles()100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Profiles/RouterDbProfileConfiguration.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using Itinero.Profiles.EdgeTypesMap;
 4using Itinero.Routing.Costs.Caches;
 5
 6namespace Itinero.Profiles;
 7
 8internal class RouterDbProfileConfiguration
 9{
 10    private readonly Dictionary<string, (Profile profile, EdgeFactorCache cache, TurnCostFactorCache turnCostFactorCache
 11    private readonly RouterDb _routerDb;
 12
 15213    public RouterDbProfileConfiguration(RouterDb routerDb)
 15214    {
 15215        _routerDb = routerDb;
 15216        _profiles = new Dictionary<string, (Profile profile, EdgeFactorCache cache, TurnCostFactorCache turnCostFactorCa
 15217    }
 18
 19    internal IEnumerable<string> GetProfileNames()
 020    {
 021        return _profiles.Keys.ToList();
 022    }
 23
 24    internal bool HasProfile(string name)
 025    {
 026        return _profiles.ContainsKey(name);
 027    }
 28
 29    public void AddProfiles(IEnumerable<Profile> profiles)
 030    {
 031        foreach (var profile in profiles)
 032        {
 033            _profiles[profile.Name] = (profile, new EdgeFactorCache(), new TurnCostFactorCache());
 034        }
 35
 036        this.UpdateEdgeTypeMap();
 037    }
 38
 39    internal bool TryGetProfileHandlerEdgeTypesCache(string profileName, out EdgeFactorCache? cache, out TurnCostFactorC
 4740    {
 4741        cache = null;
 4742        turnCostFactorCache = null;
 4743        if (!_profiles.TryGetValue(profileName, out var profileValue))
 4744        {
 4745            return false;
 46        }
 47
 048        cache = profileValue.cache;
 049        turnCostFactorCache = profileValue.turnCostFactorCache;
 050        return true;
 4751    }
 52
 53    private void UpdateEdgeTypeMap()
 054    {
 55        // only update the edge type map when it is based on the active profiles.
 056        if (_routerDb.EdgeTypeMap is not ProfilesEdgeTypeMap)
 057        {
 058            return;
 59        }
 60
 61        // update edge type map to include the new profile(s).
 062        var edgeTypeMap = new ProfilesEdgeTypeMap(_profiles.Values.Select(x => x.profile));
 063        _routerDb.EdgeTypeMap = edgeTypeMap;
 064    }
 65
 066    public IEnumerable<Profile> Profiles => _profiles.Values.Select(x => x.profile);
 67}