Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / text / NumberFormat.js
1 Clazz.declarePackage ("java.text");
2 Clazz.load (["java.text.Format", "java.util.HashMap", "$.Hashtable"], "java.text.NumberFormat", ["java.lang.Byte", "$.IllegalArgumentException", "$.Long", "$.Number", "$.Short", "$.StringBuffer", "$.UnsupportedOperationException", "java.text.DecimalFormatSymbols", "$.DontCareFieldPosition", "$.ParseException", "$.ParsePosition", "java.util.Locale", "jssun.util.resources.LocaleData"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.groupingUsed = true;
5 this.maxFractionDigits = 3;
6 this.parseIntegerOnly = false;
7 this.maximumIntegerDigits = 40;
8 this.minimumIntegerDigits = 1;
9 this.maximumFractionDigits = 3;
10 this.minimumFractionDigits = 0;
11 Clazz.instantialize (this, arguments);
12 }, java.text, "NumberFormat", java.text.Format);
13 Clazz.makeConstructor (c$, 
14 function () {
15 Clazz.superConstructor (this, java.text.NumberFormat, []);
16 });
17 Clazz.defineMethod (c$, "format", 
18 function (number, toAppendTo, pos) {
19 if (Clazz.instanceOf (number, Long) || Clazz.instanceOf (number, Integer) || Clazz.instanceOf (number, Short) || Clazz.instanceOf (number, Byte)) {
20 return this.format ((number).longValue (), toAppendTo, pos);
21 } else if (Clazz.instanceOf (number, Number)) {
22 return this.format ((number).doubleValue (), toAppendTo, pos);
23 } else {
24 throw  new IllegalArgumentException ("Cannot format given Object as a Number");
25 }}, "~O,StringBuffer,java.text.FieldPosition");
26 Clazz.defineMethod (c$, "parseObject", 
27 function (source, pos) {
28 return this.parse (source, pos);
29 }, "~S,java.text.ParsePosition");
30 Clazz.defineMethod (c$, "format", 
31 function (number) {
32 return this.format (number,  new StringBuffer (), java.text.DontCareFieldPosition.INSTANCE).toString ();
33 }, "~N");
34 Clazz.defineMethod (c$, "parse", 
35 function (source) {
36 var parsePosition =  new java.text.ParsePosition (0);
37 var result = this.parse (source, parsePosition);
38 if (parsePosition.index == 0) {
39 throw  new java.text.ParseException ("Unparseable number: \"" + source + "\"", parsePosition.errorIndex);
40 }return result;
41 }, "~S");
42 Clazz.defineMethod (c$, "isParseIntegerOnly", 
43 function () {
44 return this.parseIntegerOnly;
45 });
46 Clazz.defineMethod (c$, "setParseIntegerOnly", 
47 function (value) {
48 this.parseIntegerOnly = value;
49 }, "~B");
50 c$.getInstance = Clazz.defineMethod (c$, "getInstance", 
51 function () {
52 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 0);
53 });
54 c$.getInstance = Clazz.defineMethod (c$, "getInstance", 
55 function (inLocale) {
56 return java.text.NumberFormat.getInstance (inLocale, 0);
57 }, "java.util.Locale");
58 c$.getNumberInstance = Clazz.defineMethod (c$, "getNumberInstance", 
59 function () {
60 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 0);
61 });
62 c$.getNumberInstance = Clazz.defineMethod (c$, "getNumberInstance", 
63 function (inLocale) {
64 return java.text.NumberFormat.getInstance (inLocale, 0);
65 }, "java.util.Locale");
66 c$.getIntegerInstance = Clazz.defineMethod (c$, "getIntegerInstance", 
67 function () {
68 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 4);
69 });
70 c$.getIntegerInstance = Clazz.defineMethod (c$, "getIntegerInstance", 
71 function (inLocale) {
72 return java.text.NumberFormat.getInstance (inLocale, 4);
73 }, "java.util.Locale");
74 c$.getCurrencyInstance = Clazz.defineMethod (c$, "getCurrencyInstance", 
75 function () {
76 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 1);
77 });
78 c$.getCurrencyInstance = Clazz.defineMethod (c$, "getCurrencyInstance", 
79 function (inLocale) {
80 return java.text.NumberFormat.getInstance (inLocale, 1);
81 }, "java.util.Locale");
82 c$.getPercentInstance = Clazz.defineMethod (c$, "getPercentInstance", 
83 function () {
84 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 2);
85 });
86 c$.getPercentInstance = Clazz.defineMethod (c$, "getPercentInstance", 
87 function (inLocale) {
88 return java.text.NumberFormat.getInstance (inLocale, 2);
89 }, "java.util.Locale");
90 c$.getScientificInstance = Clazz.defineMethod (c$, "getScientificInstance", 
91 function () {
92 return java.text.NumberFormat.getInstance (java.util.Locale.getDefault (), 3);
93 });
94 c$.getScientificInstance = Clazz.defineMethod (c$, "getScientificInstance", 
95 function (inLocale) {
96 return java.text.NumberFormat.getInstance (inLocale, 3);
97 }, "java.util.Locale");
98 Clazz.overrideMethod (c$, "hashCode", 
99 function () {
100 return this.maximumIntegerDigits * 37 + this.maxFractionDigits;
101 });
102 Clazz.overrideMethod (c$, "equals", 
103 function (obj) {
104 if (obj == null) {
105 return false;
106 }if (this === obj) {
107 return true;
108 }if (this.getClass () !== obj.getClass ()) {
109 return false;
110 }var other = obj;
111 return (this.maximumIntegerDigits == other.maximumIntegerDigits && this.minimumIntegerDigits == other.minimumIntegerDigits && this.maximumFractionDigits == other.maximumFractionDigits && this.minimumFractionDigits == other.minimumFractionDigits && this.groupingUsed == other.groupingUsed && this.parseIntegerOnly == other.parseIntegerOnly);
112 }, "~O");
113 Clazz.defineMethod (c$, "clone", 
114 function () {
115 var other = Clazz.superCall (this, java.text.NumberFormat, "clone", []);
116 return other;
117 });
118 Clazz.defineMethod (c$, "isGroupingUsed", 
119 function () {
120 return this.groupingUsed;
121 });
122 Clazz.defineMethod (c$, "setGroupingUsed", 
123 function (newValue) {
124 this.groupingUsed = newValue;
125 }, "~B");
126 Clazz.defineMethod (c$, "getMaximumIntegerDigits", 
127 function () {
128 return this.maximumIntegerDigits;
129 });
130 Clazz.defineMethod (c$, "setMaximumIntegerDigits", 
131 function (newValue) {
132 this.maximumIntegerDigits = Math.max (0, newValue);
133 if (this.minimumIntegerDigits > this.maximumIntegerDigits) {
134 this.minimumIntegerDigits = this.maximumIntegerDigits;
135 }}, "~N");
136 Clazz.defineMethod (c$, "getMinimumIntegerDigits", 
137 function () {
138 return this.minimumIntegerDigits;
139 });
140 Clazz.defineMethod (c$, "setMinimumIntegerDigits", 
141 function (newValue) {
142 this.minimumIntegerDigits = Math.max (0, newValue);
143 if (this.minimumIntegerDigits > this.maximumIntegerDigits) {
144 this.maximumIntegerDigits = this.minimumIntegerDigits;
145 }}, "~N");
146 Clazz.defineMethod (c$, "getMaximumFractionDigits", 
147 function () {
148 return this.maximumFractionDigits;
149 });
150 Clazz.defineMethod (c$, "setMaximumFractionDigits", 
151 function (newValue) {
152 this.maximumFractionDigits = Math.max (0, newValue);
153 if (this.maximumFractionDigits < this.minimumFractionDigits) {
154 this.minimumFractionDigits = this.maximumFractionDigits;
155 }}, "~N");
156 Clazz.defineMethod (c$, "getMinimumFractionDigits", 
157 function () {
158 return this.minimumFractionDigits;
159 });
160 Clazz.defineMethod (c$, "setMinimumFractionDigits", 
161 function (newValue) {
162 this.minimumFractionDigits = Math.max (0, newValue);
163 if (this.maximumFractionDigits < this.minimumFractionDigits) {
164 this.maximumFractionDigits = this.minimumFractionDigits;
165 }}, "~N");
166 Clazz.defineMethod (c$, "getRoundingMode", 
167 function () {
168 throw  new UnsupportedOperationException ();
169 });
170 Clazz.defineMethod (c$, "setRoundingMode", 
171 function (roundingMode) {
172 throw  new UnsupportedOperationException ();
173 }, "java.math.RoundingMode");
174 c$.getInstance = Clazz.defineMethod (c$, "getInstance", 
175  function (desiredLocale, choice) {
176 var numberPatterns = java.text.NumberFormat.cachedLocaleData.get (desiredLocale);
177 if (numberPatterns == null) {
178 var resource = jssun.util.resources.LocaleData.getNumberFormatData (desiredLocale);
179 numberPatterns = resource.getStringArray ("NumberPatterns");
180 java.text.NumberFormat.cachedLocaleData.put (desiredLocale, numberPatterns);
181 }var symbols = java.text.DecimalFormatSymbols.getInstance (desiredLocale);
182 var entry = (choice == 4) ? 0 : choice;
183 var format =  new java.text.DecimalFormat (numberPatterns[entry], symbols);
184 if (choice == 4) {
185 format.setMaximumFractionDigits (0);
186 format.setDecimalSeparatorAlwaysShown (false);
187 format.setParseIntegerOnly (true);
188 } else if (choice == 1) {
189 format.adjustForCurrencyDefaultFractionDigits ();
190 }return format;
191 }, "java.util.Locale,~N");
192 Clazz.pu$h(self.c$);
193 c$ = Clazz.declareType (java.text.NumberFormat, "Field", java.text.Format.Field);
194 Clazz.makeConstructor (c$, 
195 function (a) {
196 Clazz.superConstructor (this, java.text.NumberFormat.Field, [a]);
197 if (this.getClass () === java.text.NumberFormat.Field) {
198 java.text.NumberFormat.Field.$instanceMap.put (a, this);
199 }}, "~S");
200 c$.$instanceMap = c$.prototype.$instanceMap =  new java.util.HashMap (11);
201 c$.INTEGER = c$.prototype.INTEGER =  new java.text.NumberFormat.Field ("integer");
202 c$.FRACTION = c$.prototype.FRACTION =  new java.text.NumberFormat.Field ("fraction");
203 c$.EXPONENT = c$.prototype.EXPONENT =  new java.text.NumberFormat.Field ("exponent");
204 c$.DECIMAL_SEPARATOR = c$.prototype.DECIMAL_SEPARATOR =  new java.text.NumberFormat.Field ("decimal separator");
205 c$.SIGN = c$.prototype.SIGN =  new java.text.NumberFormat.Field ("sign");
206 c$.GROUPING_SEPARATOR = c$.prototype.GROUPING_SEPARATOR =  new java.text.NumberFormat.Field ("grouping separator");
207 c$.EXPONENT_SYMBOL = c$.prototype.EXPONENT_SYMBOL =  new java.text.NumberFormat.Field ("exponent symbol");
208 c$.PERCENT = c$.prototype.PERCENT =  new java.text.NumberFormat.Field ("percent");
209 c$.PERMILLE = c$.prototype.PERMILLE =  new java.text.NumberFormat.Field ("per mille");
210 c$.CURRENCY = c$.prototype.CURRENCY =  new java.text.NumberFormat.Field ("currency");
211 c$.EXPONENT_SIGN = c$.prototype.EXPONENT_SIGN =  new java.text.NumberFormat.Field ("exponent sign");
212 c$ = Clazz.p0p ();
213 Clazz.defineStatics (c$,
214 "INTEGER_FIELD", 0,
215 "FRACTION_FIELD", 1);
216 c$.cachedLocaleData = c$.prototype.cachedLocaleData =  new java.util.Hashtable (3);
217 Clazz.defineStatics (c$,
218 "NUMBERSTYLE", 0,
219 "CURRENCYSTYLE", 1,
220 "PERCENTSTYLE", 2,
221 "SCIENTIFICSTYLE", 3,
222 "INTEGERSTYLE", 4,
223 "currentSerialVersion", 1);
224 });