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