From 8406e7b20a29c0fcbd3ceaef6cb687f6295c62ef Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 7 Jul 2019 19:43:13 +0200 Subject: [PATCH] Fix RouteStatisticsHelper --- .../osmand/router/RouteStatisticsHelper.java | 75 +++++++------------ 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteStatisticsHelper.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatisticsHelper.java index f82d9d00dc..2f7342704e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteStatisticsHelper.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatisticsHelper.java @@ -25,7 +25,8 @@ public class RouteStatisticsHelper { for (int i = 0; i < colorAttrNames.length; i++) { String colorAttrName = colorAttrNames[i]; - RouteStatisticComputer statisticComputer = new RoutePlainStatisticComputer(route, colorAttrName, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); + RouteStatisticComputer statisticComputer = + new RouteStatisticComputer(route, colorAttrName, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); result.add(statisticComputer.computeStatistic()); } @@ -38,7 +39,7 @@ public class RouteStatisticsHelper { int color; } - private abstract static class RouteStatisticComputer { + private static class RouteStatisticComputer { final List route; final String colorAttrName; @@ -58,21 +59,20 @@ public class RouteStatisticsHelper { this.defaultRenderingRuleSearchRequest = defaultRenderingRuleSearchRequest; } - Map> makePartition(List> routeAttributes) { - Map> partition = new TreeMap<>(); - for (RouteSegmentAttribute attribute : routeAttributes) { - E key = attribute.getAttribute(); - RouteSegmentAttribute pattr = partition.get(key); - if (pattr == null) { - pattr = new RouteSegmentAttribute<>(attribute); - partition.put(key, pattr); + Map makePartition(List routeAttributes) { + Map partition = new TreeMap<>(); + for (RouteSegmentAttribute attribute : routeAttributes) { + RouteSegmentAttribute attr = partition.get(attribute.propertyName); + if (attr == null) { + attr = new RouteSegmentAttribute(attribute); + partition.put(attribute.propertyName, attr); } - pattr.incrementDistanceBy(attribute.getDistance()); + attr.incrementDistanceBy(attribute.getDistance()); } return partition; } - private float computeTotalDistance(List> attributes) { + private float computeTotalDistance(List attributes) { float distance = 0f; for (RouteSegmentAttribute attribute : attributes) { distance += attribute.getDistance(); @@ -99,11 +99,11 @@ public class RouteStatisticsHelper { return routes; } - RouteStatistics computeStatistic() { - List> routeAttributes = processRoute(); - Map> partition = makePartition(routeAttributes); + RouteStatistics computeStatistic() { + List routeAttributes = processRoute(); + Map partition = makePartition(routeAttributes); float totalDistance = computeTotalDistance(routeAttributes); - return new RouteStatistics<>(routeAttributes, partition, totalDistance); + return new RouteStatistics(routeAttributes, partition, totalDistance); } RenderingRuleSearchRequest getSearchRequest(boolean useCurrentRenderer) { @@ -112,10 +112,10 @@ public class RouteStatisticsHelper { public RouteSegmentClass getAttribute(RouteSegmentResult segment) { RenderingRuleSearchRequest currentRequest = getSearchRequest(true); - RouteSegmentClass res = null; - + RouteSegmentClass res = new RouteSegmentClass(); + res.className = UNDEFINED_ATTR; if (searchRenderingAttribute(currentRenderer, currentRequest, segment)) { - res = new RouteSegmentClass(); + res.className = currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE); res.color = currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE); } else { @@ -153,29 +153,6 @@ public class RouteStatisticsHelper { } } - private static class RoutePlainStatisticComputer extends RouteStatisticComputer { - - public RoutePlainStatisticComputer(List route, String colorAttrName, - RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, - RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { - super(route, colorAttrName, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); - } - - - private String getAttributeType(String attribute) { - String type = null; - - return type == null ? UNDEFINED_ATTR : type; - } - - @Override - public String getPropertyName(String attribute) { - String type = getAttributeType(attribute); - return type != null ? type : attribute; - } - - } - private static class RouteBoundariesStatisticComputer extends RouteStatisticComputer { private final List inclines; @@ -436,14 +413,14 @@ public class RouteStatisticsHelper { } } - public static class RouteStatistics { + public static class RouteStatistics { - private final List> elements; - private final Map> partition; + private final List elements; + private final Map partition; private final float totalDistance; - private RouteStatistics(List> elements, - Map> partition, + private RouteStatistics(List elements, + Map partition, float totalDistance) { this.elements = elements; this.partition = partition; @@ -454,11 +431,11 @@ public class RouteStatisticsHelper { return totalDistance; } - public List> getElements() { + public List getElements() { return elements; } - public Map> getPartition() { + public Map getPartition() { return partition; } }