Package org.apache.hadoop.yarn.util
Class UnitsConversionUtil
java.lang.Object
org.apache.hadoop.yarn.util.UnitsConversionUtil
A util to convert values in one unit to another. Units refers to whether
the value is expressed in pico, nano, etc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper class for encapsulating conversion values. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompare a value in a given unit with a value in another unit.static intcompareUnits(String unitA, String unitB) Compare a unit to another unit.static longConverts a value from one unit to another.
-
Field Details
-
KNOWN_UNITS
-
-
Constructor Details
-
UnitsConversionUtil
public UnitsConversionUtil()
-
-
Method Details
-
convert
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 valuetoUnit- the target unitfromValue- the value you wish to convert- Returns:
- the value in toUnit
-
compare
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 unitvalueA- first valueunitB- second unitvalueB- second value- Returns:
- +1, 0 or -1 depending on whether the relationship is greater than, equal to or lesser than
-
compareUnits
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 unitunitB- second unit- Returns:
- +1, 0 or -1 depending on whether the relationship between units is smaller than, equal to or lesser than.
-