< prev index next >

src/java.base/share/classes/java/text/ChoiceFormat.java

Print this page




 332     public ChoiceFormat(double[] limits, String[] formats) {
 333         setChoices(limits, formats);
 334     }
 335 
 336     /**
 337      * Set the choices to be used in formatting.
 338      * @param limits contains the top value that you want
 339      * parsed with that format, and should be in ascending sorted order. When
 340      * formatting X, the choice will be the i, where
 341      * limit[i] &le; X {@literal <} limit[i+1].
 342      * If the limit array is not in ascending order, the results of formatting
 343      * will be incorrect.
 344      * @param formats are the formats you want to use for each limit.
 345      * They can be either Format objects or Strings.
 346      * When formatting with object Y,
 347      * if the object is a NumberFormat, then ((NumberFormat) Y).format(X)
 348      * is called. Otherwise Y.toString() is called.
 349      * @exception NullPointerException if {@code limits} or
 350      *            {@code formats} is {@code null}
 351      */
 352     public void setChoices(double[] limits, String formats[]) {
 353         if (limits.length != formats.length) {
 354             throw new IllegalArgumentException(
 355                 "Array and limit arrays must be of the same length.");
 356         }
 357         choiceLimits = Arrays.copyOf(limits, limits.length);
 358         choiceFormats = Arrays.copyOf(formats, formats.length);
 359     }
 360 
 361     /**
 362      * Get the limits passed in the constructor.
 363      * @return the limits.
 364      */
 365     public double[] getLimits() {
 366         double[] newLimits = Arrays.copyOf(choiceLimits, choiceLimits.length);
 367         return newLimits;
 368     }
 369 
 370     /**
 371      * Get the formats passed in the constructor.
 372      * @return the formats.




 332     public ChoiceFormat(double[] limits, String[] formats) {
 333         setChoices(limits, formats);
 334     }
 335 
 336     /**
 337      * Set the choices to be used in formatting.
 338      * @param limits contains the top value that you want
 339      * parsed with that format, and should be in ascending sorted order. When
 340      * formatting X, the choice will be the i, where
 341      * limit[i] &le; X {@literal <} limit[i+1].
 342      * If the limit array is not in ascending order, the results of formatting
 343      * will be incorrect.
 344      * @param formats are the formats you want to use for each limit.
 345      * They can be either Format objects or Strings.
 346      * When formatting with object Y,
 347      * if the object is a NumberFormat, then ((NumberFormat) Y).format(X)
 348      * is called. Otherwise Y.toString() is called.
 349      * @exception NullPointerException if {@code limits} or
 350      *            {@code formats} is {@code null}
 351      */
 352     public void setChoices(double[] limits, String[] formats) {
 353         if (limits.length != formats.length) {
 354             throw new IllegalArgumentException(
 355                 "Array and limit arrays must be of the same length.");
 356         }
 357         choiceLimits = Arrays.copyOf(limits, limits.length);
 358         choiceFormats = Arrays.copyOf(formats, formats.length);
 359     }
 360 
 361     /**
 362      * Get the limits passed in the constructor.
 363      * @return the limits.
 364      */
 365     public double[] getLimits() {
 366         double[] newLimits = Arrays.copyOf(choiceLimits, choiceLimits.length);
 367         return newLimits;
 368     }
 369 
 370     /**
 371      * Get the formats passed in the constructor.
 372      * @return the formats.


< prev index next >