Package com.ibm.icu.impl.units
Class MeasureUnitImpl
java.lang.Object
com.ibm.icu.impl.units.MeasureUnitImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static enum
(package private) static class
static class
(package private) static class
static enum
(package private) static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MeasureUnit.Complexity
The complexity, either SINGLE, COMPOUND, or MIXED.private long
The constant denominator.private String
The full unit identifier.private final ArrayList
<SingleUnitImpl> The list of single units. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
appendSingleUnit
(SingleUnitImpl singleUnit) Mutates this MeasureUnitImpl to append a single unit.void
applyDimensionality
(int dimensionality) Applies dimensionality to all the internal single units.build()
Transform this MeasureUnitImpl into a MeasureUnit, simplifying if possible.copy()
Returns a simplified version of the unit.private int
countCharacter
(String str, char ch) static MeasureUnitImpl
forCurrencyCode
(String currencyCode) Used for currency units.static MeasureUnitImpl
forIdentifier
(String identifier) Parse a unit identifier into a MeasureUnitImpl.long
Get the constant denominator.private String
getConstantsString
(long constantDenominator) Internal function that returns a string of the constants in the correct format.Returns the CLDR unit identifier and null if not computed.Returns the list of simple units.void
Normalizes the MeasureUnitImpl and generates the identifier string in place.void
setComplexity
(MeasureUnit.Complexity complexity) void
setConstantDenominator
(long constantDenominator) Set the constant denominator.void
Mutates this MeasureUnitImpl to take the reciprocal.toString()
-
Field Details
-
identifier
The full unit identifier. Null if not computed. -
complexity
The complexity, either SINGLE, COMPOUND, or MIXED. -
constantDenominator
private long constantDenominatorThe constant denominator. NOTE: when it is 0, it means there is no constant denominator. -
singleUnits
The list of single units. These may be summed or multiplied, based on the value of the complexity field.The "dimensionless" unit (SingleUnitImpl default constructor) must not be added to this list.
The "dimensionless"
MeasureUnitImpl
has an emptysingleUnits
.
-
-
Constructor Details
-
MeasureUnitImpl
public MeasureUnitImpl() -
MeasureUnitImpl
-
-
Method Details
-
forIdentifier
Parse a unit identifier into a MeasureUnitImpl.- Parameters:
identifier
- The unit identifier string.- Returns:
- A newly parsed object.
- Throws:
IllegalArgumentException
- in case of incorrect/non-parsed identifier.
-
forCurrencyCode
Used for currency units. -
copy
-
copyAndSimplify
Returns a simplified version of the unit. NOTE: the simplification happen when there are two units equals in their base unit and their prefixes. Example 1: "square-meter-per-meter" --> "meter" Example 2: "square-millimeter-per-meter" --> "square-millimeter-per-meter" -
getSingleUnits
Returns the list of simple units. -
takeReciprocal
public void takeReciprocal()Mutates this MeasureUnitImpl to take the reciprocal. -
extractIndividualUnitsWithIndices
-
applyDimensionality
public void applyDimensionality(int dimensionality) Applies dimensionality to all the internal single units. For example: square-meter-per-second, when we apply dimensionality -2, it will be square-second-per-p4-meter -
appendSingleUnit
Mutates this MeasureUnitImpl to append a single unit.- Returns:
- true if a new item was added. If unit is the dimensionless unit, it is never added: the return value will always be false.
-
build
Transform this MeasureUnitImpl into a MeasureUnit, simplifying if possible.NOTE: this function must be called from a thread-safe class
-
getSingleUnitImpl
- Returns:
- SingleUnitImpl
- Throws:
UnsupportedOperationException
- if the object could not be converted to SingleUnitImpl.
-
getIdentifier
Returns the CLDR unit identifier and null if not computed. -
getComplexity
-
setComplexity
-
getConstantDenominator
public long getConstantDenominator()Get the constant denominator. -
setConstantDenominator
public void setConstantDenominator(long constantDenominator) Set the constant denominator. -
countCharacter
-
getConstantsString
Internal function that returns a string of the constants in the correct format. Example: 1000 --> "-per-1000" 1000000 --> "-per-1e6" NOTE: this function is only used when the constant denominator is greater than 0. -
serialize
public void serialize()Normalizes the MeasureUnitImpl and generates the identifier string in place. -
toString
-