public int atoi (String str) {
		if (str == null) return 0;
		
		str = str.trim();
		boolean isNeg = false;
		long result = 0;
		
		for (int i = 0; i < str.length() - 1; i++) {
			if (i == 0 && str.charAt(i) == '-') {
				isNeg = true;
				continue;
			}
			
			int c = str.charAt(i) - '0';
			if (c < 0 || c > 9 ) break;
			
			result = result * 10 + c;
		}
		
		if (isNeg) {
			result = - result;
			result = Math.max(result, Integer.MIN_VALUE);
		} else {
			result = Math.min(result, Integer.MAX_VALUE);
		}
		
		return (int)result;
		
	}