From 7f5bc33e283971aab856fcde8cf8ee07c2f4f9cd Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 19 Jul 2024 15:25:40 +0200 Subject: [PATCH 1/3] Add parsing of 'any' --- .../opentripplanner/netex/support/NetexVersionHelper.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java index 4e6cf4967c0..448d73a5f75 100644 --- a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java +++ b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java @@ -26,7 +26,11 @@ private NetexVersionHelper() {} * increasing integer. A bigger value indicate a later version. */ public static int versionOf(EntityInVersionStructure e) { - return Integer.parseInt(e.getVersion()); + if(e.getVersion().equals("any")){ + return 1; + } else{ + return Integer.parseInt(e.getVersion()); + } } /** From 85b9ec04de722407a55e1380748ed3ae7ad4c549 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 23 Jul 2024 19:53:53 +0200 Subject: [PATCH 2/3] Implement NeTEx version 'any' --- .../netex/support/NetexVersionHelper.java | 13 ++++++++----- .../netex/support/NetexVersionHelperTest.java | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java index 448d73a5f75..6ede322dfba 100644 --- a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java +++ b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java @@ -16,6 +16,9 @@ */ public class NetexVersionHelper { + private static final String ANY = "any"; + private static final int UNKNOWN_VERSION = -1; + /** * private constructor to prevent instantiation of utility class */ @@ -23,12 +26,12 @@ private NetexVersionHelper() {} /** * According to the Norwegian Netex profile the version number must be a positive - * increasing integer. A bigger value indicate a later version. + * increasing integer. A bigger value indicates a later version. */ public static int versionOf(EntityInVersionStructure e) { - if(e.getVersion().equals("any")){ - return 1; - } else{ + if (e.getVersion().equals(ANY)) { + return UNKNOWN_VERSION; + } else { return Integer.parseInt(e.getVersion()); } } @@ -38,7 +41,7 @@ public static int versionOf(EntityInVersionStructure e) { * elements exist in the collection {@code -1} is returned. */ public static int latestVersionIn(Collection list) { - return list.stream().mapToInt(NetexVersionHelper::versionOf).max().orElse(-1); + return list.stream().mapToInt(NetexVersionHelper::versionOf).max().orElse(UNKNOWN_VERSION); } /** diff --git a/src/test/java/org/opentripplanner/netex/support/NetexVersionHelperTest.java b/src/test/java/org/opentripplanner/netex/support/NetexVersionHelperTest.java index d55b573a5d5..1374d871154 100644 --- a/src/test/java/org/opentripplanner/netex/support/NetexVersionHelperTest.java +++ b/src/test/java/org/opentripplanner/netex/support/NetexVersionHelperTest.java @@ -19,32 +19,39 @@ import org.rutebanken.netex.model.EntityInVersionStructure; import org.rutebanken.netex.model.ValidBetween; -public class NetexVersionHelperTest { +class NetexVersionHelperTest { private static final EntityInVersionStructure E_VER_1 = new EntityInVersionStructure() .withVersion("1"); private static final EntityInVersionStructure E_VER_2 = new EntityInVersionStructure() .withVersion("2"); + private static final EntityInVersionStructure E_VER_ANY = new EntityInVersionStructure() + .withVersion("any"); @Test - public void versionOfTest() { + void versionOfTest() { assertEquals(1, versionOf(E_VER_1)); } @Test - public void latestVersionInTest() { + void any() { + assertEquals(-1, versionOf(E_VER_ANY)); + } + + @Test + void latestVersionInTest() { assertEquals(2, latestVersionIn(Arrays.asList(E_VER_1, E_VER_2))); assertEquals(-1, latestVersionIn(Collections.emptyList())); } @Test - public void lastestVersionedElementInTest() { + void lastestVersionedElementInTest() { assertEquals(E_VER_2, latestVersionedElementIn(Arrays.asList(E_VER_1, E_VER_2))); assertNull(latestVersionedElementIn(Collections.emptyList())); } @Test - public void comparingVersionTest() { + void comparingVersionTest() { // Given a comparator (subject under test) Comparator subject = comparingVersion(); // And a entity with version as the E_VER_1 entity @@ -62,7 +69,7 @@ public void comparingVersionTest() { } @Test - public void testFirstRelevantDateTime() { + void testFirstRelevantDateTime() { var may1st = LocalDateTime.of(2021, MAY, 1, 14, 0); var may2nd = LocalDateTime.of(2021, MAY, 2, 14, 0); var may3rd = LocalDateTime.of(2021, MAY, 3, 14, 0); From d71fcc11c07a137adc1a41401b608bb6f14a251b Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 23 Jul 2024 20:25:20 +0200 Subject: [PATCH 3/3] Add documentation --- .../netex/support/NetexVersionHelper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java index 6ede322dfba..8f7a7f14913 100644 --- a/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java +++ b/src/main/java/org/opentripplanner/netex/support/NetexVersionHelper.java @@ -16,7 +16,13 @@ */ public class NetexVersionHelper { + /** + * @see NetexVersionHelper#versionOf(EntityInVersionStructure) + */ private static final String ANY = "any"; + /** + * A special value that represents an unknown version. + */ private static final int UNKNOWN_VERSION = -1; /** @@ -27,6 +33,11 @@ private NetexVersionHelper() {} /** * According to the Norwegian Netex profile the version number must be a positive * increasing integer. A bigger value indicates a later version. + * However, the special value "any" is also supported and returns a constant meaning "unknown". + * The EPIP profile at + * http://netex.uk/netex/doc/2019.05.07-v1.1_FinalDraft/prCEN_TS_16614-PI_Profile_FV_%28E%29-2019-Final-Draft-v3.pdf (page 33) + * defines this as follows: "Use "any" if the VERSION is unknown (note that this will trigger NeTEx's + * XML automatic consistency check)." */ public static int versionOf(EntityInVersionStructure e) { if (e.getVersion().equals(ANY)) {