mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-10574 Add API (getter/setter) to set capitalization context for NumberFormat, J
X-SVN-Rev: 34899
This commit is contained in:
parent
d6eb092438
commit
d894ab3a4f
2 changed files with 52 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2013, International Business Machines Corporation and *
|
||||
* Copyright (C) 1996-2014, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ import java.util.MissingResourceException;
|
|||
import java.util.Set;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.text.DisplayContext;
|
||||
import com.ibm.icu.util.Currency;
|
||||
import com.ibm.icu.util.CurrencyAmount;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
@ -498,6 +499,34 @@ public abstract class NumberFormat extends UFormat {
|
|||
return parseStrict;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@icu} Set a particular DisplayContext value in the formatter,
|
||||
* such as CAPITALIZATION_FOR_STANDALONE.
|
||||
*
|
||||
* @param context The DisplayContext value to set.
|
||||
* @draft ICU 53
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public void setContext(DisplayContext context) {
|
||||
if (context.type() == DisplayContext.Type.CAPITALIZATION) {
|
||||
capitalizationSetting = context;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@icu} Get the formatter's DisplayContext value for the specified DisplayContext.Type,
|
||||
* such as CAPITALIZATION.
|
||||
*
|
||||
* @param type the DisplayContext.Type whose value to return
|
||||
* @return the current DisplayContext setting for the specified type
|
||||
* @draft ICU 53
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public DisplayContext getContext(DisplayContext.Type type) {
|
||||
return (type == DisplayContext.Type.CAPITALIZATION && capitalizationSetting != null)?
|
||||
capitalizationSetting: DisplayContext.CAPITALIZATION_NONE;
|
||||
}
|
||||
|
||||
//============== Locale Stuff =====================
|
||||
|
||||
/**
|
||||
|
@ -1686,7 +1715,7 @@ public abstract class NumberFormat extends UFormat {
|
|||
private static final long serialVersionUID = -2308460125733713944L;
|
||||
|
||||
/**
|
||||
* Empty constructor. Public for compatibily with JDK which lets the
|
||||
* Empty constructor. Public for compatibility with JDK which lets the
|
||||
* compiler generate a default public constructor even though this is
|
||||
* an abstract class.
|
||||
* @stable ICU 2.6
|
||||
|
@ -1697,6 +1726,11 @@ public abstract class NumberFormat extends UFormat {
|
|||
// new in ICU4J 3.6
|
||||
private boolean parseStrict;
|
||||
|
||||
/*
|
||||
* Capitalization setting, new in ICU 53
|
||||
*/
|
||||
private transient DisplayContext capitalizationSetting = DisplayContext.CAPITALIZATION_NONE;
|
||||
|
||||
/**
|
||||
* The instances of this inner class are used as attribute keys and values
|
||||
* in AttributedCharacterIterator that
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001-2013, International Business Machines Corporation and *
|
||||
* Copyright (C) 2001-2014, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -29,6 +29,7 @@ import com.ibm.icu.math.BigDecimal;
|
|||
import com.ibm.icu.math.MathContext;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.text.DisplayContext;
|
||||
import com.ibm.icu.text.MeasureFormat;
|
||||
import com.ibm.icu.text.NumberFormat;
|
||||
import com.ibm.icu.text.NumberFormat.NumberFormatFactory;
|
||||
|
@ -3569,4 +3570,18 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TestContext() {
|
||||
// just a minimal sanity check for now
|
||||
NumberFormat nfmt = NumberFormat.getInstance();
|
||||
DisplayContext context = nfmt.getContext(DisplayContext.Type.CAPITALIZATION);
|
||||
if (context != DisplayContext.CAPITALIZATION_NONE) {
|
||||
errln("FAIL: Initial NumberFormat.getContext() is not CAPITALIZATION_NONE");
|
||||
}
|
||||
nfmt.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
|
||||
context = nfmt.getContext(DisplayContext.Type.CAPITALIZATION);
|
||||
if (context != DisplayContext.CAPITALIZATION_FOR_STANDALONE) {
|
||||
errln("FAIL: NumberFormat.getContext() does not return the value set, CAPITALIZATION_FOR_STANDALONE");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue