@@ -318,8 +318,6 @@ public PopulationData setWritingPopulation(double writingPopulation) {
318
318
}
319
319
}
320
320
321
- static final Pattern WHITESPACE_PATTERN = PatternCache .get ("\\ s+" );
322
-
323
321
/** Simple language/script/region information */
324
322
public static class BasicLanguageData
325
323
implements Comparable <BasicLanguageData >,
@@ -349,18 +347,17 @@ public BasicLanguageData setType(Type type) {
349
347
// Adding scripts but leaving 0 as a placeholder when there is no population data
350
348
// input: a whitespace-separated list of scripts
351
349
public BasicLanguageData setScriptsWithoutPopulation (String scriptTokens ) {
352
- List <String > scripts = new ArrayList <>();
353
- if (scriptTokens != null ) {
354
- scripts = Arrays .asList (WHITESPACE_PATTERN .split (scriptTokens ));
355
- }
356
- return setScriptsWithoutPopulation (scripts );
350
+ return setScriptsWithoutPopulation (
351
+ scriptTokens == null ? null : WHITESPACE_SPLITTER .splitToList (scriptTokens ));
357
352
}
358
353
359
354
// Adding scripts but leaving 0 as a placeholder when there is no population data
360
355
public BasicLanguageData setScriptsWithoutPopulation (Collection <String > scripts ) {
361
356
Map <String , Integer > scriptsByPopulation = new TreeMap <>();
362
- for (String script : scripts ) {
363
- scriptsByPopulation .put (script , 0 );
357
+ if (scripts != null ) {
358
+ for (String script : scripts ) {
359
+ scriptsByPopulation .put (script , 0 );
360
+ }
364
361
}
365
362
return setScripts (scriptsByPopulation );
366
363
}
@@ -369,7 +366,7 @@ public BasicLanguageData setTerritories(String territoryTokens) {
369
366
return setTerritories (
370
367
territoryTokens == null
371
368
? null
372
- : Arrays . asList ( WHITESPACE_PATTERN . split ( territoryTokens ) ));
369
+ : WHITESPACE_SPLITTER . splitToList ( territoryTokens ));
373
370
}
374
371
375
372
public BasicLanguageData setScripts (Map <String , Integer > newScripts ) {
@@ -379,7 +376,9 @@ public BasicLanguageData setScripts(Map<String, Integer> newScripts) {
379
376
// TODO add error checking
380
377
scripts = Collections .emptySet ();
381
378
scriptsByPopulation = new TreeMap <>();
382
- addScripts (newScripts );
379
+ if (newScripts != null ) {
380
+ addScripts (newScripts );
381
+ }
383
382
return this ;
384
383
}
385
384
@@ -1686,7 +1685,7 @@ private boolean handleUnitPreferences(XPathValue parts, String value) {
1686
1685
1687
1686
private boolean handleLanguageGroups (String value , XPathValue parts ) {
1688
1687
String parent = parts .getAttributeValue (-1 , "parent" );
1689
- List <String > children = WHITESPACE_SPLTTER .splitToList (value );
1688
+ List <String > children = WHITESPACE_SPLITTER .splitToList (value );
1690
1689
languageGroups .putAll (parent , children );
1691
1690
return true ;
1692
1691
}
@@ -1862,7 +1861,7 @@ private boolean handleLanguageMatcher(XPathValue parts) {
1862
1861
switch (parts .getElement (3 )) {
1863
1862
case "paradigmLocales" :
1864
1863
List <String > locales =
1865
- WHITESPACE_SPLTTER .splitToList (parts .getAttributeValue (3 , "locales" ));
1864
+ WHITESPACE_SPLITTER .splitToList (parts .getAttributeValue (3 , "locales" ));
1866
1865
// TODO
1867
1866
// LanguageMatchData languageMatchData =
1868
1867
// languageMatchData.get(type);
@@ -5107,7 +5106,7 @@ public File getDirectory() {
5107
5106
return directory ;
5108
5107
}
5109
5108
5110
- public static final Splitter WHITESPACE_SPLTTER =
5109
+ public static final Splitter WHITESPACE_SPLITTER =
5111
5110
Splitter .on (PatternCache .get ("\\ s+" )).omitEmptyStrings ();
5112
5111
5113
5112
public static final class AttributeValidityInfo {
@@ -5155,7 +5154,7 @@ public AttributeValidityInfo(
5155
5154
this .dtds = Collections .singleton (DtdType .ldml );
5156
5155
} else {
5157
5156
Set <DtdType > temp = EnumSet .noneOf (DtdType .class );
5158
- for (String s : WHITESPACE_SPLTTER .split (dtds )) {
5157
+ for (String s : WHITESPACE_SPLITTER .split (dtds )) {
5159
5158
temp .add (DtdType .fromElement (s ));
5160
5159
}
5161
5160
this .dtds = Collections .unmodifiableSet (temp );
@@ -5164,10 +5163,10 @@ public AttributeValidityInfo(
5164
5163
this .elements =
5165
5164
elements == null
5166
5165
? Collections .EMPTY_SET
5167
- : With .in (WHITESPACE_SPLTTER .split (elements ))
5166
+ : With .in (WHITESPACE_SPLITTER .split (elements ))
5168
5167
.toUnmodifiableCollection (new HashSet <String >());
5169
5168
this .attributes =
5170
- With .in (WHITESPACE_SPLTTER .split (attributes ))
5169
+ With .in (WHITESPACE_SPLITTER .split (attributes ))
5171
5170
.toUnmodifiableCollection (new HashSet <String >());
5172
5171
this .order = order ;
5173
5172
}
0 commit comments