/** * Given an integer string, it checks if it's a valid integer (base on apaches NumberUtils.createInteger) and if * it's between the lowerBound and upperBound (including the lowerBound and excluding the upperBound). * * @param integerStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound) { return isValidInt(integerStr, lowerBound, upperBound, true, false); }
private static void validateTimeout(final String timeout, final List<String> validationList) { if (!NumberUtilities.isValidInt(timeout)) { validationList.add(INVALID_TIMEOUT); } else if (NumberUtilities.toInteger(timeout) < 0) { validationList.add(INVALID_NEGATIVE_TIMEOUT); } }
/** * Given a long integer string, it checks if it's a valid long (base on apaches NumberUtils.createLong) and if * it's between the lowerBound and upperBound. * * @param longStr the long integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @param includeLowerBound boolean if to include the lower bound of the interval * @param includeUpperBound boolean if to include the upper bound of the interval * @return true if the long integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidLong(longStr)) { return false; } final long aLong = toLong(longStr); final boolean respectsLowerBound = includeLowerBound ? lowerBound <= aLong : lowerBound < aLong; final boolean respectsUpperBound = includeUpperBound ? aLong <= upperBound : aLong < upperBound; return respectsLowerBound && respectsUpperBound; }
/** * Given an double string, it checks if it's a valid double (base on apaches NumberUtils.createDouble) and if * it's between the lowerBound and upperBound. * * @param doubleStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @param includeLowerBound boolean if to include the lower bound of the interval * @param includeUpperBound boolean if to include the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; }
if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE);
/** * If the integer string is null or empty, it returns the defaultInteger otherwise it returns the integer value (see toInteger) * * @param integerStr the integer to convert * @param defaultInteger the default value if the integerStr is null or the empty string * @return the integer value of the string or the defaultInteger is the integer string is empty * @throws IllegalArgumentException if the passed integer string is not a valid integer */ public static int toInteger(@Nullable final String integerStr, final int defaultInteger) { return StringUtils.isNoneEmpty(integerStr) ? toInteger(integerStr) : defaultInteger; }
/** * Given a long integer string, it checks if it's a valid long (base on apaches NumberUtils.createLong) and if * it's between the lowerBound and upperBound (including the lowerBound and excluding the upperBound). * * @param longStr the long integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the long integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound) { return isValidLong(longStr, lowerBound, upperBound, true, false); }
/** * Given an double string, it checks if it's a valid double (base on apaches NumberUtils.createDouble) and if * it's between the lowerBound and upperBound (including the lower bound and excluding the upper one) * * @param doubleStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound) { return isValidDouble(doubleStr, lowerBound, upperBound, true, false); }
/** * If the double string is null or empty, it returns the defaultDouble otherwise it returns the duoble value (see toDouble) * * @param doubleStr the double to convert * @param defaultDouble the default value if the doubleStr is null or the empty string * @return the double value of the string or the defaultDouble is the double string is empty * @throws IllegalArgumentException if the passed double string is not a valid double */ public static double toDouble(@Nullable final String doubleStr, final double defaultDouble) { return StringUtils.isNoneEmpty(doubleStr) ? toDouble(doubleStr) : defaultDouble; } }
if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE);
/** * If the integer string is null or empty, it returns the defaultInteger otherwise it returns the integer value (see toInteger) * * @param integerStr the integer to convert * @param defaultInteger the default value if the integerStr is null or the empty string * @return the integer value of the string or the defaultInteger is the integer string is empty * @throws IllegalArgumentException if the passed integer string is not a valid integer */ public static int toInteger(@Nullable final String integerStr, final int defaultInteger) { return StringUtils.isNoneEmpty(integerStr) ? toInteger(integerStr) : defaultInteger; }
/** * Given a long integer string, it checks if it's a valid long (base on apaches NumberUtils.createLong) and if * it's between the lowerBound and upperBound (including the lowerBound and excluding the upperBound). * * @param longStr the long integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the long integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound) { return isValidLong(longStr, lowerBound, upperBound, true, false); }
/** * Given an double string, it checks if it's a valid double (base on apaches NumberUtils.createDouble) and if * it's between the lowerBound and upperBound. * * @param doubleStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @param includeLowerBound boolean if to include the lower bound of the interval * @param includeUpperBound boolean if to include the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidDouble(doubleStr)) { return false; } final double aDouble = toDouble(doubleStr); final boolean respectsLowerBound = includeLowerBound ? Double.compare(lowerBound, aDouble) <= 0 : lowerBound < aDouble; final boolean respectsUpperBound = includeUpperBound ? Double.compare(aDouble, upperBound) <= 0 : aDouble < upperBound; return respectsLowerBound && respectsUpperBound; }
/** * Given an double string, it checks if it's a valid double (base on apaches NumberUtils.createDouble) and if * it's between the lowerBound and upperBound (including the lower bound and excluding the upper one) * * @param doubleStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidDouble(@Nullable final String doubleStr, double lowerBound, double upperBound) { return isValidDouble(doubleStr, lowerBound, upperBound, true, false); }
/** * If the double string is null or empty, it returns the defaultDouble otherwise it returns the duoble value (see toDouble) * * @param doubleStr the double to convert * @param defaultDouble the default value if the doubleStr is null or the empty string * @return the double value of the string or the defaultDouble is the double string is empty * @throws IllegalArgumentException if the passed double string is not a valid double */ public static double toDouble(@Nullable final String doubleStr, final double defaultDouble) { return StringUtils.isNoneEmpty(doubleStr) ? toDouble(doubleStr) : defaultDouble; } }
/** * Given an integer string, it checks if it's a valid integer (base on apaches NumberUtils.createInteger) and if * it's between the lowerBound and upperBound (including the lowerBound and excluding the upperBound). * * @param integerStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound) { return isValidInt(integerStr, lowerBound, upperBound, true, false); }
/** * Given an integer string, it checks if it's a valid integer (base on apaches NumberUtils.createInteger) and if * it's between the lowerBound and upperBound. * * @param integerStr the integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @param includeLowerBound boolean if to include the lower bound of the interval * @param includeUpperBound boolean if to include the upper bound of the interval * @return true if the integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidInt(@Nullable final String integerStr, final int lowerBound, final int upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidInt(integerStr)) { return false; } final int aInteger = toInteger(integerStr); final boolean respectsLowerBound = includeLowerBound ? lowerBound <= aInteger : lowerBound < aInteger; final boolean respectsUpperBound = includeUpperBound ? aInteger <= upperBound : aInteger < upperBound; return respectsLowerBound && respectsUpperBound; }
if (!isValidLong(timeout)) { throw new RuntimeException(TIMEOUT_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidLong(packetCount)) { throw new RuntimeException(PACKET_COUNT_SHOULD_HAVE_A_NUMERIC_VALUE); if (!isValidInt(packetSize)) { throw new RuntimeException(PACKET_SIZE_SHOULD_HAVE_A_NUMERIC_VALUE);
.strDelim(delimiter) .key(key) .timeout(toInteger(timeout)) .databasePoolingProperties(getOrDefaultDBPoolingProperties(databasePoolingProperties, EMPTY)) .resultSetType(getResultSetTypeForDbType(resultSetType, dbType))
/** * Given a long integer string, it checks if it's a valid long (base on apaches NumberUtils.createLong) and if * it's between the lowerBound and upperBound. * * @param longStr the long integer string to check * @param lowerBound the lower bound of the interval * @param upperBound the upper bound of the interval * @param includeLowerBound boolean if to include the lower bound of the interval * @param includeUpperBound boolean if to include the upper bound of the interval * @return true if the long integer string is valid and in between the lowerBound and upperBound, false otherwise * @throws IllegalArgumentException if the lowerBound is not less than the upperBound */ public static boolean isValidLong(@Nullable final String longStr, final long lowerBound, final long upperBound, final boolean includeLowerBound, final boolean includeUpperBound) { if (lowerBound > upperBound) { throw new IllegalArgumentException(ExceptionValues.INVALID_BOUNDS); } else if (!isValidLong(longStr)) { return false; } final long aLong = toLong(longStr); final boolean respectsLowerBound = includeLowerBound ? lowerBound <= aLong : lowerBound < aLong; final boolean respectsUpperBound = includeUpperBound ? aLong <= upperBound : aLong < upperBound; return respectsLowerBound && respectsUpperBound; }