From 36752263045bf0e93afd93359f63f94ac33c57a4 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Wed, 27 Mar 2024 16:48:14 +0100 Subject: [PATCH] Improve documentation --- docs/BuildConfiguration.md | 10 ++++++++- .../module/osm/naming/SidewalkNamer.java | 8 +------ .../graph_builder/services/osm/EdgeNamer.java | 21 +++++++++++-------- .../services/osm/EdgeNamerTest.java | 12 +++++++++++ 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 src/test/java/org/opentripplanner/graph_builder/services/osm/EdgeNamerTest.java diff --git a/docs/BuildConfiguration.md b/docs/BuildConfiguration.md index c993016160f..a95421e47f7 100644 --- a/docs/BuildConfiguration.md +++ b/docs/BuildConfiguration.md @@ -35,7 +35,7 @@ Sections follow that describe particular settings in more depth. | maxTransferDuration | `duration` | Transfers up to this duration with the default walk speed value will be pre-calculated and included in the Graph. | *Optional* | `"PT30M"` | 2.1 | | [multiThreadElevationCalculations](#multiThreadElevationCalculations) | `boolean` | Configuring multi-threading during elevation calculations. | *Optional* | `false` | 2.0 | | [osmCacheDataInMem](#osmCacheDataInMem) | `boolean` | If OSM data should be cached in memory during processing. | *Optional* | `false` | 2.0 | -| osmNaming | `string` | A custom OSM namer to use. | *Optional* | | 1.5 | +| [osmNaming](#osmNaming) | `enum` | A custom OSM namer to use. | *Optional* | `"none"` | 1.5 | | platformEntriesLinking | `boolean` | Link unconnected entries to public transport platforms. | *Optional* | `false` | 2.0 | | [readCachedElevations](#readCachedElevations) | `boolean` | Whether to read cached elevation data. | *Optional* | `true` | 2.0 | | staticBikeParkAndRide | `boolean` | Whether we should create bike P+R stations from OSM data. | *Optional* | `false` | 1.5 | @@ -536,6 +536,14 @@ deployment depending on your infrastructure. Set the parameter to `true` to cach data, and to `false` to read the stream from the source each time. +

osmNaming

+ +**Since version:** `1.5` ∙ **Type:** `enum` ∙ **Cardinality:** `Optional` ∙ **Default value:** `"none"` +**Path:** / +**Enum values:** `none` | `portland` | `sidewalks` + +A custom OSM namer to use. +

readCachedElevations

**Since version:** `2.0` ∙ **Type:** `boolean` ∙ **Cardinality:** `Optional` ∙ **Default value:** `true` diff --git a/src/main/java/org/opentripplanner/graph_builder/module/osm/naming/SidewalkNamer.java b/src/main/java/org/opentripplanner/graph_builder/module/osm/naming/SidewalkNamer.java index 8c03eacbd67..41e4fa09482 100644 --- a/src/main/java/org/opentripplanner/graph_builder/module/osm/naming/SidewalkNamer.java +++ b/src/main/java/org/opentripplanner/graph_builder/module/osm/naming/SidewalkNamer.java @@ -119,13 +119,7 @@ public void postprocess() { .max(Comparator.comparingDouble(NamedEdgeGroup::percentInBuffer)) .ifPresent(group -> { namesApplied.incrementAndGet(); - var name = group.name.toString(); - - sidewalk.setName( - Objects.requireNonNull( - I18NString.of("%s, Percent in buffer: %s".formatted(name, group.percentInBuffer)) - ) - ); + sidewalk.setName(Objects.requireNonNull(group.name)); }); //Keep lambda! A method-ref would cause incorrect class and line number to be logged diff --git a/src/main/java/org/opentripplanner/graph_builder/services/osm/EdgeNamer.java b/src/main/java/org/opentripplanner/graph_builder/services/osm/EdgeNamer.java index 2733e705c70..249557ba1fe 100644 --- a/src/main/java/org/opentripplanner/graph_builder/services/osm/EdgeNamer.java +++ b/src/main/java/org/opentripplanner/graph_builder/services/osm/EdgeNamer.java @@ -52,25 +52,28 @@ public static EdgeNamer fromConfig(NodeAdapter root, String parameterName) { .of(parameterName) .summary("A custom OSM namer to use.") .since(OtpVersion.V1_5) - .asString(null); + .asEnum(EdgeNamerType.NONE); return fromConfig(osmNaming); } /** * Create a custom namer if needed, return null if not found / by default. */ - public static EdgeNamer fromConfig(String type) { - if (type == null) { + public static EdgeNamer fromConfig(EdgeNamerType type) { + if(type == null{ return new DefaultNamer(); } - return switch (type) { - case "portland" -> new PortlandCustomNamer(); - case "sidewalks" -> new SidewalkNamer(); - default -> throw new IllegalArgumentException( - String.format("Unknown osmNaming type: '%s'", type) - ); + case PORTLAND -> new PortlandCustomNamer(); + case SIDEWALKS -> new SidewalkNamer(); + case NONE -> new DefaultNamer(); }; } } + + enum EdgeNamerType { + NONE, + PORTLAND, + SIDEWALKS, + } } diff --git a/src/test/java/org/opentripplanner/graph_builder/services/osm/EdgeNamerTest.java b/src/test/java/org/opentripplanner/graph_builder/services/osm/EdgeNamerTest.java new file mode 100644 index 00000000000..70e9dbbc198 --- /dev/null +++ b/src/test/java/org/opentripplanner/graph_builder/services/osm/EdgeNamerTest.java @@ -0,0 +1,12 @@ +package org.opentripplanner.graph_builder.services.osm; + +import org.junit.jupiter.api.Test; + +class EdgeNamerTest { + + @Test + void nullType(){ + var namer = EdgeNamer.EdgeNamerFactory.fromConfig(null); + } + +} \ No newline at end of file