litesoft
Diff Revisions
929
vs
931
for /trunk/DeviceDesktopTest/src/org/litesoft/locale/Locales.java
|
@@ -1,5 +1,54 @@ |
1 |
1 |
|
package org.litesoft.locale; |
2 |
2 |
|
|
3 |
|
- |
public class Locales |
4 |
|
- |
{ |
|
3 |
+ |
import java.util.ArrayList; |
|
4 |
+ |
import java.util.Collections; |
|
5 |
+ |
import java.util.HashSet; |
|
6 |
+ |
import java.util.List; |
|
7 |
+ |
import java.util.Set; |
|
8 |
+ |
|
|
9 |
+ |
@SuppressWarnings("Convert2Diamond") |
|
10 |
+ |
public final class Locales { |
|
11 |
+ |
private static Locales sInstance; |
|
12 |
+ |
|
|
13 |
+ |
public static synchronized Locales getInstance() { |
|
14 |
+ |
if (sInstance == null) { |
|
15 |
+ |
throw new IllegalStateException("Locales referenced before being initialized!"); |
|
16 |
+ |
} |
|
17 |
+ |
return sInstance; |
|
18 |
+ |
} |
|
19 |
+ |
|
|
20 |
+ |
private static synchronized void setInstance(Locales pInstance) { |
|
21 |
+ |
if (sInstance != null) { |
|
22 |
+ |
throw new IllegalStateException("Duplicate Locales created!"); |
|
23 |
+ |
} |
|
24 |
+ |
sInstance = pInstance; |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
private final Set<AbstractLocale> mSupported; |
|
28 |
+ |
private final List<String> mActiveCodes = new ArrayList<String>(); |
|
29 |
+ |
|
|
30 |
+ |
public Locales(AbstractLocale... pSupportedLocales) { |
|
31 |
+ |
mSupported = Collections.unmodifiableSet(toSet(pSupportedLocales)); |
|
32 |
+ |
for (AbstractLocale zLocale : pSupportedLocales) { |
|
33 |
+ |
if (zLocale.isActive()) { |
|
34 |
+ |
mActiveCodes.add(zLocale.getCode()); |
|
35 |
+ |
} |
|
36 |
+ |
} |
|
37 |
+ |
setInstance(this); // 'this' leakage, but is final class! |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
public static Set<AbstractLocale> getSupported() { |
|
41 |
+ |
return getInstance().mSupported; |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
public static String[] getActiveCodes() { |
|
45 |
+ |
List<String> zActiveCodes = getInstance().mActiveCodes; |
|
46 |
+ |
return zActiveCodes.toArray(new String[zActiveCodes.size()]); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
public static Set<AbstractLocale> toSet(AbstractLocale... pSupportedLocales) { |
|
50 |
+ |
Set<AbstractLocale> zLocales = new HashSet<>(); |
|
51 |
+ |
Collections.addAll(zLocales, pSupportedLocales); |
|
52 |
+ |
return zLocales; |
|
53 |
+ |
} |
5 |
54 |
|
} |