ICU-2202 getLocale for NumberFormat and Calendar
X-SVN-Rev: 13808
This commit is contained in:
parent
91d46c9250
commit
f36be0e1b3
@ -5,14 +5,15 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/DecimalFormat.java,v $
|
||||
* $Date: 2003/10/29 00:20:03 $
|
||||
* $Revision: 1.37 $
|
||||
* $Date: 2003/11/21 08:11:49 $
|
||||
* $Revision: 1.38 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.impl.UCharacterProperty;
|
||||
import java.text.ParsePosition;
|
||||
@ -3466,6 +3467,15 @@ public class DecimalFormat extends NumberFormat {
|
||||
super.setMinimumFractionDigits(Math.min(newValue, DOUBLE_FRACTION_DIGITS));
|
||||
}
|
||||
|
||||
/** Get the locale for this decimal format object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @return the locale
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public ULocale getLocale(ULocale.ULocaleDataType type) {
|
||||
return symbols.getLocale(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* First, read the default serializable fields from the stream. Then
|
||||
* if <code>serialVersionOnStream</code> is less than 1, indicating that
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/DecimalFormatSymbols.java,v $
|
||||
* $Date: 2003/06/03 18:49:34 $
|
||||
* $Revision: 1.11 $
|
||||
* $Date: 2003/11/21 08:11:49 $
|
||||
* $Revision: 1.12 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -14,6 +14,8 @@ package com.ibm.icu.text;
|
||||
|
||||
import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
@ -482,6 +484,9 @@ final public class DecimalFormatSymbols implements Cloneable, Serializable {
|
||||
cachedLocaleData.put(locale, data);
|
||||
}
|
||||
numberElements = data[0];
|
||||
|
||||
ResourceBundle r = ICULocaleData.getLocaleElements(locale);
|
||||
validLocale = new ULocale(r.getLocale());
|
||||
|
||||
// {dlf} clean up below now that we have our own resource data
|
||||
decimalSeparator = numberElements[0].charAt(0);
|
||||
@ -751,4 +756,11 @@ final public class DecimalFormatSymbols implements Cloneable, Serializable {
|
||||
* cache to hold the NumberElements of a Locale.
|
||||
*/
|
||||
private static final Hashtable cachedLocaleData = new Hashtable(3);
|
||||
|
||||
private ULocale validLocale;
|
||||
|
||||
ULocale getLocale(ULocale.ULocaleDataType type) {
|
||||
return (ULocale)validLocale.clone();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/NumberFormat.java,v $
|
||||
* $Date: 2003/11/14 23:45:01 $
|
||||
* $Revision: 1.31 $
|
||||
* $Date: 2003/11/21 08:11:49 $
|
||||
* $Revision: 1.32 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -917,13 +917,14 @@ public abstract class NumberFormat extends UFormat {
|
||||
return currency;
|
||||
}
|
||||
|
||||
|
||||
/** Get the locale for this date format object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @return the locale
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public ULocale getLocale(ULocale.ULocaleDataType type) {
|
||||
return new ULocale("");
|
||||
return new ULocale(Locale.getDefault());
|
||||
}
|
||||
|
||||
// =======================privates===============================
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java,v $
|
||||
* $Date: 2003/06/03 18:49:35 $
|
||||
* $Revision: 1.16 $
|
||||
* $Date: 2003/11/21 08:11:49 $
|
||||
* $Revision: 1.17 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -15,6 +15,7 @@ package com.ibm.icu.text;
|
||||
|
||||
import com.ibm.icu.impl.ICULocaleData;
|
||||
import com.ibm.icu.impl.UCharacterProperty;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.text.FieldPosition;
|
||||
@ -474,7 +475,7 @@ import java.util.ResourceBundle;
|
||||
* using these features.</p>
|
||||
*
|
||||
* @author Richard Gillam
|
||||
* $RCSfile: RuleBasedNumberFormat.java,v $ $Revision: 1.16 $ $Date: 2003/06/03 18:49:35 $
|
||||
* $RCSfile: RuleBasedNumberFormat.java,v $ $Revision: 1.17 $ $Date: 2003/11/21 08:11:49 $
|
||||
* @see NumberFormat
|
||||
* @see DecimalFormat
|
||||
* @stable ICU 2.0
|
||||
@ -555,6 +556,8 @@ public final class RuleBasedNumberFormat extends NumberFormat {
|
||||
*/
|
||||
private String lenientParseRules = null;
|
||||
|
||||
private ULocale validLocale;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// constructors
|
||||
//-----------------------------------------------------------------------
|
||||
@ -609,6 +612,7 @@ public final class RuleBasedNumberFormat extends NumberFormat {
|
||||
// from the specified locale
|
||||
// ResourceBundle bundle = ICULocaleData.getResourceBundle("NumberFormatRules", locale);
|
||||
ResourceBundle bundle = ICULocaleData.getResourceBundle("LocaleElements", locale);
|
||||
validLocale = new ULocale(bundle.getLocale());
|
||||
String description = "";
|
||||
|
||||
// pick a description from the resource bundle based on the
|
||||
@ -1109,6 +1113,7 @@ public final class RuleBasedNumberFormat extends NumberFormat {
|
||||
* in the class docs.
|
||||
*/
|
||||
private void init(String description) {
|
||||
validLocale = new ULocale(Locale.getDefault());
|
||||
// start by stripping the trailing whitespace from all the rules
|
||||
// (this is all the whitespace follwing each semicolon in the
|
||||
// description). This allows us to look for rule-set boundaries
|
||||
@ -1334,5 +1339,14 @@ public final class RuleBasedNumberFormat extends NumberFormat {
|
||||
}
|
||||
throw new IllegalArgumentException("No rule set named " + name);
|
||||
}
|
||||
/** Get the locale for this date format object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @return the locale
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public ULocale getLocale(ULocale.ULocaleDataType type) {
|
||||
return (ULocale)validLocale.clone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1591,14 +1591,17 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
factory = (CalendarFactory)getFactoryMap().get(factoryName);
|
||||
}
|
||||
|
||||
if (factory == null && service != null) {
|
||||
factory = (CalendarFactory)service.get(locale);
|
||||
Locale[] actualReturn = new Locale[1];
|
||||
if (factory == null && service != null) {
|
||||
factory = (CalendarFactory)service.get(locale, actualReturn);
|
||||
}
|
||||
|
||||
if (factory == null) {
|
||||
return new GregorianCalendar(zone, locale);
|
||||
} else {
|
||||
return factory.create(zone, locale);
|
||||
Calendar result = factory.create(zone, locale);
|
||||
result.validLocale = new ULocale(actualReturn[0]);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
///CLOVER:ON
|
||||
@ -3586,6 +3589,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
private void setWeekendData(Locale loc) {
|
||||
ResourceBundle resource =
|
||||
ICULocaleData.getResourceBundle("CalendarData", loc);
|
||||
validLocale = new ULocale(resource.getLocale());
|
||||
String[] data = resource.getStringArray("Weekend");
|
||||
weekendOnset = Integer.parseInt(data[0]);
|
||||
weekendOnsetMillis = Integer.parseInt(data[1]);
|
||||
@ -3597,13 +3601,15 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
// End of weekend support
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
private ULocale validLocale;
|
||||
|
||||
/** Get the locale for this calendar object. You can choose between valid and actual locale.
|
||||
* @param type type of the locale we're looking for (valid or actual)
|
||||
* @return the locale
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public ULocale getLocale(ULocale.ULocaleDataType type) {
|
||||
return new ULocale("");
|
||||
return (ULocale)validLocale.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,8 +5,8 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/util/ULocale.java,v $
|
||||
* $Date: 2003/11/21 00:16:06 $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2003/11/21 08:11:49 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@ -22,9 +22,11 @@ import java.util.Locale;
|
||||
* @author weiv
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public class ULocale {
|
||||
public class ULocale implements Cloneable {
|
||||
/**
|
||||
* Actual locale where data is coming from
|
||||
* Actual locale will make sense only after the alternate
|
||||
* ICU data handling framework is implemented in ICU 3.0
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public static final ULocaleDataType ACTUAL_LOCALE = new ULocaleDataType(0);
|
||||
@ -79,4 +81,19 @@ public class ULocale {
|
||||
public ULocale(String locName) {
|
||||
locale = new Locale(locName, "");
|
||||
}
|
||||
/**
|
||||
* Clone method. Clones this ULocale object
|
||||
* @return cloned ULocale object.
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
public Object clone() {
|
||||
try {
|
||||
ULocale copy = (ULocale) super.clone();
|
||||
copy.locale = (Locale) locale.clone();
|
||||
return copy;
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
throw new InternalError(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user