int (@NotNull String lineString) { // some quick checks to avoid costly exceptions if (lineString.isEmpty() || lineString.length() > 9 || !Character.isDigit(lineString.charAt(0))) { return -1; } try { return Integer.parseInt(lineString); } catch (NumberFormatException e) { return -1; } }