source: josm/trunk/src/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProvider.java@ 17534

Last change on this file since 17534 was 16665, checked in by simon04, 4 years ago

see #19397 - JosmDecimalFormatSymbolsProvider: exclude Locale.ROOT

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.text.DecimalFormatSymbols;
5import java.text.spi.DecimalFormatSymbolsProvider;
6import java.util.Locale;
7import java.util.function.Function;
8import java.util.stream.Stream;
9
10/**
11 * JOSM implementation of the {@link java.text.DecimalFormatSymbols DecimalFormatSymbols} class,
12 * consistent with ISO 80000-1.
13 * This class will only be used with Java 9 and later runtimes, as Java 8 implementation relies
14 * on Java Extension Mechanism only, while Java 9 supports application classpath.
15 * See {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider} javadoc for more details.
16 * @since 12931
17 */
18public class JosmDecimalFormatSymbolsProvider extends DecimalFormatSymbolsProvider {
19
20 @Override
21 public DecimalFormatSymbols getInstance(Locale locale) {
22 DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
23 // Override digit group separator to be consistent across languages with ISO 80000-1, chapter 7.3.1
24 symbols.setGroupingSeparator('\u202F'); // U+202F: NARROW NO-BREAK SPACE
25 return symbols;
26 }
27
28 @Override
29 public Locale[] getAvailableLocales() {
30 return Stream.of(
31 Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")),
32 Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, "")),
33 I18n.getAvailableTranslations()
34 ).flatMap(Function.identity()).toArray(Locale[]::new);
35 }
36
37 /**
38 * Returns a new {@code double} initialized to the value represented by the specified {@code String},
39 * allowing both dot and comma decimal separators.
40 *
41 * @param s the string to be parsed.
42 * @return the {@code double} value represented by the string argument.
43 * @throws NullPointerException if the string is null
44 * @throws NumberFormatException if the string does not contain a parsable {@code double}.
45 * @see Double#parseDouble(String)
46 * @since 13050
47 */
48 public static double parseDouble(String s) {
49 return Double.parseDouble(s.replace(',', '.'));
50 }
51}
Note: See TracBrowser for help on using the repository browser.