Class UnitUtil


public class UnitUtil
extends Object
A utility class for working with Unit:s.
Last modified
$Date: 2008-12-18 09:22:27 +0100 (to, 18 dec 2008) $
  • Field Details


      public static final Pattern VALUE_WITH_UNIT
      Pattern for checking if a string is a numeric value with an optional unit. Used by splitValueWithUnit(String)
  • Constructor Details

    • UnitUtil

      public UnitUtil()
  • Method Details

    • getUnit

      public static Unit getUnit​(DbControl dc, String quantityId, String symbol)
      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 a UnitCache instead.
      dc - The DbControl to use for database access
      quantityId - The system ID of the quantity
      symbol - The unit symbol
      A unit object, or null if no unit is found
    • splitValueWithUnit

      public static String[] splitValueWithUnit​(String value)
      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.
      value - The value to split
      An array of length 2, or null