ParserUtils: extract hardcoded EUR currency into constant

This commit is contained in:
Andreas Schildbach 2021-10-17 22:09:13 +02:00
parent c6b63ce257
commit de2a0a614f
3 changed files with 9 additions and 7 deletions

View file

@ -23,7 +23,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
@ -497,9 +496,9 @@ public class NegentweeProvider extends AbstractNetworkProvider {
List<Fare> tripFares = null;
if (fareInfo.getBoolean("complete")) {
tripFares = Arrays.asList(
new Fare("Full-price", Fare.Type.ADULT, Currency.getInstance("EUR"),
new Fare("Full-price", Fare.Type.ADULT, ParserUtils.CURRENCY_EUR,
fareInfo.getInt("fullPriceCents") / 100, null, null),
new Fare("Reduced-price", Fare.Type.ADULT, Currency.getInstance("EUR"),
new Fare("Reduced-price", Fare.Type.ADULT, ParserUtils.CURRENCY_EUR,
fareInfo.getInt("reducedPriceCents") / 100, null, null));
}
@ -531,7 +530,7 @@ public class NegentweeProvider extends AbstractNetworkProvider {
}
}
return new Fare(fareLeg.getString("operatorString"), Fare.Type.ADULT, Currency.getInstance("EUR"), farePrice,
return new Fare(fareLeg.getString("operatorString"), Fare.Type.ADULT, ParserUtils.CURRENCY_EUR, farePrice,
null, null);
}

View file

@ -25,7 +25,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.EnumSet;
import java.util.GregorianCalendar;
@ -41,6 +40,7 @@ import java.util.regex.Pattern;
import javax.annotation.Nullable;
import de.schildbach.pte.util.ParserUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -865,11 +865,11 @@ public class VrsProvider extends AbstractNetworkProvider {
// "4"
if (name != null && price != 0.0 && level != null) {
fares.add(new Fare(name, Fare.Type.ADULT, Currency.getInstance("EUR"), price, level, null /* units */));
fares.add(new Fare(name, Fare.Type.ADULT, ParserUtils.CURRENCY_EUR, price, level, null /* units */));
} else if (name != null && name.equals("NRW-Tarif") && text != null) {
Matcher matcher = nrwTarifPattern.matcher(text);
if (matcher.find()) {
fares.add(new Fare(name, Fare.Type.ADULT, Currency.getInstance("EUR"),
fares.add(new Fare(name, Fare.Type.ADULT, ParserUtils.CURRENCY_EUR,
Float.parseFloat(matcher.group(0).replace(",", ".")), null /* level */, null /* units */));
}
}

View file

@ -24,6 +24,7 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
@ -40,6 +41,8 @@ public final class ParserUtils {
private static final Pattern P_HTML_BREAKS = Pattern.compile("(<br\\s*/>)+",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
public static final Currency CURRENCY_EUR = Currency.getInstance("EUR");
public static String formatHtml(final CharSequence html) {
if (html == null)
return null;