src/java.base/share/classes/java/text/ChoiceFormat.java
changeset 58288 48e480e56aad
parent 58242 94bb65cb37d3
child 58679 9c3209ff7550
equal deleted inserted replaced
58287:a7f16447085e 58288:48e480e56aad
    42 import java.io.IOException;
    42 import java.io.IOException;
    43 import java.io.ObjectInputStream;
    43 import java.io.ObjectInputStream;
    44 import java.util.Arrays;
    44 import java.util.Arrays;
    45 
    45 
    46 /**
    46 /**
    47  * A <code>ChoiceFormat</code> allows you to attach a format to a range of numbers.
    47  * A {@code ChoiceFormat} allows you to attach a format to a range of numbers.
    48  * It is generally used in a <code>MessageFormat</code> for handling plurals.
    48  * It is generally used in a {@code MessageFormat} for handling plurals.
    49  * The choice is specified with an ascending list of doubles, where each item
    49  * The choice is specified with an ascending list of doubles, where each item
    50  * specifies a half-open interval up to the next item:
    50  * specifies a half-open interval up to the next item:
    51  * <blockquote>
    51  * <blockquote>
    52  * <pre>
    52  * <pre>
    53  * X matches j if and only if limit[j] &le; X &lt; limit[j+1]
    53  * X matches j if and only if limit[j] &le; X &lt; limit[j+1]
    58  * in ascending order, the results of formatting will be incorrect.  ChoiceFormat
    58  * in ascending order, the results of formatting will be incorrect.  ChoiceFormat
    59  * also accepts <code>&#92;u221E</code> as equivalent to infinity(INF).
    59  * also accepts <code>&#92;u221E</code> as equivalent to infinity(INF).
    60  *
    60  *
    61  * <p>
    61  * <p>
    62  * <strong>Note:</strong>
    62  * <strong>Note:</strong>
    63  * <code>ChoiceFormat</code> differs from the other <code>Format</code>
    63  * {@code ChoiceFormat} differs from the other {@code Format}
    64  * classes in that you create a <code>ChoiceFormat</code> object with a
    64  * classes in that you create a {@code ChoiceFormat} object with a
    65  * constructor (not with a <code>getInstance</code> style factory
    65  * constructor (not with a {@code getInstance} style factory
    66  * method). The factory methods aren't necessary because <code>ChoiceFormat</code>
    66  * method). The factory methods aren't necessary because {@code ChoiceFormat}
    67  * doesn't require any complex setup for a given locale. In fact,
    67  * doesn't require any complex setup for a given locale. In fact,
    68  * <code>ChoiceFormat</code> doesn't implement any locale specific behavior.
    68  * {@code ChoiceFormat} doesn't implement any locale specific behavior.
    69  *
    69  *
    70  * <p>
    70  * <p>
    71  * When creating a <code>ChoiceFormat</code>, you must specify an array of formats
    71  * When creating a {@code ChoiceFormat}, you must specify an array of formats
    72  * and an array of limits. The length of these arrays must be the same.
    72  * and an array of limits. The length of these arrays must be the same.
    73  * For example,
    73  * For example,
    74  * <ul>
    74  * <ul>
    75  * <li>
    75  * <li>
    76  *     <em>limits</em> = {1,2,3,4,5,6,7}<br>
    76  *     <em>limits</em> = {1,2,3,4,5,6,7}<br>
    77  *     <em>formats</em> = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}
    77  *     <em>formats</em> = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}
    78  * <li>
    78  * <li>
    79  *     <em>limits</em> = {0, 1, ChoiceFormat.nextDouble(1)}<br>
    79  *     <em>limits</em> = {0, 1, ChoiceFormat.nextDouble(1)}<br>
    80  *     <em>formats</em> = {"no files", "one file", "many files"}<br>
    80  *     <em>formats</em> = {"no files", "one file", "many files"}<br>
    81  *     (<code>nextDouble</code> can be used to get the next higher double, to
    81  *     ({@code nextDouble} can be used to get the next higher double, to
    82  *     make the half-open interval.)
    82  *     make the half-open interval.)
    83  * </ul>
    83  * </ul>
    84  *
    84  *
    85  * <p>
    85  * <p>
    86  * Here is a simple example that shows formatting and parsing:
    86  * Here is a simple example that shows formatting and parsing:
   379 
   379 
   380     // Overrides
   380     // Overrides
   381 
   381 
   382     /**
   382     /**
   383      * Specialization of format. This method really calls
   383      * Specialization of format. This method really calls
   384      * <code>format(double, StringBuffer, FieldPosition)</code>
   384      * {@code format(double, StringBuffer, FieldPosition)}
   385      * thus the range of longs that are supported is only equal to
   385      * thus the range of longs that are supported is only equal to
   386      * the range that can be stored by double. This will never be
   386      * the range that can be stored by double. This will never be
   387      * a practical limitation.
   387      * a practical limitation.
   388      */
   388      */
   389     public StringBuffer format(long number, StringBuffer toAppendTo,
   389     public StringBuffer format(long number, StringBuffer toAppendTo,
   540 
   540 
   541     // ===============privates===========================
   541     // ===============privates===========================
   542 
   542 
   543     /**
   543     /**
   544      * A list of lower bounds for the choices.  The formatter will return
   544      * A list of lower bounds for the choices.  The formatter will return
   545      * <code>choiceFormats[i]</code> if the number being formatted is greater than or equal to
   545      * {@code choiceFormats[i]} if the number being formatted is greater than or equal to
   546      * <code>choiceLimits[i]</code> and less than <code>choiceLimits[i+1]</code>.
   546      * {@code choiceLimits[i]} and less than {@code choiceLimits[i+1]}.
   547      * @serial
   547      * @serial
   548      */
   548      */
   549     private double[] choiceLimits;
   549     private double[] choiceLimits;
   550 
   550 
   551     /**
   551     /**
   552      * A list of choice strings.  The formatter will return
   552      * A list of choice strings.  The formatter will return
   553      * <code>choiceFormats[i]</code> if the number being formatted is greater than or equal to
   553      * {@code choiceFormats[i]} if the number being formatted is greater than or equal to
   554      * <code>choiceLimits[i]</code> and less than <code>choiceLimits[i+1]</code>.
   554      * {@code choiceLimits[i]} and less than {@code choiceLimits[i+1]}.
   555      * @serial
   555      * @serial
   556      */
   556      */
   557     private String[] choiceFormats;
   557     private String[] choiceFormats;
   558 
   558 
   559     /**
   559     /**