|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.data.unit.UnitUtilities
public class UnitUtilities
A set of manipulation routines that are useful for factoring most of the difficulty of dealing with units out of individual token classes. Furthermore, having these as static methods which do not depend on token classes can improve generated code. Generally, the methods in this class manipulate arrays of integers, where each index in the array corresponds to a different category of units, and the value of each element in the array corresponds to the factor in that unit. Generally, multiplying two tokens adds adds their units, dividing two tokens subtracts their units, and adding and subtracting tokens assert that the units are the same.
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.
Red (cxh) |
Red (cxh) |
Field Summary | |
---|---|
private static int |
_categories
|
private static java.util.ArrayList |
_categoryList
|
private static java.util.HashMap |
_indexTable
|
Constructor Summary | |
---|---|
private |
UnitUtilities()
There are no instances of this class. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.HashMap _indexTable
private static int _categories
private static java.util.ArrayList _categoryList
Constructor Detail |
---|
private UnitUtilities()
Method Detail |
---|
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |