Package net.sf.basedb.core
Class IntegerUtil
- java.lang.Object
-
- net.sf.basedb.core.IntegerUtil
-
public class IntegerUtil extends Object
Utility methods that will make it easier to implement data validation for integer attributes.- Version:
- 2.0
- Author:
- Nicklas, Enell
-
-
Constructor Summary
Constructors Constructor Description IntegerUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
checkMax(int value, String name, int maxValue)
Check that an integer is equal or lower than a maximum value.static int
checkMin(int value, String name, int minValue)
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
getInt(Integer value)
Get the value of anInteger
.static int
getInt(Integer value, int defaultValue)
Get the value of anInteger
.static int
getInt(String value)
Get the int value of anString
.static int
getInt(String value, int defaultValue)
Get the int value of anString
.
-
-
-
Method Detail
-
getInt
public static int getInt(String value)
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
public static int getInt(String value, int defaultValue)
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
public static int getInt(Integer value)
Get the value of anInteger
.- Parameters:
value
- TheInteger
- Returns:
- The value of the
Integer
or 0 if it is null
-
getInt
public static int getInt(Integer value, int defaultValue)
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
public static int checkMin(int value, String name, int minValue) throws NumberOutOfRangeException
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
public static int checkMax(int value, String name, int maxValue) throws NumberOutOfRangeException
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
-
-