Skip to content

Commit

Permalink
Explicitly map internal voice hint ids to external JSON API ids
Browse files Browse the repository at this point in the history
As c9ae7c8 showed, changing internal ids without being aware of the
possible impact might easily lead to break the external API.

While ids could be fixated by adding respective tests, an even more
elegant solution is to make the mapping from internal ids to external
ids explicit, similar how it is already done for other voice hint
formats.

To underline the purpose of the mapping even more, the
respective method is renamed appropriately.

Test Plan:
  - `./gradlew test`
  - Export a complex route in BRouter-Web and check voice hints have not
  been changed.
  • Loading branch information
rkflx committed Jul 12, 2023
1 parent 82fecf9 commit d98b106
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/OsmTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ public String formatAsGeoJson() {
for (VoiceHint hint : voiceHints.list) {
sb.append(" [");
sb.append(hint.indexInTrack);
sb.append(',').append(hint.getCommand());
sb.append(',').append(hint.getJsonCommandIndex());
sb.append(',').append(hint.getExitNumber());
sb.append(',').append(hint.distanceToNext);
sb.append(',').append((int) hint.angle);
Expand Down
39 changes: 37 additions & 2 deletions brouter-core/src/main/java/btools/router/VoiceHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,43 @@ public void addBadWay(MessageData badWay) {
badWays.add(badWay);
}

public int getCommand() {
return cmd;
public int getJsonCommandIndex() {
switch (cmd) {
case TLU:
return 10;
case TU:
return 15;
case TSHL:
return 4;
case TL:
return 2;
case TSLL:
return 3;
case KL:
return 8;
case C:
return 1;
case KR:
return 9;
case TSLR:
return 6;
case TR:
return 5;
case TSHR:
return 7;
case TRU:
return 11;
case RNDB:
return 13;
case RNLB:
return 14;
case BL:
return 16;
case OFFR:
return 12;
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
}

public int getExitNumber() {
Expand Down

0 comments on commit d98b106

Please sign in to comment.