Skip to content

Commit 2acf6e2

Browse files
committed
tiny post-treatment
1 parent 350bd5c commit 2acf6e2

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

core/src/main/java/net/time4j/PrettyTime.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ public final class PrettyTime {
8888

8989
static {
9090
NumberSymbolProvider p = null;
91+
int count = 0;
9192

9293
for (NumberSymbolProvider tmp : ResourceLoader.getInstance().services(NumberSymbolProvider.class)) {
93-
p = tmp;
94-
break;
94+
int size = tmp.getAvailableLocales().length;
95+
if (size >= count) { // includes SymbolProviderSPI if available
96+
p = tmp;
97+
count = size;
98+
}
9599
}
96100

97101
if (p == null) {

i18n/src/main/java/net/time4j/format/expert/AttributeSet.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ final class AttributeSet
6464
int count = 0;
6565

6666
for (NumberSymbolProvider tmp : ResourceLoader.getInstance().services(NumberSymbolProvider.class)) {
67-
if (!tmp.equals(SymbolProviderSPI.INSTANCE)) {
68-
int size = tmp.getAvailableLocales().length;
69-
if (size > count) {
70-
p = tmp;
71-
count = size;
72-
}
67+
int size = tmp.getAvailableLocales().length;
68+
if (size > count) {
69+
p = tmp;
70+
count = size;
7371
}
7472
}
7573

i18n/src/main/java/net/time4j/i18n/SymbolProviderSPI.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import net.time4j.format.NumberSymbolProvider;
2525

26-
import java.text.DecimalFormatSymbols;
2726
import java.util.Collections;
2827
import java.util.HashSet;
2928
import java.util.Locale;
@@ -46,6 +45,8 @@ public final class SymbolProviderSPI
4645

4746
//~ Statische Felder/Initialisierungen --------------------------------
4847

48+
private static final Locale[] EMPTY_ARRAY = new Locale[0];
49+
4950
public static final Set<String> SUPPORTED_LOCALES;
5051
public static final SymbolProviderSPI INSTANCE;
5152

@@ -79,30 +80,7 @@ public SymbolProviderSPI() {
7980
@Override
8081
public Locale[] getAvailableLocales() {
8182

82-
Set<String> set = new HashSet<>(SUPPORTED_LOCALES);
83-
84-
for (Locale loc : DecimalFormatSymbols.getAvailableLocales()) {
85-
if (loc.getCountry().isEmpty()) {
86-
set.add(loc.getLanguage());
87-
} else {
88-
set.add(loc.getLanguage() + "_" + loc.getCountry());
89-
}
90-
}
91-
92-
Locale[] result = new Locale[set.size()];
93-
int i = 0;
94-
95-
for (String s : set) {
96-
int underscore = s.indexOf('_');
97-
if (underscore == -1) {
98-
result[i] = new Locale(s);
99-
} else {
100-
result[i] = new Locale(s.substring(0, underscore), s.substring(underscore + 1));
101-
}
102-
i++;
103-
}
104-
105-
return result;
83+
return EMPTY_ARRAY; // ok because this class only serves as fallback in SPI-mechanism
10684

10785
}
10886

0 commit comments

Comments
 (0)