Class UnitsConversionUtil

java.lang.Object
org.apache.hadoop.yarn.util.UnitsConversionUtil

@Private @Unstable public class UnitsConversionUtil extends Object
A util to convert values in one unit to another. Units refers to whether the value is expressed in pico, nano, etc.
  • Field Details

    • KNOWN_UNITS

      public static final Set<String> KNOWN_UNITS
  • Constructor Details

    • UnitsConversionUtil

      public UnitsConversionUtil()
  • Method Details

    • convert

      public static long convert(String fromUnit, String toUnit, long fromValue)
      Converts a value from one unit to another. Supported units can be obtained by inspecting the KNOWN_UNITS set.
      Parameters:
      fromUnit - the unit of the from value
      toUnit - the target unit
      fromValue - the value you wish to convert
      Returns:
      the value in toUnit
    • compare

      public static int compare(String unitA, long valueA, String unitB, long valueB)
      Compare a value in a given unit with a value in another unit. The return value is equivalent to the value returned by compareTo.
      Parameters:
      unitA - first unit
      valueA - first value
      unitB - second unit
      valueB - second value
      Returns:
      +1, 0 or -1 depending on whether the relationship is greater than, equal to or lesser than
    • compareUnits

      public static int compareUnits(String unitA, String unitB)
      Compare a unit to another unit.
      Examples:
      1. 'm' (milli) is smaller than 'k' (kilo), so compareUnits("m", "k") will return -1.
      2. 'M' (MEGA) is greater than 'k' (kilo), so compareUnits("M", "k") will return 1.
      Parameters:
      unitA - first unit
      unitB - second unit
      Returns:
      +1, 0 or -1 depending on whether the relationship between units is smaller than, equal to or lesser than.