public class UnitUtilities
extends java.lang.Object
Note that a null units array is considered to be a 'unitless' value to reduce memory allocation for tokens that have no units. In other words, the exponent associated with each unit category is zero. In general, the methods in this class return null whenever a unitless unit array is encountered.
Modifier and Type | Method and Description |
---|---|
static int[] |
addUnitsArray(int[] units1,
int[] units2)
Add the given unit arrays, and return the result in a new
array.
|
static boolean |
areUnitArraysEqual(int[] units1,
int[] units2)
Return true if the units of this token are the same as that of the
argument token.
|
static java.util.ArrayList |
categoryList()
Return a copy of the category list.
|
static int[] |
copyUnitsArray(int[] units)
Return a copy of the given units array.
|
static java.lang.String |
getBaseUnitName(int categoryIndex)
Return the name of the base unit of the specified category.
|
static int |
getNumCategories()
Return the number of currently registered categories.
|
static int |
getUnitCategoryIndex(java.lang.String categoryName)
Return the index assigned to the specified unit category.
|
static boolean |
isUnitless(int[] exponents)
Return true if the given unit array is null, or the exponents for
each index are zero.
|
static int[] |
newUnitArrayInCategory(int index)
Return a new units array that has the element at the given
index set to one.
|
static void |
registerUnitCategory(java.lang.String categoryName)
Register the specified unit category name.
|
static void |
resetUnitCategories()
Reset the internal state of the UnitSystem.
|
static int[] |
subtractUnitsArray(int[] units1,
int[] units2)
Subtract the given unit arrays and return the result in a new array.
|
static java.lang.String |
summarizeUnitCategories()
Return a string representation of the UnitSystem.
|
static java.lang.String |
unitsString(int[] units)
Return the string representation of the given array of units.
|
public static int[] addUnitsArray(int[] units1, int[] units2)
units1
- The first array of units.units2
- The second array of units.public static boolean areUnitArraysEqual(int[] units1, int[] units2)
units1
- The first array of units.units2
- The second array of units.public static java.util.ArrayList categoryList()
public static int[] copyUnitsArray(int[] units)
units
- The given array of units.public static java.lang.String getBaseUnitName(int categoryIndex)
categoryIndex
- The index of the unit category.public static int getNumCategories()
public static int getUnitCategoryIndex(java.lang.String categoryName)
categoryName
- The unit category.public static boolean isUnitless(int[] exponents)
exponents
- The unit array to be checked.public static int[] newUnitArrayInCategory(int index)
index
- The unit category index.public static void registerUnitCategory(java.lang.String categoryName)
Note that the
UnitCategory.UnitCategory(NamedObj, String)
constructor
calls this method.
categoryName
- The unit categoryName to be registered.public static void resetUnitCategories()
public static int[] subtractUnitsArray(int[] units1, int[] units2)
units1
- The first array of units.units2
- The second array of units.public static java.lang.String summarizeUnitCategories()
public static java.lang.String unitsString(int[] units)
units
- the given array of units.