Subversion Repository Public Repository

litesoft

Diff Revisions 931 vs 935 for /trunk/DeviceDesktopTest/src/org/litesoft/locale/AbstractLocale.java

Diff revisions: vs.
  @@ -1,6 +1,7 @@
1 1 package org.litesoft.locale;
2 2
3 - public abstract class AbstractLocale {
3 + public abstract class AbstractLocale
4 + {
4 5 public static final String BAD_LANGUAGE_OR_COUNTRY = "??";
5 6
6 7 private static final String LOCALE_CLASS_NAME_PREFIX = ".Locale_";
  @@ -9,104 +10,129 @@
9 10 private final String mLanguage, mCountry, mCode;
10 11 /* friend( DerivedLocaleGraph ) */ int mDepth;
11 12
12 - protected AbstractLocale(boolean pActive) {
13 + protected AbstractLocale( boolean pActive )
14 + {
13 15 mActive = pActive;
14 16 String zName = "." + this.getClass().getName();
15 - int zAt = zName.indexOf(LOCALE_CLASS_NAME_PREFIX);
16 - if (zAt == -1) {
17 - throw new IllegalStateException("'" + LOCALE_CLASS_NAME_PREFIX + "' not found in: " + zName);
17 + int zAt = zName.indexOf( LOCALE_CLASS_NAME_PREFIX );
18 + if ( zAt == -1 )
19 + {
20 + throw new IllegalStateException( "'" + LOCALE_CLASS_NAME_PREFIX + "' not found in: " + zName );
18 21 }
19 - String zLanguageCountry = zName.substring(zAt + LOCALE_CLASS_NAME_PREFIX.length());
20 - if (!isValidStructuredCode(zLanguageCountry)) {
21 - throw new IllegalStateException("No Language & Country found in: " + zName);
22 + String zLanguageCountry = zName.substring( zAt + LOCALE_CLASS_NAME_PREFIX.length() );
23 + if ( !isValidStructuredCode( zLanguageCountry ) )
24 + {
25 + throw new IllegalStateException( "No Language & Country found in: " + zName );
22 26 }
23 - mLanguage = assertLowerCase("Language", codeToLanguage(zLanguageCountry));
24 - mCountry = assertUpperCase("Country", codeToCountry(zLanguageCountry));
25 - mCode = toCode(mLanguage, mCountry);
27 + mLanguage = assertLowerCase( "Language", codeToLanguage( zLanguageCountry ) );
28 + mCountry = assertUpperCase( "Country", codeToCountry( zLanguageCountry ) );
29 + mCode = toCode( mLanguage, mCountry );
26 30 }
27 31
28 - private static String assertLowerCase(String pWhat, String pString) {
29 - return assertCase(pWhat, pString, pString.toLowerCase(), "LowerCase");
32 + private static String assertLowerCase( String pWhat, String pString )
33 + {
34 + return assertCase( pWhat, pString, pString.toLowerCase(), "LowerCase" );
30 35 }
31 36
32 - private static String assertUpperCase(String pWhat, String pString) {
33 - return assertCase(pWhat, pString, pString.toUpperCase(), "UpperCase");
37 + private static String assertUpperCase( String pWhat, String pString )
38 + {
39 + return assertCase( pWhat, pString, pString.toUpperCase(), "UpperCase" );
34 40 }
35 41
36 - private static String assertCase(String pWhat, String pString, String pAdjustedString, String pCase) {
37 - if (pString.equals(pAdjustedString)) {
42 + private static String assertCase( String pWhat, String pString, String pAdjustedString, String pCase )
43 + {
44 + if ( pString.equals( pAdjustedString ) )
45 + {
38 46 return pString;
39 47 }
40 - throw new IllegalStateException(pWhat + " '" + pString + "' NOT " + pCase);
48 + throw new IllegalStateException( pWhat + " '" + pString + "' NOT " + pCase );
41 49 }
42 50
43 - protected AbstractLocale() {
44 - this(true);
51 + protected AbstractLocale()
52 + {
53 + this( true );
45 54 }
46 55
47 - public boolean isActive() {
56 + public boolean isActive()
57 + {
48 58 return mActive;
49 59 }
50 60
51 - public String getLanguage() {
61 + public String getLanguage()
62 + {
52 63 return mLanguage;
53 64 }
54 65
55 - public String getCountry() {
66 + public String getCountry()
67 + {
56 68 return mCountry;
57 69 }
58 70
59 - public String getCode() {
71 + public String getCode()
72 + {
60 73 return mCode;
61 74 }
62 75
63 76 @Override
64 - public boolean equals(Object o) {
65 - return (this == o) || ((o instanceof AbstractLocale) && equals((AbstractLocale) o));
77 + public boolean equals( Object o )
78 + {
79 + return (this == o) || ((o instanceof AbstractLocale) && equals( (AbstractLocale) o ));
66 80 }
67 81
68 - public boolean equals(AbstractLocale them) {
82 + public boolean equals( AbstractLocale them )
83 + {
69 84 return (this == them) || ((them != null)
70 - && this.mCode.equals(them.mCode));
85 + && this.mCode.equals( them.mCode ));
71 86 }
72 87
73 88 @Override
74 - public int hashCode() {
89 + public int hashCode()
90 + {
75 91 return mCode.hashCode();
76 92 }
77 93
78 94 @Override
79 - public String toString() {
95 + public String toString()
96 + {
80 97 return getCode();
81 98 }
82 99
83 - public static String languageFrom(String pCode) {
84 - return isValidStructuredCode(pCode) ? codeToLanguage(pCode) : BAD_LANGUAGE_OR_COUNTRY;
100 + public static String languageFrom( String pCode )
101 + {
102 + return isValidStructuredCode( pCode ) ? codeToLanguage( pCode ) : BAD_LANGUAGE_OR_COUNTRY;
85 103 }
86 104
87 - public static String countryFrom(String pCode) {
88 - return isValidStructuredCode(pCode) ? codeToCountry(pCode) : BAD_LANGUAGE_OR_COUNTRY;
105 + public static String countryFrom( String pCode )
106 + {
107 + return isValidStructuredCode( pCode ) ? codeToCountry( pCode ) : BAD_LANGUAGE_OR_COUNTRY;
89 108 }
90 109
91 - public static String toCode(String pLanguage, String pCountry) {
92 - return ensure2Char(pLanguage).toLowerCase() + "_" + ensure2Char(pCountry).toUpperCase();
110 + public static String toCode( String pLanguage, String pCountry )
111 + {
112 + return ensure2Char( pLanguage ).toLowerCase() + "_" + ensure2Char( pCountry ).toUpperCase();
93 113 }
94 114
95 - private static boolean isValidStructuredCode(String pCode) {
96 - return (pCode != null) && (pCode.length() == 5) && (pCode.charAt(2) == '_');
115 + private static boolean isValidStructuredCode( String pCode )
116 + {
117 + return (pCode != null) && (pCode.length() == 5) && (pCode.charAt( 2 ) == '_');
97 118 }
98 119
99 - private static String codeToLanguage(String pLanguageCountry) {
100 - return pLanguageCountry.substring(0, 2);
120 + private static String codeToLanguage( String pLanguageCountry )
121 + {
122 + return pLanguageCountry.substring( 0, 2 );
101 123 }
102 124
103 - private static String codeToCountry(String pLanguageCountry) {
104 - return pLanguageCountry.substring(3);
125 + private static String codeToCountry( String pLanguageCountry )
126 + {
127 + return pLanguageCountry.substring( 3 );
105 128 }
106 129
107 - private static String ensure2Char(String pString) {
108 - if (pString != null) {
109 - if ((pString = pString.trim()).length() == 2) {
130 + private static String ensure2Char( String pString )
131 + {
132 + if ( pString != null )
133 + {
134 + if ( (pString = pString.trim()).length() == 2 )
135 + {
110 136 return pString;
111 137 }
112 138 }