/** * Compare a unit to another unit. * <br> * Examples:<br> * 1. 'm' (milli) is smaller than 'k' (kilo), so compareUnits("m", "k") * will return -1.<br> * 2. 'M' (MEGA) is greater than 'k' (kilo), so compareUnits("M", "k") will * return 1. * * @param unitA first unit * @param unitB second unit * @return +1, 0 or -1 depending on whether the relationship between units * is smaller than, * equal to or lesser than. */ public static int compareUnits(String unitA, String unitB) { checkUnitArgument(unitA); checkUnitArgument(unitB); int unitAPos = SORTED_UNITS.indexOf(unitA); int unitBPos = SORTED_UNITS.indexOf(unitB); return Integer.compare(unitAPos, unitBPos); } }
checkUnitArgument(unitA); checkUnitArgument(unitB); if (unitA.equals(unitB)) { return Long.compare(valueA, valueB);