return;
}
- results->identityType = UNUM_IDENTITY_TYPE_NOT_EQUAL;
+ results->identityResult = UNUM_IDENTITY_RESULT_NOT_EQUAL;
}
return fResults->quantity2.toScientificString();
}
-UNumberRangeIdentityType FormattedNumberRange::getIdentityType(UErrorCode& status) const {
+UNumberRangeIdentityResult FormattedNumberRange::getIdentityResult(UErrorCode& status) const {
if (U_FAILURE(status)) {
- return UNUM_IDENTITY_TYPE_NOT_EQUAL;
+ return UNUM_IDENTITY_RESULT_NOT_EQUAL;
}
if (fResults == nullptr) {
status = fErrorCode;
- return UNUM_IDENTITY_TYPE_NOT_EQUAL;
+ return UNUM_IDENTITY_RESULT_NOT_EQUAL;
}
- return fResults->identityType;
+ return fResults->identityResult;
}
FormattedNumberRange::~FormattedNumberRange() {
DecimalQuantity quantity1;
DecimalQuantity quantity2;
NumberStringBuilder string;
- UNumberRangeIdentityType identityType = UNUM_IDENTITY_TYPE_EQUAL_BEFORE_ROUNDING;
+ UNumberRangeIdentityResult identityResult = UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING;
// No C conversion methods (no C API yet)
};
* Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none,
* some, or all repeated pieces in a locale-sensitive way.
*
+ * The heuristics used for this option are subject to change over time.
+ *
* @draft ICU 63
*/
UNUM_RANGE_COLLAPSE_AUTO,
* when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber.
*
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
typedef enum UNumberRangeIdentityFallback {
* were equal or not, and whether or not the identity fallback was applied.
*
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
-typedef enum UNumberRangeIdentityType {
+typedef enum UNumberRangeIdentityResult {
/**
* Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.
*
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
- UNUM_IDENTITY_TYPE_EQUAL_BEFORE_ROUNDING,
+ UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING,
/**
* Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.
*
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
- UNUM_IDENTITY_TYPE_EQUAL_AFTER_ROUNDING,
+ UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING,
/**
* Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.
*
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
- UNUM_IDENTITY_TYPE_NOT_EQUAL
-} UNumberRangeIdentityType;
+ UNUM_IDENTITY_RESULT_NOT_EQUAL
+} UNumberRangeIdentityResult;
U_NAMESPACE_BEGIN
* <li>UNIT: "3K - 5K miles"</li>
* <li>NONE: "3K miles - 5K miles"</li>
* <li>AUTO: usually UNIT or NONE, depending on the locale and formatter settings</li>
+ * </ul>
* <p>
* The default value is AUTO.
*
* rounding was applied</li>
* <li>APPROXIMATELY: "~5 miles"</li>
* <li>RANGE: "5-5 miles" (with collapse=UNIT)</li>
+ * </ul>
* <p>
* The default value is APPROXIMATELY.
*
// NOTE: Uses default copy and move constructors.
- protected:
+ private:
impl::RangeMacroProps fMacros;
- private:
// Don't construct me directly! Use (Un)LocalizedNumberFormatter.
NumberRangeFormatterSettings() = default;
* The first number in the range, usually to the left in LTR locales.
* @param second
* The second number in the range, usually to the right in LTR locales.
+ * @param status
+ * Set if an error occurs while formatting.
* @return A FormattedNumberRange object; call .toString() to get the string.
* @draft ICU 63
*/
/**
* @param results
* The results object. This method will mutate it to save the results.
+ * @param status
+ * Set if an error occurs while formatting.
* @internal
*/
void formatImpl(impl::UFormattedNumberRangeData* results, UErrorCode& status) const;
* information, use #getAllFieldPositions().
*
* @param fieldPosition
- * Input+output variable. See {@link FormattedNumber#nextFieldPosition(FieldPosition)}.
+ * Input+output variable. See {@link FormattedNumber#nextFieldPosition}.
* @param status
* Set if an error occurs while populating the FieldPosition.
* @return TRUE if a new occurrence of the field was found; FALSE otherwise.
*
* @return A decimal representation of the first formatted number.
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
* @see #getSecondDecimal
*/
*
* @return A decimal representation of the second formatted number.
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
* @see #getFirstDecimal
*/
*
* @return An indication the resulting identity situation in the formatted number range.
* @draft ICU 63
- * @provisional This API might change or be removed in a future release.
* @see UNumberRangeIdentityFallback
*/
- UNumberRangeIdentityType getIdentityType(UErrorCode& status) const;
+ UNumberRangeIdentityResult getIdentityResult(UErrorCode& status) const;
/**
* Copying not supported; use move constructor instead.
import com.ibm.icu.impl.number.DecimalQuantity;
import com.ibm.icu.impl.number.NumberStringBuilder;
-import com.ibm.icu.number.NumberRangeFormatter.RangeIdentityType;
+import com.ibm.icu.number.NumberRangeFormatter.RangeIdentityResult;
import com.ibm.icu.util.ICUUncheckedIOException;
/**
final NumberStringBuilder nsb;
final DecimalQuantity first;
final DecimalQuantity second;
- final RangeIdentityType identityType;
+ final RangeIdentityResult identityResult;
FormattedNumberRange(NumberStringBuilder nsb, DecimalQuantity first, DecimalQuantity second,
- RangeIdentityType identityType) {
+ RangeIdentityResult identityResult) {
this.nsb = nsb;
this.first = first;
this.second = second;
- this.identityType = identityType;
+ this.identityResult = identityResult;
}
/**
* @see NumberRangeFormatter
* @see NumberRangeFormatter.RangeIdentityFallback
*/
- public RangeIdentityType getIdentityType() {
- return identityType;
+ public RangeIdentityResult getIdentityResult() {
+ return identityResult;
}
/**
import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD;
import com.ibm.icu.impl.number.NumberStringBuilder;
import com.ibm.icu.impl.number.range.RangeMacroProps;
-import com.ibm.icu.number.NumberRangeFormatter.RangeIdentityType;
+import com.ibm.icu.number.NumberRangeFormatter.RangeIdentityResult;
/**
* A NumberRangeFormatter that has a locale associated with it; this means .formatRange() methods are available.
nsb.append(r1.nsb);
nsb.append(" --- ", null);
nsb.append(r2.nsb);
- RangeIdentityType identityType = equalBeforeRounding ? RangeIdentityType.EQUAL_BEFORE_ROUNDING
- : RangeIdentityType.NOT_EQUAL;
- return new FormattedNumberRange(nsb, first, second, identityType);
+ RangeIdentityResult identityResult = equalBeforeRounding ? RangeIdentityResult.EQUAL_BEFORE_ROUNDING
+ : RangeIdentityResult.NOT_EQUAL;
+ return new FormattedNumberRange(nsb, first, second, identityResult);
}
@Override
* <p>
*
* <pre>
- * NumberRangeFormatter.with().identityFallback(RangeIdentityFallback.APPROXIMATELY_OR_SINGLE_VALUE)
+ * NumberRangeFormatter.with()
+ * .identityFallback(RangeIdentityFallback.APPROXIMATELY_OR_SINGLE_VALUE)
* .numberFormatterFirst(NumberFormatter.with().unit(MeasureUnit.METER))
- * .numberFormatterSecond(NumberFormatter.with().unit(MeasureUnit.KILOMETER)).locale(ULocale.UK)
- * .formatRange(750, 1.2).toString();
+ * .numberFormatterSecond(NumberFormatter.with().unit(MeasureUnit.KILOMETER))
+ * .locale(ULocale.UK)
+ * .formatRange(750, 1.2)
+ * .toString();
* // => "750 m - 1.2 km"
* </pre>
* <p>
/**
* Use locale data and heuristics to determine how much of the string to collapse. Could end up collapsing none,
* some, or all repeated pieces in a locale-sensitive way.
+ * <p>
+ * The heuristics used for this option are subject to change over time.
*
* @draft ICU 63
* @provisional This API might change or be removed in a future release.
* @provisional This API might change or be removed in a future release.
* @see NumberRangeFormatter
*/
- public static enum RangeIdentityType {
+ public static enum RangeIdentityResult {
/**
* Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.
*
return BASE.locale(locale);
}
+ /**
+ * Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call
+ * site.
+ *
+ * @param locale
+ * The locale from which to load formats and symbols for number range formatting.
+ * @return A {@link LocalizedNumberRangeFormatter}, to be used for chaining.
+ * @draft ICU 63
+ */
public static LocalizedNumberRangeFormatter withLocale(ULocale locale) {
return BASE.locale(locale);
}
* <li>UNIT: "3K - 5K miles"</li>
* <li>NONE: "3K miles - 5K miles"</li>
* <li>AUTO: usually UNIT or NONE, depending on the locale and formatter settings</li>
+ * </ul>
* <p>
* The default value is AUTO.
*
* rounding was applied</li>
* <li>APPROXIMATELY: "~5 miles"</li>
* <li>RANGE: "5-5 miles" (with collapse=UNIT)</li>
+ * </ul>
* <p>
* The default value is APPROXIMATELY.
*
/**
* {@inheritDoc}
*
- * @draft ICU 60
+ * @draft ICU 63
* @provisional This API might change or be removed in a future release.
*/
@Override
/**
* {@inheritDoc}
*
- * @draft ICU 60
+ * @draft ICU 63
* @provisional This API might change or be removed in a future release.
*/
@Override