094042b09a67409cbacb429fd69adf19de6b5c23
[jalviewjs.git] / site / j2s / java / util / Locale.js
1 Clazz.declarePackage ("java.util");
2 Clazz.load (["java.util.HashMap"], "java.util.Locale", ["java.lang.InternalError", "$.NullPointerException", "$.StringBuilder"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.language = null;
5 this.country = null;
6 this.variant = null;
7 this.hashCodeValue = 0;
8 Clazz.instantialize (this, arguments);
9 }, java.util, "Locale", null, [Cloneable, java.io.Serializable]);
10 Clazz.makeConstructor (c$, 
11 function (language, country, variant) {
12 this.language = language.intern ();
13 this.country = country.intern ();
14 this.variant = variant.intern ();
15 }, "~S,~S,~S");
16 Clazz.makeConstructor (c$, 
17 function (language, country) {
18 this.construct (language, country, "");
19 }, "~S,~S");
20 Clazz.makeConstructor (c$, 
21 function (language) {
22 this.construct (language, "", "");
23 }, "~S");
24 Clazz.makeConstructor (c$, 
25  function (language, country, flag) {
26 this.language = language;
27 this.country = country;
28 this.variant = "";
29 }, "~S,~S,~B");
30 c$.createSingleton = Clazz.defineMethod (c$, "createSingleton", 
31  function (key, language, country) {
32 var locale =  new java.util.Locale (language, country, false);
33 java.util.Locale.cache.put (key, locale);
34 return locale;
35 }, "~S,~S,~S");
36 c$.getInstance = Clazz.defineMethod (c$, "getInstance", 
37 function (language, country, variant) {
38 if (language == null || country == null || variant == null) {
39 throw  new NullPointerException ();
40 }var sb =  new StringBuilder ();
41 sb.append (language).append ('_').append (country).append ('_').append (variant);
42 var key = sb.toString ();
43 var locale = java.util.Locale.cache.get (key);
44 if (locale == null) {
45 locale =  new java.util.Locale (language, country, variant);
46 var l = java.util.Locale.cache.put (key, locale);
47 if (l != null) {
48 locale = l;
49 }}return locale;
50 }, "~S,~S,~S");
51 c$.getDefault = Clazz.defineMethod (c$, "getDefault", 
52 function () {
53 if (java.util.Locale.defaultLocale == null) {
54 var language;
55 var country;
56 var variant;
57 language = "en";
58 country = "";
59 variant = "";
60 java.util.Locale.defaultLocale = java.util.Locale.getInstance (language, country, variant);
61 }return java.util.Locale.defaultLocale;
62 });
63 c$.setDefault = Clazz.defineMethod (c$, "setDefault", 
64 function (newLocale) {
65 if (newLocale == null) throw  new NullPointerException ("Can't set default locale to NULL");
66 java.util.Locale.defaultLocale = newLocale;
67 }, "java.util.Locale");
68 Clazz.defineMethod (c$, "getLanguage", 
69 function () {
70 return this.language;
71 });
72 Clazz.defineMethod (c$, "getCountry", 
73 function () {
74 return this.country;
75 });
76 Clazz.defineMethod (c$, "getVariant", 
77 function () {
78 return this.variant;
79 });
80 Clazz.overrideMethod (c$, "toString", 
81 function () {
82 var l = this.language.length != 0;
83 var c = this.country.length != 0;
84 var v = this.variant.length != 0;
85 var result =  new StringBuilder (this.language);
86 if (c || (l && v)) {
87 result.append ('_').append (this.country);
88 }if (v && (l || c)) {
89 result.append ('_').append (this.variant);
90 }return result.toString ();
91 });
92 Clazz.defineMethod (c$, "getDisplayLanguage", 
93 function () {
94 return this.getDisplayLanguage (java.util.Locale.getDefault ());
95 });
96 Clazz.defineMethod (c$, "getDisplayLanguage", 
97 function (inLocale) {
98 return this.getDisplayString (this.language, inLocale, 0);
99 }, "java.util.Locale");
100 Clazz.defineMethod (c$, "getDisplayCountry", 
101 function () {
102 return this.getDisplayCountry (java.util.Locale.getDefault ());
103 });
104 Clazz.defineMethod (c$, "getDisplayCountry", 
105 function (inLocale) {
106 return this.getDisplayString (this.country, inLocale, 1);
107 }, "java.util.Locale");
108 Clazz.defineMethod (c$, "getDisplayString", 
109  function (code, inLocale, type) {
110 if (code.length == 0) {
111 return "";
112 }if (inLocale == null) {
113 throw  new NullPointerException ();
114 }return inLocale.toString ();
115 }, "~S,java.util.Locale,~N");
116 Clazz.defineMethod (c$, "getDisplayVariant", 
117 function () {
118 return this.getDisplayVariant (java.util.Locale.getDefault ());
119 });
120 Clazz.defineMethod (c$, "getDisplayVariant", 
121 function (inLocale) {
122 if (this.variant.length == 0) return "";
123 return this.variant;
124 }, "java.util.Locale");
125 Clazz.defineMethod (c$, "getDisplayName", 
126 function () {
127 return this.getDisplayName (java.util.Locale.getDefault ());
128 });
129 Clazz.defineMethod (c$, "getDisplayName", 
130 function (inLocale) {
131 return inLocale.toString ();
132 }, "java.util.Locale");
133 Clazz.defineMethod (c$, "clone", 
134 function () {
135 try {
136 var that = Clazz.superCall (this, java.util.Locale, "clone", []);
137 return that;
138 } catch (e) {
139 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
140 throw  new InternalError ();
141 } else {
142 throw e;
143 }
144 }
145 });
146 Clazz.overrideMethod (c$, "hashCode", 
147 function () {
148 var hc = this.hashCodeValue;
149 if (hc == 0) {
150 hc = (this.language.hashCode () << 8) ^ this.country.hashCode () ^ (this.variant.hashCode () << 4);
151 this.hashCodeValue = hc;
152 }return hc;
153 });
154 Clazz.overrideMethod (c$, "equals", 
155 function (obj) {
156 if (this === obj) return true;
157 if (!(Clazz.instanceOf (obj, java.util.Locale))) return false;
158 var other = obj;
159 return this.language === other.language && this.country === other.country && this.variant === other.variant;
160 }, "~O");
161 c$.cache = c$.prototype.cache =  new java.util.HashMap (32);
162 c$.ENGLISH = c$.prototype.ENGLISH = java.util.Locale.createSingleton ("en__", "en", "");
163 c$.ROOT = c$.prototype.ROOT = java.util.Locale.createSingleton ("__", "", "");
164 Clazz.defineStatics (c$,
165 "DISPLAY_LANGUAGE", 0,
166 "DISPLAY_COUNTRY", 1,
167 "defaultLocale", null);
168 });