src/java.base/share/classes/java/text/ChoiceFormat.java
changeset 58242 94bb65cb37d3
parent 57956 e0b8b019d2f5
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
   172     private static final long serialVersionUID = 1795184449645032964L;
   172     private static final long serialVersionUID = 1795184449645032964L;
   173 
   173 
   174     /**
   174     /**
   175      * Sets the pattern.
   175      * Sets the pattern.
   176      * @param newPattern See the class description.
   176      * @param newPattern See the class description.
   177      * @exception NullPointerException if {@code newPattern}
   177      * @throws    NullPointerException if {@code newPattern}
   178      *            is {@code null}
   178      *            is {@code null}
   179      */
   179      */
   180     public void applyPattern(String newPattern) {
   180     public void applyPattern(String newPattern) {
   181         StringBuffer[] segments = new StringBuffer[2];
   181         StringBuffer[] segments = new StringBuffer[2];
   182         for (int i = 0; i < segments.length; ++i) {
   182         for (int i = 0; i < segments.length; ++i) {
   311 
   311 
   312     /**
   312     /**
   313      * Constructs with limits and corresponding formats based on the pattern.
   313      * Constructs with limits and corresponding formats based on the pattern.
   314      *
   314      *
   315      * @param newPattern the new pattern string
   315      * @param newPattern the new pattern string
   316      * @exception NullPointerException if {@code newPattern} is
   316      * @throws    NullPointerException if {@code newPattern} is
   317      *            {@code null}
   317      *            {@code null}
   318      * @see #applyPattern
   318      * @see #applyPattern
   319      */
   319      */
   320     public ChoiceFormat(String newPattern)  {
   320     public ChoiceFormat(String newPattern)  {
   321         applyPattern(newPattern);
   321         applyPattern(newPattern);
   324     /**
   324     /**
   325      * Constructs with the limits and the corresponding formats.
   325      * Constructs with the limits and the corresponding formats.
   326      *
   326      *
   327      * @param limits limits in ascending order
   327      * @param limits limits in ascending order
   328      * @param formats corresponding format strings
   328      * @param formats corresponding format strings
   329      * @exception NullPointerException if {@code limits} or {@code formats}
   329      * @throws    NullPointerException if {@code limits} or {@code formats}
   330      *            is {@code null}
   330      *            is {@code null}
   331      * @see #setChoices
   331      * @see #setChoices
   332      */
   332      */
   333     public ChoiceFormat(double[] limits, String[] formats) {
   333     public ChoiceFormat(double[] limits, String[] formats) {
   334         setChoices(limits, formats);
   334         setChoices(limits, formats);
   345      * @param formats are the formats you want to use for each limit.
   345      * @param formats are the formats you want to use for each limit.
   346      * They can be either Format objects or Strings.
   346      * They can be either Format objects or Strings.
   347      * When formatting with object Y,
   347      * When formatting with object Y,
   348      * if the object is a NumberFormat, then ((NumberFormat) Y).format(X)
   348      * if the object is a NumberFormat, then ((NumberFormat) Y).format(X)
   349      * is called. Otherwise Y.toString() is called.
   349      * is called. Otherwise Y.toString() is called.
   350      * @exception NullPointerException if {@code limits} or
   350      * @throws    NullPointerException if {@code limits} or
   351      *            {@code formats} is {@code null}
   351      *            {@code formats} is {@code null}
   352      */
   352      */
   353     public void setChoices(double[] limits, String formats[]) {
   353     public void setChoices(double[] limits, String formats[]) {
   354         if (limits.length != formats.length) {
   354         if (limits.length != formats.length) {
   355             throw new IllegalArgumentException(
   355             throw new IllegalArgumentException(
   394     /**
   394     /**
   395      * Returns pattern with formatted double.
   395      * Returns pattern with formatted double.
   396      * @param number number to be formatted and substituted.
   396      * @param number number to be formatted and substituted.
   397      * @param toAppendTo where text is appended.
   397      * @param toAppendTo where text is appended.
   398      * @param status ignore no useful status is returned.
   398      * @param status ignore no useful status is returned.
   399      * @exception NullPointerException if {@code toAppendTo}
   399      * @throws    NullPointerException if {@code toAppendTo}
   400      *            is {@code null}
   400      *            is {@code null}
   401      */
   401      */
   402    public StringBuffer format(double number, StringBuffer toAppendTo,
   402    public StringBuffer format(double number, StringBuffer toAppendTo,
   403                                FieldPosition status) {
   403                                FieldPosition status) {
   404         // find the number
   404         // find the number
   424      * occurred, status.index is set to the first unparsed character
   424      * occurred, status.index is set to the first unparsed character
   425      * in the source text.  On exit, if an error did occur,
   425      * in the source text.  On exit, if an error did occur,
   426      * status.index is unchanged and status.errorIndex is set to the
   426      * status.index is unchanged and status.errorIndex is set to the
   427      * first index of the character that caused the parse to fail.
   427      * first index of the character that caused the parse to fail.
   428      * @return A Number representing the value of the number parsed.
   428      * @return A Number representing the value of the number parsed.
   429      * @exception NullPointerException if {@code status} is {@code null}
   429      * @throws    NullPointerException if {@code status} is {@code null}
   430      *            or if {@code text} is {@code null} and the list of
   430      *            or if {@code text} is {@code null} and the list of
   431      *            choice strings is not empty.
   431      *            choice strings is not empty.
   432      */
   432      */
   433     public Number parse(String text, ParsePosition status) {
   433     public Number parse(String text, ParsePosition status) {
   434         // find the best number (defined as the one with the longest parse)
   434         // find the best number (defined as the one with the longest parse)