4141import org .mtransit .parser .mt .data .MDirection ;
4242import org .mtransit .parser .mt .data .MString ;
4343import org .mtransit .parser .mt .data .MStrings ;
44+ import org .mtransit .parser .mt .data .MVerify ;
4445
4546import java .text .SimpleDateFormat ;
4647import java .util .ArrayList ;
4748import java .util .Arrays ;
4849import java .util .Calendar ;
4950import java .util .Collections ;
51+ import java .util .HashMap ;
5052import java .util .HashSet ;
5153import java .util .List ;
5254import java .util .Locale ;
@@ -180,6 +182,7 @@ public void start(@NotNull String[] args) {
180182 return ; // DEBUG
181183 }
182184 MGenerator .dumpFiles (this , mSpec , args [0 ], args [1 ], args [2 ], inputUrl , false );
185+ MVerify .verify (mSpec , this ); // after dump files to have all values
183186 MTLog .log ("Generating data... DONE in %s." , Utils .getPrettyDuration (System .currentTimeMillis () - start ));
184187 }
185188
@@ -351,10 +354,14 @@ public boolean excludeAgency(@NotNull GAgency gAgency) {
351354 return KEEP ;
352355 }
353356
357+ private final Map <String , String > serviceIdToCleanupServiceId = new HashMap <>();
358+
354359 @ NotNull
355360 @ Override
356361 public String cleanServiceId (@ NotNull String gServiceId ) {
357- return GTFSCommons .cleanOriginalId (gServiceId , getServiceIdCleanupPattern ());
362+ final String cleanServiceId = GTFSCommons .cleanOriginalId (gServiceId , getServiceIdCleanupPattern ());
363+ serviceIdToCleanupServiceId .put (gServiceId , cleanServiceId );
364+ return cleanServiceId ;
358365 }
359366
360367 @ Nullable
@@ -379,13 +386,30 @@ public String getServiceIdCleanupRegex() {
379386 return this .serviceIdCleanupPattern ;
380387 }
381388
389+ @ Override
390+ public boolean verifyServiceIdsUniqueness () {
391+ if (Configs .getAgencyConfig () != null ) {
392+ if (Configs .getAgencyConfig ().getServiceIdNotUniqueAllowed ()) return false ;
393+ }
394+ return getServiceIdCleanupRegex () != null ; // OPT-IN feature
395+ }
396+
397+ @ NotNull
398+ public Map <String , String > getServiceIdToCleanupServiceId () {
399+ return serviceIdToCleanupServiceId ;
400+ }
401+
402+ private final Map <String , String > routeIdToCleanupRouteId = new HashMap <>();
403+
382404 @ NotNull
383405 @ Override
384406 public String cleanRouteOriginalId (@ NotNull String gRouteId ) {
385407 if (Configs .getRouteConfig ().getRouteIdCleanMerged ()) {
386408 gRouteId = CleanUtils .cleanMergedID (gRouteId );
387409 }
388- return GTFSCommons .cleanOriginalId (gRouteId , getRouteIdCleanupPattern ());
410+ final String cleanRouteId = GTFSCommons .cleanOriginalId (gRouteId , getRouteIdCleanupPattern ());
411+ this .routeIdToCleanupRouteId .put (gRouteId , cleanRouteId );
412+ return cleanRouteId ;
389413 }
390414
391415 @ Override
@@ -449,6 +473,17 @@ public String getRouteIdCleanupRegex() {
449473 return Configs .getRouteConfig ().getRouteIdCleanupRegex ();
450474 }
451475
476+ @ Override
477+ public boolean verifyRouteIdsUniqueness () {
478+ if (Configs .getRouteConfig ().getRouteIdNotUniqueAllowed ()) return false ;
479+ return getRouteIdCleanupRegex () != null ; // OPT-IN feature
480+ }
481+
482+ @ NotNull
483+ public Map <String , String > getRouteIdToCleanupRouteId () {
484+ return this .routeIdToCleanupRouteId ;
485+ }
486+
452487 @ Nullable
453488 private Pattern routeIdCleanupPattern = null ;
454489
@@ -657,6 +692,17 @@ public String getTripIdCleanupRegex() {
657692 return Configs .getRouteConfig ().getTripIdCleanupRegex ();
658693 }
659694
695+ @ Override
696+ public boolean verifyTripIdsUniqueness () {
697+ if (Configs .getRouteConfig ().getTripIdNotUniqueAllowed ()) return false ;
698+ return getTripIdCleanupRegex () != null ; // OPT-IN feature
699+ }
700+
701+ @ NotNull
702+ public Map <String , String > getTripIdToCleanupTripId () {
703+ return this .tripIdToCleanupTripId ;
704+ }
705+
660706 @ Nullable
661707 private Pattern tripIdCleanupPattern = null ;
662708
@@ -671,9 +717,13 @@ private Pattern getTripIdCleanupPattern() {
671717 return this .tripIdCleanupPattern ;
672718 }
673719
720+ private final Map <String , String > tripIdToCleanupTripId = new HashMap <>();
721+
674722 @ Override
675723 public @ NotNull String cleanTripOriginalId (@ NotNull String gTripId ) {
676- return GTFSCommons .cleanOriginalId (gTripId , getTripIdCleanupPattern ());
724+ final String cleanTripId = GTFSCommons .cleanOriginalId (gTripId , getTripIdCleanupPattern ());
725+ this .tripIdToCleanupTripId .put (gTripId , cleanTripId );
726+ return cleanTripId ;
677727 }
678728
679729 @ Override
@@ -1035,6 +1085,17 @@ public boolean useStopCodeForStopId() {
10351085 return Configs .getRouteConfig ().getStopIdCleanupRegex ();
10361086 }
10371087
1088+ @ Override
1089+ public boolean verifyStopIdsUniqueness () {
1090+ if (Configs .getRouteConfig ().getStopIdNotUniqueAllowed ()) return false ;
1091+ return getStopIdCleanupRegex () != null ; // OPT-IN feature
1092+ }
1093+
1094+ @ NotNull
1095+ public Map <String , String > getStopIdToCleanupStopId () {
1096+ return this .stopIdToCleanupStopId ;
1097+ }
1098+
10381099 @ Nullable
10391100 private Pattern stopIdCleanupPattern = null ;
10401101
@@ -1049,10 +1110,14 @@ private Pattern getStopIdCleanupPattern() {
10491110 return this .stopIdCleanupPattern ;
10501111 }
10511112
1113+ private final Map <String , String > stopIdToCleanupStopId = new HashMap <>();
1114+
10521115 @ NotNull
10531116 @ Override
10541117 public String cleanStopOriginalId (@ NotNull String gStopId ) {
1055- return GTFSCommons .cleanOriginalId (gStopId , getStopIdCleanupPattern ());
1118+ final String cleanStopId = GTFSCommons .cleanOriginalId (gStopId , getStopIdCleanupPattern ());
1119+ this .stopIdToCleanupStopId .put (gStopId , cleanStopId );
1120+ return cleanStopId ;
10561121 }
10571122
10581123 @ Override
0 commit comments