Package net.sf.basedb.core
Class IntegerUtil
java.lang.Object
net.sf.basedb.core.IntegerUtil
Utility methods that will make it easier to implement
data validation for integer attributes.
- Version:
- 2.0
- Author:
- Nicklas, Enell
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Check that an integer is equal or lower than a maximum value.static int
Check that an integer is equal or greater than a minimum value.static int
checkMinMax
(int value, String name, int minValue, int maxValue) Check that an integer is equal or between a minimum and a maximum value.static int
Get the value of anInteger
.static int
Get the value of anInteger
.static int
Get the int value of anString
.static int
Get the int value of anString
.
-
Constructor Details
-
IntegerUtil
public IntegerUtil()
-
-
Method Details
-
getInt
Get the int value of anString
. If theString
couldn't be parsed 0 is returned.- Parameters:
value
- TheInteger
- Returns:
- The value of the
Integer
or 0 if it is not parseable
-
getInt
Get the int value of anString
. If theString
couldn't be parsed default value is returned.- Parameters:
value
- TheInteger
defaultValue
- Default value to return if the parsing fails.- Returns:
- The value of the
Integer
or defaultValue if it is not parseable
-
getInt
Get the value of anInteger
.- Parameters:
value
- TheInteger
- Returns:
- The value of the
Integer
or 0 if it is null
-
getInt
Get the value of anInteger
.- Parameters:
value
- TheInteger
defaultValue
- The default value to return if the value is null- Returns:
- The value of the
Integer
or defaultValue if it is null
-
checkMin
Check that an integer is equal or greater than a minimum value.- Parameters:
value
- The value to checkname
- The name of the attribute to use if an exception is thrownminValue
- The minimum allowed value- Returns:
- The same value
- Throws:
NumberOutOfRangeException
- If the value lower than the minimum
-
checkMax
Check that an integer is equal or lower than a maximum value.- Parameters:
value
- The value to checkname
- The name of the attribute to use if an exception is thrownmaxValue
- The maximum allowed value- Returns:
- The same value
- Throws:
NumberOutOfRangeException
- If the value greater than the maximum
-
checkMinMax
public static int checkMinMax(int value, String name, int minValue, int maxValue) throws NumberOutOfRangeException Check that an integer is equal or between a minimum and a maximum value.- Parameters:
value
- The value to checkname
- The name of the attribute to use if an exception is thrownminValue
- The minimum allowed valuemaxValue
- The maximum allowed value- Returns:
- The same value
- Throws:
NumberOutOfRangeException
- If the value is outside the range
-