@ThreadSafe public class MyUtils extends Object
This class is stateless and thread-safe.
| Modifier and Type | Method and Description |
|---|---|
static int |
intRequirePositive(int val,
String valName)
Checks whether an integer is greater than zero or not.
|
static int |
intRequireRange(int val,
int lowerLimit,
int upperLimit,
String valName)
Checks whether an integer is in a range or not.
|
static boolean |
isBetween(int val,
int lowerLimit,
int upperLimit)
Returns true if and only if
val is greater than or equal to lowerLimit
and is less than or equal to upperLimit. |
public static boolean isBetween(int val,
int lowerLimit,
int upperLimit)
val is greater than or equal to lowerLimit
and is less than or equal to upperLimit.val - the value to be checked, an integerlowerLimit - lower boundary to be checked, an integerupperLimit - upper boundary to be checked, an integerval is between lowerLimit and
upperLimitpublic static int intRequireRange(int val,
int lowerLimit,
int upperLimit,
String valName)
val is less than
lowerLimit or greater than upperLimit, an IllegalArgumentException
will be thrown with a suitable message.val - value to checklowerLimit - lower limit of rangeupperLimit - upper limit of rangevalName - the name of val that is printed in the exception messageval, if it is in the rangepublic static int intRequirePositive(int val,
String valName)
val is less than
or equal to zero, an IllegalArgumentException will be thrown with a suitable message.val - integer value to checkvalName - name of val that is printed in the exception messageval, if it is positiveCopyright © 2017. All rights reserved.