Created
April 28, 2012 21:32
-
-
Save mourawaldson/2522195 to your computer and use it in GitHub Desktop.
Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Valida se a String está realmente preenchida e dentro dos limites de | |
* caracteres. Caso o parâmetro: quantidadeMinima, seja passado "null" ou | |
* "0", a função toma como padrão o valor 5, já para quantidadeMaxima o | |
* valor padrão é 255. | |
* | |
* @param str | |
* @return boolean true se a String for válida; false caso a mesma não | |
* esteja dentro dos padrões. | |
*/ | |
public static boolean isValidStr(String str, Integer quantidadeMinima, | |
Integer quantidadeMaxima) { | |
if (quantidadeMinima == null || quantidadeMinima == 0) | |
quantidadeMinima = 5; | |
if (quantidadeMaxima == null || quantidadeMaxima == 0) | |
quantidadeMaxima = 255; | |
if (!isNullOrEmpty(str)) { | |
int tamanhoStr = str.trim().length(); | |
return (tamanhoStr >= quantidadeMinima && tamanhoStr <= quantidadeMaxima) ? true | |
: false; | |
} else | |
return false; | |
} | |
/** | |
* Valida se o int está realmente preenchido dentro dos limites definidos. | |
* Caso o parâmetro: numeroMinimo, seja passado "null" ou "0", a função toma | |
* como padrão o valor 1, já para numeroMaximo o valor padrão é 99. | |
* | |
* @param value | |
* @return boolean true se o int for válido; false caso o mesmo não esteja | |
* dentro dos padrões. | |
*/ | |
public static boolean isValidInt(int value, Integer numeroMinimo, | |
Integer numeroMaximo) { | |
if (numeroMinimo == null || numeroMinimo == 0) | |
numeroMinimo = 1; | |
if (numeroMaximo == null || numeroMaximo == 0) | |
numeroMaximo = 99; | |
return (value < numeroMinimo.intValue() || value > numeroMaximo | |
.intValue()) ? false : true; | |
} | |
/** | |
* Valida se o float está realmente preenchido dentro dos limites definidos. | |
* Caso o parâmetro: numeroMinimo, seja passado "null" ou "0", a função toma | |
* como padrão o valor 0.0f, já para numeroMaximo o valor padrão é 999.9f. | |
* | |
* @param value | |
* @return boolean true se o float for válido; false caso o mesmo não esteja | |
* dentro dos padrões. | |
*/ | |
public static boolean isValidFloat(float value, Float numeroMinimo, | |
Float numeroMaximo) { | |
if (numeroMinimo == null || numeroMinimo == 0.0) | |
numeroMinimo = 0.0f; | |
if (numeroMaximo == null || numeroMaximo == 0.0) | |
numeroMaximo = 999.9f; | |
return (value < numeroMinimo.intValue() || value > numeroMaximo | |
.intValue()) ? false : true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment