Package com.ibm.icu.impl.units
Class MeasureUnitImpl
- java.lang.Object
-
- com.ibm.icu.impl.units.MeasureUnitImpl
-
public class MeasureUnitImpl extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MeasureUnitImpl.CompoundPart
static class
MeasureUnitImpl.InitialCompoundPart
(package private) static class
MeasureUnitImpl.MeasureUnitImplComparator
static class
MeasureUnitImpl.MeasureUnitImplWithIndex
(package private) static class
MeasureUnitImpl.MeasureUnitImplWithIndexComparator
static class
MeasureUnitImpl.PowerPart
(package private) static class
MeasureUnitImpl.SingleUnitComparator
static class
MeasureUnitImpl.UnitsParser
-
Field Summary
Fields Modifier and Type Field Description private MeasureUnit.Complexity
complexity
The complexity, either SINGLE, COMPOUND, or MIXED.private java.lang.String
identifier
The full unit identifier.private java.util.ArrayList<SingleUnitImpl>
singleUnits
The list of single units.
-
Constructor Summary
Constructors Constructor Description MeasureUnitImpl()
MeasureUnitImpl(SingleUnitImpl singleUnit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
appendSingleUnit(SingleUnitImpl singleUnit)
Mutates this MeasureUnitImpl to append a single unit.void
applyDimensionality(int dimensionality)
Applies dimensionality to all the internal single units.MeasureUnit
build()
Transform this MeasureUnitImpl into a MeasureUnit, simplifying if possible.MeasureUnitImpl
copy()
MeasureUnitImpl
copyAndSimplify()
Returns a simplified version of the unit.java.util.ArrayList<MeasureUnitImpl.MeasureUnitImplWithIndex>
extractIndividualUnitsWithIndices()
static MeasureUnitImpl
forCurrencyCode(java.lang.String currencyCode)
Used for currency units.static MeasureUnitImpl
forIdentifier(java.lang.String identifier)
Parse a unit identifier into a MeasureUnitImpl.MeasureUnit.Complexity
getComplexity()
java.lang.String
getIdentifier()
Returns the CLDR unit identifier and null if not computed.SingleUnitImpl
getSingleUnitImpl()
java.util.ArrayList<SingleUnitImpl>
getSingleUnits()
Returns the list of simple units.void
serialize()
Normalizes the MeasureUnitImpl and generates the identifier string in place.void
setComplexity(MeasureUnit.Complexity complexity)
void
takeReciprocal()
Mutates this MeasureUnitImpl to take the reciprocal.java.lang.String
toString()
-
-
-
Field Detail
-
identifier
private java.lang.String identifier
The full unit identifier. Null if not computed.
-
complexity
private MeasureUnit.Complexity complexity
The complexity, either SINGLE, COMPOUND, or MIXED.
-
singleUnits
private final java.util.ArrayList<SingleUnitImpl> 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 Detail
-
MeasureUnitImpl
public MeasureUnitImpl()
-
MeasureUnitImpl
public MeasureUnitImpl(SingleUnitImpl singleUnit)
-
-
Method Detail
-
forIdentifier
public static MeasureUnitImpl forIdentifier(java.lang.String identifier)
Parse a unit identifier into a MeasureUnitImpl.- Parameters:
identifier
- The unit identifier string.- Returns:
- A newly parsed object.
- Throws:
java.lang.IllegalArgumentException
- in case of incorrect/non-parsed identifier.
-
forCurrencyCode
public static MeasureUnitImpl forCurrencyCode(java.lang.String currencyCode)
Used for currency units.
-
copy
public MeasureUnitImpl copy()
-
copyAndSimplify
public MeasureUnitImpl 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
public java.util.ArrayList<SingleUnitImpl> getSingleUnits()
Returns the list of simple units.
-
takeReciprocal
public void takeReciprocal()
Mutates this MeasureUnitImpl to take the reciprocal.
-
extractIndividualUnitsWithIndices
public java.util.ArrayList<MeasureUnitImpl.MeasureUnitImplWithIndex> 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
public boolean appendSingleUnit(SingleUnitImpl singleUnit)
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
public MeasureUnit build()
Transform this MeasureUnitImpl into a MeasureUnit, simplifying if possible.NOTE: this function must be called from a thread-safe class
-
getSingleUnitImpl
public SingleUnitImpl getSingleUnitImpl()
- Returns:
- SingleUnitImpl
- Throws:
java.lang.UnsupportedOperationException
- if the object could not be converted to SingleUnitImpl.
-
getIdentifier
public java.lang.String getIdentifier()
Returns the CLDR unit identifier and null if not computed.
-
getComplexity
public MeasureUnit.Complexity getComplexity()
-
setComplexity
public void setComplexity(MeasureUnit.Complexity complexity)
-
serialize
public void serialize()
Normalizes the MeasureUnitImpl and generates the identifier string in place.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-