protected List<UnitFactor> getPath(Unit from, Unit to) {
    if (from == to) {
      return list(new UnitFactor(Rational.ONE, to));
    }

    // Find all paths between the two units.
    List<List<UnitFactor>> paths = getPaths(from, to, new HashSet<>());
    if (paths.isEmpty()) {
      return Collections.emptyList();
    }

    // Sort and return the path with the smallest precision. If two paths
    // have equal precision return the shorter path.
    paths.sort((a, b) -> {
      int cmp = Integer.compare(precisionSum(a), precisionSum(b));
      if (cmp == 0) {
        return Integer.compare(a.size(), b.size());
      }
      return cmp;
    });
    return paths.get(0);
  }
protected List < UnitFactor > getPath ( Unit from , Unit to ) { if ( from == to ) { return list ( new UnitFactor ( Rational . ONE , to ) ) ; } List < List < UnitFactor > > paths = getPaths ( from , to , new HashSet < > ( ) ) ; if ( paths . isEmpty ( ) ) { return Collections . emptyList ( ) ; } paths . sort ( ( a , b ) -> { int cmp = Integer . compare ( precisionSum ( a ) , precisionSum ( b ) ) ; if ( cmp == 0 ) { return Integer . compare ( a . size ( ) , b . size ( ) ) ; } return cmp ; } ) ; return paths . get ( 0 ) ; }
Find the shortest conversion path between the from and to units. Currently
we just look for path with the lowest precision, falling back to the
shortest path (fewest number of conversions to get from A to B).