mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 19:38:49 +00:00
ParserUtils: add helper method to parse currency code
This commit is contained in:
parent
de2a0a614f
commit
fca02d58b3
3 changed files with 10 additions and 2 deletions
|
@ -3014,7 +3014,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
|||
return Currency.getInstance("USD");
|
||||
if (currencyStr.equals("Dirham"))
|
||||
return Currency.getInstance("AED");
|
||||
return Currency.getInstance(currencyStr);
|
||||
return ParserUtils.getCurrency(currencyStr);
|
||||
}
|
||||
|
||||
private static final Pattern P_POSITION = Pattern.compile(
|
||||
|
|
|
@ -785,7 +785,7 @@ public abstract class AbstractHafasClientInterfaceProvider extends AbstractHafas
|
|||
} else if (type.equals("F")) { // fare
|
||||
final String currencyStr = jsonFare.optString("cur");
|
||||
if (currencyStr != null) {
|
||||
final Currency currency = Currency.getInstance(currencyStr);
|
||||
final Currency currency = ParserUtils.getCurrency(currencyStr);
|
||||
final float price = jsonFare.getInt("prc") / 100f;
|
||||
fare = new Fare(normalizeFareName(fareName), normalizeFareType(fareName), currency,
|
||||
price, null, null);
|
||||
|
|
|
@ -303,4 +303,12 @@ public final class ParserUtils {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Currency getCurrency(final String code) {
|
||||
try {
|
||||
return Currency.getInstance(code);
|
||||
} catch (final IllegalArgumentException x) {
|
||||
throw new RuntimeException("unknown ISO 4217 code: " + code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue