KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > util > Currency


1 /**
2  *******************************************************************************
3  * Copyright (C) 2001-2006, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

7 package com.ibm.icu.util;
8
9 import java.io.Serializable JavaDoc;
10 import java.text.ChoiceFormat JavaDoc;
11 import java.text.ParsePosition JavaDoc;
12 import java.util.Locale JavaDoc;
13 import java.util.MissingResourceException JavaDoc;
14
15 import com.ibm.icu.impl.ICUDebug;
16 import com.ibm.icu.impl.ICUResourceBundle;
17 import com.ibm.icu.impl.LocaleUtility;
18
19 /**
20  * A class encapsulating a currency, as defined by ISO 4217. A
21  * <tt>Currency</tt> object can be created given a <tt>Locale</tt> or
22  * given an ISO 4217 code. Once created, the <tt>Currency</tt> object
23  * can return various data necessary to its proper display:
24  *
25  * <ul><li>A display symbol, for a specific locale
26  * <li>The number of fraction digits to display
27  * <li>A rounding increment
28  * </ul>
29  *
30  * The <tt>DecimalFormat</tt> class uses these data to display
31  * currencies.
32  *
33  * <p>Note: This class deliberately resembles
34  * <tt>java.util.Currency</tt> but it has a completely independent
35  * implementation, and adds features not present in the JDK.
36  * @author Alan Liu
37  * @stable ICU 2.2
38  */

39 public class Currency extends MeasureUnit implements Serializable JavaDoc {
40     // using serialver from jdk1.4.2_05
41
private static final long serialVersionUID = -5839973855554750484L;
42     private static final boolean DEBUG = ICUDebug.enabled("currency");
43     /**
44      * ISO 4217 3-letter code.
45      */

46     private String JavaDoc isoCode;
47
48     /**
49      * Selector for getName() indicating a symbolic name for a
50      * currency, such as "$" for USD.
51      * @stable ICU 2.6
52      */

53     public static final int SYMBOL_NAME = 0;
54
55     /**
56      * Selector for ucurr_getName indicating the long name for a
57      * currency, such as "US Dollar" for USD.
58      * @stable ICU 2.6
59      */

60     public static final int LONG_NAME = 1;
61
62     // begin registry stuff
63

64     // shim for service code
65
/* package */ static abstract class ServiceShim {
66         abstract ULocale[] getAvailableULocales();
67         abstract Locale JavaDoc[] getAvailableLocales();
68         abstract Currency createInstance(ULocale l);
69         abstract Object JavaDoc registerInstance(Currency c, ULocale l);
70         abstract boolean unregister(Object JavaDoc f);
71     }
72
73     private static ServiceShim shim;
74     private static ServiceShim getShim() {
75         // Note: this instantiation is safe on loose-memory-model configurations
76
// despite lack of synchronization, since the shim instance has no state--
77
// it's all in the class init. The worst problem is we might instantiate
78
// two shim instances, but they'll share the same state so that's ok.
79
if (shim == null) {
80             try {
81                 Class JavaDoc cls = Class.forName("com.ibm.icu.util.CurrencyServiceShim");
82                 shim = (ServiceShim)cls.newInstance();
83             }
84             catch (Exception JavaDoc e) {
85                 if(DEBUG){
86                     e.printStackTrace();
87                 }
88                 throw new RuntimeException JavaDoc(e.getMessage());
89             }
90         }
91         return shim;
92     }
93
94     /**
95      * Returns a currency object for the default currency in the given
96      * locale.
97      * @param locale the locale
98      * @return the currency object for this locale
99      * @stable ICU 2.2
100      */

101     public static Currency getInstance(Locale JavaDoc locale) {
102         return getInstance(ULocale.forLocale(locale));
103     }
104
105     /**
106      * Returns a currency object for the default currency in the given
107      * locale.
108      * @draft ICU 3.2
109      * @provisional This API might change or be removed in a future release.
110      */

111     public static Currency getInstance(ULocale locale) {
112     String JavaDoc currency = locale.getKeywordValue("currency");
113     if (currency != null) {
114         return getInstance(currency);
115     }
116
117         if (shim == null) {
118             return createCurrency(locale);
119         }
120
121         return shim.createInstance(locale);
122     }
123
124     /**
125      * Instantiate a currency from a resource bundle found in Locale loc.
126      */

127     /* package */ static Currency createCurrency(ULocale loc) {
128         // TODO: check, this munging might not be required for ULocale
129
String JavaDoc country = loc.getCountry();
130         String JavaDoc variant = loc.getVariant();
131         if (variant.equals("PREEURO") || variant.equals("EURO")) {
132             country = country + '_' + variant;
133         }
134         ICUResourceBundle bundle = (ICUResourceBundle) ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"CurrencyData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
135         if(bundle==null){
136             //throw new MissingResourceException()
137
}
138         ICUResourceBundle cm = bundle.get("CurrencyMap");
139
140         // Do a linear search
141
String JavaDoc curriso = null;
142         try {
143             curriso = cm.getString(country);
144             if (curriso != null) {
145                 return new Currency(curriso);
146             }
147         } catch (MissingResourceException JavaDoc ex) {
148             try{
149                 // a deprecated ISO code may have been passed
150
// try to get the current country code
151
String JavaDoc rep = ULocale.getCurrentCountryID(country);
152                 if(DEBUG) System.out.println("DEBUG: oldID: "+country +" newID:" +rep);
153                 // here pointer comparison is valid since getCurrentCountryID
154
// will return the input string if there is no replacement
155
if(rep != country){
156                     curriso = cm.getString(rep);
157                     if (curriso != null) {
158                         return new Currency(curriso);
159                     }
160                 }
161             }catch(MissingResourceException JavaDoc e){
162                 //do nothing
163
}
164         }
165         return null;
166         /*
167         for (int i=0; i<cm.length; ++i) {
168             if (country.equals((String) cm[i][0])) {
169                 curriso = (String) cm[i][1];
170                 break;
171             }
172         }
173
174         Currency curr = null;
175         if (curriso != null) {
176
177             curr = new Currency(curriso);
178
179             // TODO: Determine valid and actual locale correctly.
180             ULocale uloc = bundle.getULocale();
181             curr.setLocale(uloc, uloc);
182         }
183         return curr;
184         */

185     }
186
187     /**
188      * Returns a currency object given an ISO 4217 3-letter code.
189      * @param theISOCode the iso code
190      * @return the currency for this iso code
191      * @stable ICU 2.2
192      */

193     public static Currency getInstance(String JavaDoc theISOCode) {
194         return new Currency(theISOCode);
195     }
196
197     /**
198      * Registers a new currency for the provided locale. The returned object
199      * is a key that can be used to unregister this currency object.
200      * @param currency the currency to register
201      * @param locale the ulocale under which to register the currency
202      * @return a registry key that can be used to unregister this currency
203      * @see #unregister
204      * @draft ICU 3.2
205      * @provisional This API might change or be removed in a future release.
206      */

207     public static Object JavaDoc registerInstance(Currency currency, ULocale locale) {
208         return getShim().registerInstance(currency, locale);
209     }
210
211     /**
212      * Unregister the currency associated with this key (obtained from
213      * registerInstance).
214      * @param registryKey the registry key returned from registerInstance
215      * @see #registerInstance
216      * @stable ICU 2.6
217      */

218     public static boolean unregister(Object JavaDoc registryKey) {
219         if (registryKey == null) {
220             throw new IllegalArgumentException JavaDoc("registryKey must not be null");
221         }
222         if (shim == null) {
223             return false;
224         }
225         return shim.unregister(registryKey);
226     }
227
228     /**
229      * Return an array of the locales for which a currency
230      * is defined.
231      * @return an array of the available locales
232      * @stable ICU 2.2
233      */

234     public static Locale JavaDoc[] getAvailableLocales() {
235         if (shim == null) {
236             return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
237         } else {
238             return shim.getAvailableLocales();
239         }
240     }
241
242     /**
243      * Return an array of the ulocales for which a currency
244      * is defined.
245      * @return an array of the available ulocales
246      * @stable ICU 3.2
247      */

248     public static ULocale[] getAvailableULocales() {
249         if (shim == null) {
250             return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_BASE_NAME);
251         } else {
252             return shim.getAvailableULocales();
253         }
254     }
255
256     // end registry stuff
257

258     /**
259      * Return a hashcode for this currency.
260      * @stable ICU 2.2
261      */

262     public int hashCode() {
263         return isoCode.hashCode();
264     }
265
266     /**
267      * Return true if rhs is a Currency instance,
268      * is non-null, and has the same currency code.
269      * @stable ICU 2.2
270      */

271     public boolean equals(Object JavaDoc rhs) {
272         if (rhs == null) return false;
273         if (rhs == this) return true;
274         try {
275             Currency c = (Currency) rhs;
276             return isoCode.equals(c.isoCode);
277         }
278         catch (ClassCastException JavaDoc e) {
279             return false;
280         }
281     }
282
283     /**
284      * Returns the ISO 4217 3-letter code for this currency object.
285      * @stable ICU 2.2
286      */

287     public String JavaDoc getCurrencyCode() {
288         return isoCode;
289     }
290
291     /**
292      * Convenience and compatibility override of getName that
293      * requests the symbol name.
294      * @see #getName
295      * @draft ICU 3.4
296      * @provisional This API might change or be removed in a future release.
297      */

298     public String JavaDoc getSymbol() {
299     return getSymbol(ULocale.getDefault());
300     }
301
302     /**
303      * Convenience and compatibility override of getName that
304      * requests the symbol name.
305      * @param loc the Locale for the symbol
306      * @see #getName
307      * @draft ICU 3.4
308      * @provisional This API might change or be removed in a future release.
309      */

310     public String JavaDoc getSymbol(Locale JavaDoc loc) {
311     return getSymbol(ULocale.forLocale(loc));
312     }
313
314     /**
315      * Convenience and compatibility override of getName that
316      * requests the symbol name.
317      * @param uloc the ULocale for the symbol
318      * @see #getName
319      * @draft ICU 3.4
320      * @provisional This API might change or be removed in a future release.
321      */

322     public String JavaDoc getSymbol(ULocale uloc) {
323     return getName(uloc, SYMBOL_NAME, new boolean[1]);
324     }
325
326     /**
327      * Returns the display name for the given currency in the
328      * given locale. For example, the display name for the USD
329      * currency object in the en_US locale is "$".
330      * @param locale locale in which to display currency
331      * @param nameStyle selector for which kind of name to return
332      * @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
333      * if the returned value is a ChoiceFormat pattern; otherwise it
334      * is set to false
335      * @return display string for this currency. If the resource data
336      * contains no entry for this currency, then the ISO 4217 code is
337      * returned. If isChoiceFormat[0] is true, then the result is a
338      * ChoiceFormat pattern. Otherwise it is a static string.
339      * @draft ICU 3.2
340      * @provisional This API might change or be removed in a future release.
341      */

342     public String JavaDoc getName(Locale JavaDoc locale,
343                           int nameStyle,
344                           boolean[] isChoiceFormat) {
345     return getName(ULocale.forLocale(locale), nameStyle, isChoiceFormat);
346     }
347
348     /**
349      * Returns the display name for the given currency in the
350      * given locale. For example, the display name for the USD
351      * currency object in the en_US locale is "$".
352      * @param locale locale in which to display currency
353      * @param nameStyle selector for which kind of name to return
354      * @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
355      * if the returned value is a ChoiceFormat pattern; otherwise it
356      * is set to false
357      * @return display string for this currency. If the resource data
358      * contains no entry for this currency, then the ISO 4217 code is
359      * returned. If isChoiceFormat[0] is true, then the result is a
360      * ChoiceFormat pattern. Otherwise it is a static string.
361      * @draft ICU 3.2
362      * @provisional This API might change or be removed in a future release.
363      */

364     public String JavaDoc getName(ULocale locale,
365                           int nameStyle,
366                           boolean[] isChoiceFormat) {
367
368         // Look up the Currencies resource for the given locale. The
369
// Currencies locale data looks like this:
370
//|en {
371
//| Currencies {
372
//| USD { "US$", "US Dollar" }
373
//| CHF { "Sw F", "Swiss Franc" }
374
//| INR { "=0#Rs|1#Re|1<Rs", "=0#Rupees|1#Rupee|1<Rupees" }
375
//| //...
376
//| }
377
//|}
378

379         if (nameStyle < 0 || nameStyle > 1) {
380             throw new IllegalArgumentException JavaDoc();
381         }
382
383         String JavaDoc s = null;
384
385          try {
386             ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
387             ICUResourceBundle currencies = rb.get("Currencies");
388
389             // Fetch resource with multi-level resource inheritance fallback
390
s = currencies.getWithFallback(isoCode).getString(nameStyle);
391         }catch (MissingResourceException JavaDoc e) {
392             //TODO what should be done here?
393
}
394
395         // Determine if this is a ChoiceFormat pattern. One leading mark
396
// indicates a ChoiceFormat. Two indicates a static string that
397
// starts with a mark. In either case, the first mark is ignored,
398
// if present. Marks in the rest of the string have no special
399
// meaning.
400
isChoiceFormat[0] = false;
401         if (s != null) {
402             int i=0;
403             while (i < s.length() && s.charAt(i) == '=' && i < 2) {
404                 ++i;
405             }
406             isChoiceFormat[0]= (i == 1);
407             if (i != 0) {
408                 // Skip over first mark
409
s = s.substring(1);
410             }
411             return s;
412         }
413
414         // If we fail to find a match, use the ISO 4217 code
415
return isoCode;
416     }
417
418     /**
419      * Attempt to parse the given string as a currency, either as a
420      * display name in the given locale, or as a 3-letter ISO 4217
421      * code. If multiple display names match, then the longest one is
422      * selected. If both a display name and a 3-letter ISO code
423      * match, then the display name is preferred, unless it's length
424      * is less than 3.
425      *
426      * @param locale the locale of the display names to match
427      * @param text the text to parse
428      * @param pos input-output position; on input, the position within
429      * text to match; must have 0 <= pos.getIndex() < text.length();
430      * on output, the position after the last matched character. If
431      * the parse fails, the position in unchanged upon output.
432      * @return the ISO 4217 code, as a string, of the best match, or
433      * null if there is no match
434      *
435      * @internal
436      * @deprecated This API is ICU internal only.
437      */

438     public static String JavaDoc parse(ULocale locale, String JavaDoc text, ParsePosition JavaDoc pos) {
439
440         // TODO: There is a slight problem with the pseudo-multi-level
441
// fallback implemented here. More-specific locales don't
442
// properly shield duplicate entries in less-specific locales.
443
// This problem will go away when real multi-level fallback is
444
// implemented. We could also fix this by recording (in a
445
// hash) which codes are used at each level of fallback, but
446
// this doesn't seem warranted.
447

448         int start = pos.getIndex();
449         String JavaDoc fragment = text.substring(start);
450
451         String JavaDoc iso = null;
452         int max = 0;
453
454         // Look up the Currencies resource for the given locale. The
455
// Currencies locale data looks like this:
456
//|en {
457
//| Currencies {
458
//| USD { "US$", "US Dollar" }
459
//| CHF { "Sw F", "Swiss Franc" }
460
//| INR { "=0#Rs|1#Re|1<Rs", "=0#Rupees|1#Rupee|1<Rupees" }
461
//| //...
462
//| }
463
//|}
464

465         // In the future, resource bundles may implement multi-level
466
// fallback. That is, if a currency is not found in the en_US
467
// Currencies data, then the en Currencies data will be searched.
468
// Currently, if a Currencies datum exists in en_US and en, the
469
// en_US entry hides that in en.
470

471         // We want multi-level fallback for this resource, so we implement
472
// it manually.
473

474         // Multi-level resource inheritance fallback loop
475

476         while (locale != null) {
477             ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
478             // We can't cast this to String[][]; the cast has to happen later
479

480             try {
481                 ICUResourceBundle currencies = rb.get("Currencies");
482                 // Do a linear search
483
for (int i=0; i<currencies.getSize(); ++i) {
484                     //String name = ((String[]) currencies[i][1])[0];
485
ICUResourceBundle item = currencies.get(i);
486                     String JavaDoc name = item.getString(0);
487                     if (name.length() < 1) {
488                         // Ignore zero-length names -- later, change this
489
// when zero-length is used to mean something.
490
continue;
491                     } else if (name.charAt(0) == '=') {
492                         name = name.substring(1);
493                         if (name.length() > 0 && name.charAt(0) != '=') {
494                             ChoiceFormat JavaDoc choice = new ChoiceFormat JavaDoc(name);
495                             // Number n =
496
choice.parse(text, pos);
497                             int len = pos.getIndex() - start;
498                             if (len > max) {
499                                 iso = item.getKey();
500                                 max = len;
501                             }
502                             pos.setIndex(start);
503                             continue;
504                         }
505                     }
506                     if (name.length() > max && fragment.startsWith(name)) {
507                         iso = item.getKey();
508                         max = name.length();
509                     }
510                 }
511             }
512             catch (MissingResourceException JavaDoc e) {}
513
514             locale = locale.getFallback();
515         }
516
517         /*
518         1. Look at the Currencies array from the locale
519             1a. Iterate through it, and check each row to see if row[1] matches
520                 1a1. If row[1] is a pattern, use ChoiceFormat to attempt a parse
521             1b. Upon a match, return the ISO code stored at row[0]
522         2. If there is no match, fall back to "en" and try again
523         3. If there is no match, fall back to root and try again
524         4. If still no match, parse 3-letter ISO {this code is probably unchanged}.
525
526         ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, locale);
527         ICUResourceBundle currencies = rb.get("Currencies");
528         */

529         // If display name parse fails or if it matches fewer than 3
530
// characters, try to parse 3-letter ISO. Do this after the
531
// display name processing so 3-letter display names are
532
// preferred. Consider /[A-Z]{3}/ to be valid ISO, and parse
533
// it manually--UnicodeSet/regex are too slow and heavy.
534
if (max < 3 && (text.length() - start) >= 3) {
535             boolean valid = true;
536             for (int k=0; k<3; ++k) {
537                 char ch = text.charAt(start + k); // 16-bit ok
538
if (ch < 'A' || ch > 'Z') {
539                     valid = false;
540                     break;
541                 }
542             }
543             if (valid) {
544                 iso = text.substring(start, start+3);
545                 max = 3;
546             }
547         }
548
549         pos.setIndex(start + max);
550         return iso;
551     }
552
553     /**
554      * Returns the number of the number of fraction digits that should
555      * be displayed for this currency.
556      * @return a non-negative number of fraction digits to be
557      * displayed
558      * @stable ICU 2.2
559      */

