static double unitFactor ( String leftUnit , String rightUnit , boolean fail ) { if ( leftUnit . length ( ) == 0 || rightUnit . length ( ) == 0 || leftUnit . equals ( rightUnit ) ) { return 1 ; } HashMap < String , Double > leftGroup = UNIT_CONVERSIONS . get ( leftUnit ) ; if ( leftGroup != null ) { HashMap < String , Double > rightGroup = UNIT_CONVERSIONS . get ( rightUnit ) ; if ( leftGroup == rightGroup ) { return leftGroup . get ( leftUnit ) / leftGroup . get ( rightUnit ) ; } } if ( fail ) { throw new LessException ( "Incompatible types" ) ; } return 1 ; }
Calculate the factor between 2 units .