Skip to content

Avoid frequent IllegalArgumentException - #3123

Merged
karussell merged 1 commit into
graphhopper:masterfrom
otbutz:state_lookup
Feb 19, 2025
Merged

karussell merged 1 commit into
graphhopper:masterfrom
otbutz:state_lookup

Conversation

@otbutz

@otbutz otbutz commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

A regular import of Germany creates an IllegalArgumentException for every way:

grafik

We can skip the entire try-catch if the ISO code doesn't contain a -

public static State find(String iso) {
try {
return State.valueOf(iso.replace('-', '_'));
} catch (IllegalArgumentException ex) {
return State.MISSING;
}
}

@karussell

Copy link
Copy Markdown
Member

Ok, thanks!

@karussell
karussell merged commit 3baa438 into graphhopper:master Feb 19, 2025
@karussell karussell added this to the 11.0 milestone Feb 19, 2025
Comment on lines +124 to +127
iso = iso.replace('-', '_');
if (iso.indexOf('_') == -1) {
return State.MISSING;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you first check if there is a '-' and then replace by '_'?

@karussell karussell Feb 19, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we then would have to check again for '_' in case of e.g. US_AL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that if the dataset is fully normalized and only contains - instead of _.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@easbar addressed in #3124

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we then would have to check again for '_' in case of e.g. US_AL.

Where do you expect iso="US_AL" to be coming from? There are no underscores in countries.geojson.

@otbutz
otbutz deleted the state_lookup branch February 19, 2025 13:46
@otbutz otbutz mentioned this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants