protected UnitFactor resolve ( Unit from , Unit to ) { if ( from == to ) { return new UnitFactor ( Rational . ONE , to ) ; } List < UnitFactor > path = getPath ( from , to ) ; if ( path . isEmpty ( ) ) { throw new IllegalStateException ( "Can't find a path to convert " + from + " units into " + to ) ; } UnitFactor factor = path . get ( 0 ) ; int size = path . size ( ) ; for ( int i = 1 ; i < size ; i ++ ) { factor = factor . multiply ( path . get ( i ) ) ; } return factor ; }
Find the best conversion factor path between the FROM and TO units multiply them together and return the resulting factor .