public static int VersionToNumber(String str){
  boolean error=false;
  int i=0;
  int result=0;
  int digitsAfterDecimal=0;
  boolean afterDecimal=false;
  while ((!error) && i < str.length()) {
    char c=str.charAt(i);
    if (('0' <= c) && (c <= '9')) {
      result=10 * result + (c - '0');
      if (afterDecimal) {
        digitsAfterDecimal++;
        if (digitsAfterDecimal > 3) {
          error=true;
        }
      }
    }
 else     if (c == '.') {
      afterDecimal=true;
    }
 else {
      error=true;
    }
    i++;
  }
  if (error) {
    return -1;
  }
  for (int j=0; j < 3 - digitsAfterDecimal; j++) {
    result=10 * result;
  }
  return result;
}

public static int VersionToNumber ( String str ) { boolean error = false ; int i = 0 ; int result = 0 ; int digitsAfterDecimal = 0 ; boolean afterDecimal = false ; while ( ( ! error ) && i < str . length ( ) ) { char c = str . charAt ( i ) ; if ( ( '0' <= c ) && ( c <= '9' ) ) { result = 10 * result + ( c - '0' ) ; if ( afterDecimal ) { digitsAfterDecimal ++ ; if ( digitsAfterDecimal > 3 ) { error = true ; } } } else if ( c == '.' ) { afterDecimal = true ; } else { error = true ; } i ++ ; } if ( error ) { return - 1 ; } for ( int j = 0 ; j < 3 - digitsAfterDecimal ; j ++ ) { result = 10 * result ; } return result ; }
if str is a version number like 3 . 17 , then this returns 1000 times its numeric value - - e . g . , 3170 . otherwise , it returns - 1 .
