Package net.sf.basedb.util.units
Class UnitUtil
java.lang.Object
net.sf.basedb.util.units.UnitUtil
A utility class for working with
Unit
:s.- Version:
- 2.9
- Author:
- Nicklas
- Last modified
- $Date: 2008-12-18 09:22:27 +0100 (to, 18 dec 2008) $
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
Pattern for checking if a string is a numeric value with an optional unit. -
Constructor Summary
-
Method Summary
-
Field Details
-
VALUE_WITH_UNIT
Pattern for checking if a string is a numeric value with an optional unit. Used bysplitValueWithUnit(String)
-
-
Constructor Details
-
UnitUtil
public UnitUtil()
-
-
Method Details
-
getUnit
Find the unit with a given symbol for a given quantity. Use this method only when you need to find few units. Each invokation results in a new database query. If you need to lookup mulitple units, consider using aUnitCache
instead.- Parameters:
dc
- The DbControl to use for database accessquantityId
- The system ID of the quantitysymbol
- The unit symbol- Returns:
- A unit object, or null if no unit is found
-
splitValueWithUnit
Splits a value with an optional unit. The input string should start with a numerical value and optionally end with a unit. If the value is not numeric, null is returned, otherwise an array with two elements is returned. The 0th element is the numeric part, and the 1st is the unit part. The unit part is null if the value doesn't have a unit. White-space has been stripped from all values.- Parameters:
value
- The value to split- Returns:
- An array of length 2, or null
-