Top Description Inners Fields Constructors Methods
com.ibm.icu.number

public abstract Class NumberRangeFormatter

extends Object
Class Inheritance
Imports
java.io.InvalidObjectException, java.util.Locale, com.ibm.icu.text.UFormat, com.ibm.icu.util.ULocale

The main entrypoint to the formatting of ranges of numbers, including currencies and other units of measurement.

Usage example:

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();
// => "750 m - 1.2 km"

Like NumberFormatter, NumberRangeFormatter instances (i.e., LocalizedNumberRangeFormatter and UnlocalizedNumberRangeFormatter) are immutable and thread-safe. This API is based on the fluent design pattern popularized by libraries such as Google's Guava.

Author
sffc
ICU Status
Stable since ICU 63.
See Also
NumberFormatter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
NumberRangeFormatter.RangeCollapse

Defines how to merge fields that are identical across the range sign.

public static enum
NumberRangeFormatter.RangeIdentityFallback

Defines the behavior when the two numbers in the range are identical after rounding.

public static enum
NumberRangeFormatter.RangeIdentityResult

Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range were equal or not, and whether or not the identity fallback was applied.

public static class
NumberRangeFormatter.SpanField

Class for span fields in FormattedNumberRange.

Field Summary

Modifier and TypeField and Description
private static final UnlocalizedNumberRangeFormatter

Constructor Summary

AccessConstructor and Description
private
NumberRangeFormatter()

Private constructor - this class is not designed for instantiation

Method Summary

Modifier and TypeMethod and Description
public static UnlocalizedNumberRangeFormatter

Returns:

An UnlocalizedNumberRangeFormatter, to be used for chaining.
with
()

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is not currently known at the call site.

public static LocalizedNumberRangeFormatter

Returns:

A LocalizedNumberRangeFormatter, to be used for chaining.
withLocale
(Locale
The locale from which to load formats and symbols for number range formatting.
locale
)

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call site.

public static LocalizedNumberRangeFormatter

Returns:

A LocalizedNumberRangeFormatter, to be used for chaining.
withLocale
(ULocale
The locale from which to load formats and symbols for number range formatting.
locale
)

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call site.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BASEback to summary
private static final UnlocalizedNumberRangeFormatter BASE

Constructor Detail

NumberRangeFormatterback to summary
private NumberRangeFormatter()

Private constructor - this class is not designed for instantiation

Method Detail

withback to summary
public static UnlocalizedNumberRangeFormatter with()

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is not currently known at the call site.

Returns:UnlocalizedNumberRangeFormatter

An UnlocalizedNumberRangeFormatter, to be used for chaining.

ICU Status
Stable since ICU 63.
withLocaleback to summary
public static LocalizedNumberRangeFormatter withLocale(Locale locale)

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call site.

Parameters
locale:Locale

The locale from which to load formats and symbols for number range formatting.

Returns:LocalizedNumberRangeFormatter

A LocalizedNumberRangeFormatter, to be used for chaining.

ICU Status
Stable since ICU 63.
withLocaleback to summary
public static LocalizedNumberRangeFormatter withLocale(ULocale locale)

Call this method at the beginning of a NumberRangeFormatter fluent chain in which the locale is known at the call site.

Parameters
locale:ULocale

The locale from which to load formats and symbols for number range formatting.

Returns:LocalizedNumberRangeFormatter

A LocalizedNumberRangeFormatter, to be used for chaining.

ICU Status
Stable since ICU 63.
com.ibm.icu.number back to summary

public final Enum NumberRangeFormatter.RangeCollapse

extends Enum<NumberRangeFormatter.RangeCollapse>
Class Inheritance

Defines how to merge fields that are identical across the range sign.
ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberRangeFormatter.RangeCollapse
ALL

Collapse any field that is equal across the range sign.

public static final NumberRangeFormatter.RangeCollapse
AUTO

Use locale data and heuristics to determine how much of the string to collapse.

public static final NumberRangeFormatter.RangeCollapse
NONE

Do not collapse any part of the number.

public static final NumberRangeFormatter.RangeCollapse
UNIT

Collapse the unit part of the number, but not the notation, if present.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberRangeFormatter.RangeCollapse
public static NumberRangeFormatter.RangeCollapse[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLback to summary
public static final NumberRangeFormatter.RangeCollapse ALL

Collapse any field that is equal across the range sign. May introduce ambiguity on the magnitude of the number. Example: "3.2 – 5.3 thousand kilograms"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
AUTOback to summary
public static final NumberRangeFormatter.RangeCollapse AUTO

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.

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
NONEback to summary
public static final NumberRangeFormatter.RangeCollapse NONE

Do not collapse any part of the number. Example: "3.2 thousand kilograms – 5.3 thousand kilograms"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
UNITback to summary
public static final NumberRangeFormatter.RangeCollapse UNIT

Collapse the unit part of the number, but not the notation, if present. Example: "3.2 thousand – 5.3 thousand kilograms"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Constructor Detail

RangeCollapseback to summary
private RangeCollapse()

Method Detail

valueOfback to summary
public static NumberRangeFormatter.RangeCollapse valueOf(String name)
valuesback to summary
public static NumberRangeFormatter.RangeCollapse[] values()
com.ibm.icu.number back to summary

public final Enum NumberRangeFormatter.RangeIdentityFallback

extends Enum<NumberRangeFormatter.RangeIdentityFallback>
Class Inheritance

Defines the behavior when the two numbers in the range are identical after rounding. To programmatically detect when the identity fallback is used, compare the lower and upper BigDecimals via FormattedNumber.
ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberRangeFormatter.RangeIdentityFallback
APPROXIMATELY

Show the number using a locale-sensitive approximation pattern.

public static final NumberRangeFormatter.RangeIdentityFallback
APPROXIMATELY_OR_SINGLE_VALUE

Show the number using a locale-sensitive approximation pattern.

public static final NumberRangeFormatter.RangeIdentityFallback
RANGE

Show the number as the range of two equal values.

public static final NumberRangeFormatter.RangeIdentityFallback
SINGLE_VALUE

Show the number as a single value rather than a range.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberRangeFormatter.RangeIdentityFallback
public static NumberRangeFormatter.RangeIdentityFallback[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

APPROXIMATELYback to summary
public static final NumberRangeFormatter.RangeIdentityFallback APPROXIMATELY

Show the number using a locale-sensitive approximation pattern. Use the range pattern always, even if the inputs are the same. Example: "~$5"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
APPROXIMATELY_OR_SINGLE_VALUEback to summary
public static final NumberRangeFormatter.RangeIdentityFallback APPROXIMATELY_OR_SINGLE_VALUE

Show the number using a locale-sensitive approximation pattern. If the numbers were the same before rounding, show the single value. Example: "~$5" or "$5"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
RANGEback to summary
public static final NumberRangeFormatter.RangeIdentityFallback RANGE

Show the number as the range of two equal values. Use the range pattern always, even if the inputs are the same. Example (with RangeCollapse.NONE): "$5 – $5"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
SINGLE_VALUEback to summary
public static final NumberRangeFormatter.RangeIdentityFallback SINGLE_VALUE

Show the number as a single value rather than a range. Example: "$5"

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Constructor Detail

RangeIdentityFallbackback to summary
private RangeIdentityFallback()

Method Detail

valueOfback to summary
public static NumberRangeFormatter.RangeIdentityFallback valueOf(String name)
valuesback to summary
public static NumberRangeFormatter.RangeIdentityFallback[] values()
com.ibm.icu.number back to summary

public final Enum NumberRangeFormatter.RangeIdentityResult

extends Enum<NumberRangeFormatter.RangeIdentityResult>
Class Inheritance

Used in the result class FormattedNumberRange to indicate to the user whether the numbers formatted in the range were equal or not, and whether or not the identity fallback was applied.
ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Field Summary

Modifier and TypeField and Description
public static final NumberRangeFormatter.RangeIdentityResult
EQUAL_AFTER_ROUNDING

Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.

public static final NumberRangeFormatter.RangeIdentityResult
EQUAL_BEFORE_ROUNDING

Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.

public static final NumberRangeFormatter.RangeIdentityResult
NOT_EQUAL

Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NumberRangeFormatter.RangeIdentityResult
public static NumberRangeFormatter.RangeIdentityResult[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EQUAL_AFTER_ROUNDINGback to summary
public static final NumberRangeFormatter.RangeIdentityResult EQUAL_AFTER_ROUNDING

Used to indicate that the two numbers in the range were equal, but only after rounding rules were applied.

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
EQUAL_BEFORE_ROUNDINGback to summary
public static final NumberRangeFormatter.RangeIdentityResult EQUAL_BEFORE_ROUNDING

Used to indicate that the two numbers in the range were equal, even before any rounding rules were applied.

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter
NOT_EQUALback to summary
public static final NumberRangeFormatter.RangeIdentityResult NOT_EQUAL

Used to indicate that the two numbers in the range were not equal, even after rounding rules were applied.

ICU Status
Stable since ICU 63.
See Also
NumberRangeFormatter

Constructor Detail

RangeIdentityResultback to summary
private RangeIdentityResult()

Method Detail

valueOfback to summary
public static NumberRangeFormatter.RangeIdentityResult valueOf(String name)
valuesback to summary
public static NumberRangeFormatter.RangeIdentityResult[] values()
com.ibm.icu.number back to summary

public final Class NumberRangeFormatter.SpanField

extends SpanField
Class Inheritance

Class for span fields in FormattedNumberRange.
ICU Status
Stable since ICU 69.

Field Summary

Modifier and TypeField and Description
public static final NumberRangeFormatter.SpanField
NUMBER_RANGE_SPAN

The concrete field used for spans in FormattedNumberRange.

private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected Object
readResolve()

Overrides java.text.AttributedCharacterIterator.Attribute.readResolve.

Deprecated This API is ICU internal only.
Serialization method resolve instances to the constant NumberRangeFormatter.SpanField values

Field Detail

NUMBER_RANGE_SPANback to summary
public static final NumberRangeFormatter.SpanField NUMBER_RANGE_SPAN

The concrete field used for spans in FormattedNumberRange. Instances of NUMBER_RANGE_SPAN should have an associated value, the index within the input list that is represented by the span.

ICU Status
Stable since ICU 69.
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.ibm.icu.text.UFormat.SpanField.serialVersionUID.

Constructor Detail

SpanFieldback to summary
private SpanField(String name)

Method Detail

readResolveback to summary
protected Object readResolve() throws InvalidObjectException

Overrides java.text.AttributedCharacterIterator.Attribute.readResolve.

Deprecated

This API is ICU internal only.

Serialization method resolve instances to the constant NumberRangeFormatter.SpanField values

Returns:Object

Doc from java.text.AttributedCharacterIterator.Attribute.readResolve.

the resolved Attribute object

Annotations
@Deprecated
@Override
Exceptions
InvalidObjectException:

Doc from java.text.AttributedCharacterIterator.Attribute.readResolve.

if the object to resolve is not an instance of Attribute

ICU Status
Internal ICU component.