1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2018 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html 4 package android.icu.number; 5 6 import android.icu.impl.number.DecimalQuantity; 7 import android.icu.impl.number.DecimalQuantity_DualStorageBCD; 8 9 /** 10 * A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available. 11 * 12 * Instances of this class are immutable and thread-safe. 13 * 14 * @author sffc 15 * @see NumberRangeFormatter 16 */ 17 public class LocalizedNumberRangeFormatter extends NumberRangeFormatterSettings<LocalizedNumberRangeFormatter> { 18 19 private volatile NumberRangeFormatterImpl fImpl; 20 LocalizedNumberRangeFormatter(NumberRangeFormatterSettings<?> parent, int key, Object value)21 LocalizedNumberRangeFormatter(NumberRangeFormatterSettings<?> parent, int key, Object value) { 22 super(parent, key, value); 23 } 24 25 /** 26 * Format the given integers to a string using the settings specified in the NumberRangeFormatter fluent setting 27 * chain. 28 * 29 * @param first 30 * The first number in the range, usually to the left in LTR locales. 31 * @param second 32 * The second number in the range, usually to the right in LTR locales. 33 * @return A FormattedNumberRange object; call .toString() to get the string. 34 * @see NumberRangeFormatter 35 */ formatRange(int first, int second)36 public FormattedNumberRange formatRange(int first, int second) { 37 DecimalQuantity dq1 = new DecimalQuantity_DualStorageBCD(first); 38 DecimalQuantity dq2 = new DecimalQuantity_DualStorageBCD(second); 39 return formatImpl(dq1, dq2, first == second); 40 } 41 42 /** 43 * Format the given doubles to a string using the settings specified in the NumberRangeFormatter fluent setting 44 * chain. 45 * 46 * @param first 47 * The first number in the range, usually to the left in LTR locales. 48 * @param second 49 * The second number in the range, usually to the right in LTR locales. 50 * @return A FormattedNumberRange object; call .toString() to get the string. 51 * @see NumberRangeFormatter 52 */ formatRange(double first, double second)53 public FormattedNumberRange formatRange(double first, double second) { 54 DecimalQuantity dq1 = new DecimalQuantity_DualStorageBCD(first); 55 DecimalQuantity dq2 = new DecimalQuantity_DualStorageBCD(second); 56 // Note: double equality could be changed to epsilon equality later if there is demand. 57 // The epsilon should be set via an API method. 58 return formatImpl(dq1, dq2, first == second); 59 } 60 61 /** 62 * Format the given Numbers to a string using the settings specified in the NumberRangeFormatter fluent setting 63 * chain. 64 * 65 * @param first 66 * The first number in the range, usually to the left in LTR locales. 67 * @param second 68 * The second number in the range, usually to the right in LTR locales. 69 * @return A FormattedNumberRange object; call .toString() to get the string. 70 * @throws IllegalArgumentException if first or second is null 71 * @see NumberRangeFormatter 72 */ formatRange(Number first, Number second)73 public FormattedNumberRange formatRange(Number first, Number second) { 74 if (first == null || second == null) { 75 throw new IllegalArgumentException("Cannot format null values in range"); 76 } 77 DecimalQuantity dq1 = new DecimalQuantity_DualStorageBCD(first); 78 DecimalQuantity dq2 = new DecimalQuantity_DualStorageBCD(second); 79 return formatImpl(dq1, dq2, first.equals(second)); 80 } 81 82 /** 83 * Disassociate the locale from this formatter. 84 * 85 * @return The fluent chain. 86 */ 87 @android.annotation.FlaggedApi(com.android.icu.Flags.FLAG_ICU_25Q2_API) withoutLocale()88 public UnlocalizedNumberRangeFormatter withoutLocale() { 89 return new UnlocalizedNumberRangeFormatter(this, KEY_LOCALE, null); 90 } 91 formatImpl(DecimalQuantity first, DecimalQuantity second, boolean equalBeforeRounding)92 FormattedNumberRange formatImpl(DecimalQuantity first, DecimalQuantity second, boolean equalBeforeRounding) { 93 if (fImpl == null) { 94 fImpl = new NumberRangeFormatterImpl(resolve()); 95 } 96 return fImpl.format(first, second, equalBeforeRounding); 97 } 98 99 @Override create(int key, Object value)100 LocalizedNumberRangeFormatter create(int key, Object value) { 101 return new LocalizedNumberRangeFormatter(this, key, value); 102 } 103 104 } 105