560     public int getDefaultFractionDigits() {
561         return (findData())[0];
562     }
563
564     /**
565      * Returns the rounding increment for this currency, or 0.0 if no
566      * rounding is done by this currency.
567      * @return the non-negative rounding increment, or 0.0 if none
568      * @stable ICU 2.2
569      */

570     public double getRoundingIncrement() {
571         int[] data = findData();
572
573         int data1 = data[1]; // rounding increment
574

575         // If there is no rounding return 0.0 to indicate no rounding.
576
// This is the high-runner case, by far.
577
if (data1 == 0) {
578             return 0.0;
579         }
580
581         int data0 = data[0]; // fraction digits
582

583         // If the meta data is invalid, return 0.0 to indicate no rounding.
584
if (data0 < 0 || data0 >= POW10.length) {
585             return 0.0;
586         }
587
588         // Return data[1] / 10^(data[0]). The only actual rounding data,
589
// as of this writing, is CHF { 2, 25 }.
590
return (double) data1 / POW10[data0];
591     }
592
593     /**
594      * Returns the ISO 4217 code for this currency.
595      * @stable ICU 2.2
596      */

597     public String JavaDoc toString() {
598         return isoCode;
599     }
600
601     /**
602      * Constructs a currency object for the given ISO 4217 3-letter
603      * code. This constructor assumes that the code is valid.
604      *
605      * @param theISOCode The iso code used to construct the currency.
606      * @draft ICU 3.4
607      * @provisional This API might change or be removed in a future release.
608      */

609     protected Currency(String JavaDoc theISOCode) {
610         isoCode = theISOCode;
611     }
612
613     /**
614      * Internal function to look up currency data. Result is an array of
615      * two Integers. The first is the fraction digits. The second is the
616      * rounding increment, or 0 if none. The rounding increment is in
617      * units of 10^(-fraction_digits).
618      */

