Subversion Repository Public Repository

litesoft

Diff Revisions 960 vs 961 for /trunk/DeviceDesktopTest/src/org/litesoft/locale/DerivedLocaleGraph.java

Diff revisions: vs.
  @@ -3,15 +3,13 @@
3 3 import java.util.*;
4 4
5 5 @SuppressWarnings("Convert2Diamond")
6 - public class DerivedLocaleGraph
7 - {
6 + public class DerivedLocaleGraph {
8 7 private static final AbstractLocale BASE = Locale_en_US.INSTANCE;
9 8 private static final Map<String, AbstractLocale> DEFAULT_LOCALE_BY_LANGUAGE = new HashMap<String, AbstractLocale>();
10 9 private static final Map<String, AbstractLocale> LOCALE_BY_CODE = new HashMap<String, AbstractLocale>();
11 10 private static final Map<AbstractLocale, AbstractLocale> DERIVED_FROM_LOCALE_BY_LOCALE = new HashMap<AbstractLocale, AbstractLocale>();
12 11
13 - static
14 - {
12 + static {
15 13 addToDirectMaps( BASE );
16 14 add( Locale_en_US.INSTANCE, Locale_en_GB.INSTANCE, Locale_en_CA.INSTANCE );
17 15 add( Locale_es_ES.INSTANCE, Locale_es_MX.INSTANCE );
  @@ -23,16 +21,12 @@
23 21 add( Locale_ko_KR.INSTANCE );
24 22 }
25 23
26 - public static AbstractLocale select( Set<AbstractLocale> pSupported, List<String> pOrderedCodes )
27 - {
24 + public static AbstractLocale select( Set<AbstractLocale> pSupported, List<String> pOrderedCodes ) {
28 25 AbstractLocale zBest = BASE;
29 - if ( pOrderedCodes != null )
30 - {
31 - for ( String zCode : pOrderedCodes )
32 - {
26 + if ( pOrderedCodes != null ) {
27 + for ( String zCode : pOrderedCodes ) {
33 28 AbstractLocale zCandidate = candidateForFrom( zCode, pSupported );
34 - if ( zCandidate.mDepth > zBest.mDepth )
35 - {
29 + if ( zCandidate.mDepth > zBest.mDepth ) {
36 30 zBest = zCandidate;
37 31 }
38 32 }
  @@ -40,41 +34,32 @@
40 34 return zBest;
41 35 }
42 36
43 - private static AbstractLocale candidateForFrom( String pCode, Set<AbstractLocale> pSupported )
44 - {
37 + private static AbstractLocale candidateForFrom( String pCode, Set<AbstractLocale> pSupported ) {
45 38 AbstractLocale zLocale = LOCALE_BY_CODE.get( pCode );
46 - if ( null == zLocale )
47 - {
48 - if ( null == (zLocale = DEFAULT_LOCALE_BY_LANGUAGE.get( AbstractLocale.languageFrom( pCode ) )) )
49 - {
39 + if ( null == zLocale ) {
40 + if ( null == (zLocale = DEFAULT_LOCALE_BY_LANGUAGE.get( AbstractLocale.languageFrom( pCode ) )) ) {
50 41 return BASE;
51 42 }
52 43 }
53 - while ( !pSupported.contains( zLocale ) )
54 - {
55 - if ( null == (zLocale = DERIVED_FROM_LOCALE_BY_LOCALE.get( zLocale )) )
56 - {
44 + while ( !pSupported.contains( zLocale ) ) {
45 + if ( null == (zLocale = DERIVED_FROM_LOCALE_BY_LOCALE.get( zLocale )) ) {
57 46 return BASE;
58 47 }
59 48 }
60 49 return zLocale;
61 50 }
62 51
63 - public static void add( AbstractLocale pBaseOrDerivedFrom, AbstractLocale... pDerived )
64 - {
65 - if ( addToDirectMaps( pBaseOrDerivedFrom ) )
66 - {
52 + public static void add( AbstractLocale pBaseOrDerivedFrom, AbstractLocale... pDerived ) {
53 + if ( addToDirectMaps( pBaseOrDerivedFrom ) ) {
67 54 setDerived( BASE, pBaseOrDerivedFrom );
68 55 }
69 - for ( AbstractLocale zLocale : pDerived )
70 - {
56 + for ( AbstractLocale zLocale : pDerived ) {
71 57 addToDirectMaps( zLocale );
72 58 setDerived( pBaseOrDerivedFrom, zLocale );
73 59 }
74 60 }
75 61
76 - private static void setDerived( AbstractLocale pDerivedFrom, AbstractLocale pDerived )
77 - {
62 + private static void setDerived( AbstractLocale pDerivedFrom, AbstractLocale pDerived ) {
78 63 pDerived.mDepth = pDerivedFrom.mDepth + 1;
79 64 DERIVED_FROM_LOCALE_BY_LOCALE.put( pDerived, pDerivedFrom );
80 65 }
  @@ -84,21 +69,17 @@
84 69 *
85 70 * @return true - If not already in the data structures
86 71 */
87 - private static boolean addToDirectMaps( AbstractLocale pLocale )
88 - {
89 - if ( null != LOCALE_BY_CODE.put( pLocale.getCode(), pLocale ) )
90 - {
72 + private static boolean addToDirectMaps( AbstractLocale pLocale ) {
73 + if ( null != LOCALE_BY_CODE.put( pLocale.getCode(), pLocale ) ) {
91 74 return false; // Already There!
92 75 }
93 76 // New, so might be the first of this language
94 - if ( !DEFAULT_LOCALE_BY_LANGUAGE.containsKey( pLocale.getLanguage() ) )
95 - {
77 + if ( !DEFAULT_LOCALE_BY_LANGUAGE.containsKey( pLocale.getLanguage() ) ) {
96 78 DEFAULT_LOCALE_BY_LANGUAGE.put( pLocale.getLanguage(), pLocale );
97 79 }
98 80 return true; // Added
99 81 }
100 82
101 - private DerivedLocaleGraph()
102 - {
83 + private DerivedLocaleGraph() {
103 84 }
104 85 }