619     private int[] findData() {
620
621         try {
622             // Get CurrencyMeta resource out of root locale file. [This may
623
// move out of the root locale file later; if it does, update this
624
// code.]
625
ICUResourceBundle root = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"CurrencyData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
626             ICUResourceBundle currencyMeta = root.get("CurrencyMeta");
627
628             //Integer[] i = null;
629
//int defaultPos = -1;
630
int[] i = currencyMeta.get(isoCode).getIntVector();
631
632             // Do a linear search for isoCode. At the same time,
633
// record the position of the DEFAULT meta data. If the
634
// meta data becomes large, make this faster.
635
/*for (int j=0; j<currencyMeta.length; ++j) {
636                 Object[] row = currencyMeta[j];
637                 String s = (String) row[0];
638                 int c = isoCode.compareToIgnoreCase(s);
639                 if (c == 0) {
640                     i = (Integer[]) row[1];
641                     break;
642                 }
643                 if ("DEFAULT".equalsIgnoreCase(s)) {
644                     defaultPos = j;
645                 }
646                 if (c < 0 && defaultPos >= 0) {
647                     break;
648                 }
649             }
650             */

651             if (i == null) {
652                 i = currencyMeta.get("DEFAULT").getIntVector();
653             }
654
655             if (i != null && i.length >= 2) {
656                 return i;
657             }
658         }
659         catch (MissingResourceException JavaDoc e) {}
660
661         // Config/build error; return hard-coded defaults
662
return LAST_RESORT_DATA;
663     }
664
665     // Default currency meta data of last resort. We try to use the
666
// defaults encoded in the meta data resource bundle. If there is a
667
// configuration/build error and these are not available, we use these
668
// hard-coded defaults (which should be identical).
669
private static final int[] LAST_RESORT_DATA = new int[] { 2, 0 };
670
671     // POW10[i] = 10^i
672
private static final int[] POW10 = { 1, 10, 100, 1000, 10000, 100000,
673                                 1000000, 10000000, 100000000, 1000000000 };
674
675     // -------- BEGIN ULocale boilerplate --------
676

677     /**
678      * Return the locale that was used to create this object, or null.
679      * This may may differ from the locale requested at the time of
680      * this object's creation. For example, if an object is created
681      * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
682      * drawn from <tt>en</tt> (the <i>actual</i> locale), and
683      * <tt>en_US</tt> may be the most specific locale that exists (the
684      * <i>valid</i> locale).
685      *
686      * <p>Note: This method will be obsoleted. The implementation is
687      * no longer locale-specific and so there is no longer a valid or
688      * actual locale associated with the Currency object. Until
689      * it is removed, this method will return the root locale.
690      * @param type type of information requested, either {@link
691      * com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
692      * com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
693      * @return the information specified by <i>type</i>, or null if
694      * this object was not constructed from locale data.
695      * @see com.ibm.icu.util.ULocale
696      * @see com.ibm.icu.util.ULocale#VALID_LOCALE
697      * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
698      * @obsolete ICU 3.2 to be removed
699      * @deprecated This API is obsolete.
700      */

701     public final ULocale getLocale(ULocale.Type type) {
702     return ULocale.ROOT;
703     }
704
705     /**
706      * Set information about the locales that were used to create this
707      * object. If the object was not constructed from locale data,
708      * both arguments should be set to null. Otherwise, neither
709      * should be null. The actual locale must be at the same level or
710      * less specific than the valid locale. This method is intended
711      * for use by factories or other entities that create objects of
712      * this class.
713      * @param valid the most specific locale containing any resource
714      * data, or null
715      * @param actual the locale containing data used to construct this
716      * object, or null
717      * @see com.ibm.icu.util.ULocale
718      * @see com.ibm.icu.util.ULocale#VALID_LOCALE
719      * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
720      * @internal
721      * @deprecated This API is ICU internal only.
722      */

723     final void setLocale(ULocale valid, ULocale actual) {
724         // Change the following to an assertion later
725
if ((valid == null) != (actual == null)) {
726             ///CLOVER:OFF
727
throw new IllegalArgumentException JavaDoc();
728             ///CLOVER:ON
729
}
730         // Another check we could do is that the actual locale is at
731
// the same level or less specific than the valid locale.
732
this.validLocale = valid;
733         this.actualLocale = actual;
734     }
735
736     /**
737      * The most specific locale containing any resource data, or null.
738      * @see com.ibm.icu.util.ULocale
739      * @internal
740      * @deprecated This API is ICU internal only.
741      */

742     private ULocale validLocale;
743
744     /**
745      * The locale containing data used to construct this object, or
746      * null.
747      * @see com.ibm.icu.util.ULocale
748      * @internal
749      * @deprecated This API is ICU internal only.
750      */

751     private ULocale actualLocale;
752
753     // -------- END ULocale boilerplate --------
754
}
755
756 //eof
757
Popular Tags