|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
org.mozilla.util
Class ParameterCheck
java.lang.Object | +--org.mozilla.util.ParameterCheck
- public final class ParameterCheck
- extends java.lang.Object
ParameterCheck provides convenient means for parameter checking. Class methods in the ParameterCheck class can be used to verify that method parameters meet certain conditions and to raise exceptions if the conditions are not met.
Typical usage:
ParameterCheck.nonNull(myParameter);
This verifies that myParameter is not null, throwing an IllegalArgumentException if it is.
ParameterCheck is intended specifically for checking parameters; for general condition and invariant testing, use Assert.
- See Also:
Assert
Method Summary | |
static void |
greaterThan(double aDouble,
double minimum)
Throws RangeException if 'aDouble' is not greater than 'minimum'; otherwise, does nothing. |
static void |
greaterThan(int anInt,
int minimum)
Throws RangeException if 'anInt' is not greater than 'minimum'; otherwise, does nothing. |
static void |
isFalse(boolean generalTest,
java.lang.String message)
Identical to isTrue, except the test is inverted. |
static void |
isTrue(boolean generalTest,
java.lang.String message)
Throws IllegalArgumentException if 'generalTest' is false; otherwise, does nothing. |
static void |
lessThan(double aDouble,
double maximum)
Throws RangeException if 'aDouble' is not less than 'maximum'; otherwise, does nothing. |
static void |
lessThan(int anInt,
int maximum)
Throws RangeException if 'anInt' is not less than 'maximum'; otherwise, does nothing. |
static void |
noGreaterThan(double aDouble,
double maximum)
Throws RangeException if 'aDouble' is greater than 'maximum'; otherwise, does nothing. |
static void |
noGreaterThan(int anInt,
int maximum)
Throws RangeException if 'anInt' is greater than 'maximum'; otherwise, does nothing. |
static void |
noLessThan(double aDouble,
double minimum)
Throws RangeException if 'aDouble' is less than 'minimum'; otherwise, does nothing. |
static void |
noLessThan(int anInt,
int minimum)
Throws RangeException if 'anInt' is less than 'minimum'; otherwise, does nothing. |
static void |
nonNull(java.lang.Object anObject)
Throws IllegalArgumentException if 'anObject' is null; otherwise, does nothing. |
static void |
notEmpty(java.lang.String aString)
Throws IllegalArgumentException if 'aString' is null or if 'aString' is an empty string; otherwise, does nothing. |
static void |
rangeWithinBounds(Range aRange,
int minimum,
int maximum)
Throws RangeException if 'aRange' is not completely between 'minimum' and 'maximum', inclusive; otherwise, does nothing. |
static void |
rangeWithinCount(Range aRange,
int count)
Throws RangeException if 'aRange' is not completely within a sequence that starts at 0 and has a length of 'count'; otherwise does nothing. |
static void |
rangeWithinString(Range aRange,
java.lang.String aString)
Checks a string and a range which is intended to indicate a substring. |
static void |
withinCount(int anInt,
int count)
Throws RangeException if 'anInt' is not within a sequence that starts at 0 and has a length of 'count'; otherwise does nothing. |
static void |
withinRange(double aDouble,
double minimum,
double maximum)
Throws RangeException if 'aDouble' is less than 'minimum' or greater than 'maximum'; otherwise, does nothing. |
static void |
withinRange(int anInt,
int minimum,
int maximum)
Throws RangeException if 'anInt' is less than 'minimum' or greater than 'maximum'; otherwise, does nothing. |
static void |
withinRange(int anInt,
Range aRange)
Throws RangeException if 'anInt' is not within 'aRange'; otherwise, does nothing. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Method Detail |
nonNull
public static void nonNull(java.lang.Object anObject)
- Throws IllegalArgumentException if 'anObject' is null; otherwise, does
nothing.
- Parameters:
anObject
- value to verify as non-null- Throws:
- java.lang.IllegalArgumentException - if 'anObject' is null
notEmpty
public static void notEmpty(java.lang.String aString)
- Throws IllegalArgumentException if 'aString' is null or if
'aString' is an empty string; otherwise, does nothing.
- Parameters:
aString
- string to verify as non-null and not empty- Throws:
- java.lang.IllegalArgumentException - if 'aString' is null or empty
noLessThan
public static void noLessThan(int anInt, int minimum)
- Throws RangeException if 'anInt' is less than 'minimum'; otherwise,
does nothing.
- Parameters:
anInt
- value to verify as not less than 'minimum'minimum
- smallest acceptable value for 'anInt'- Throws:
- RangeException - if 'anInt' is less than 'minimum'
greaterThan
public static void greaterThan(int anInt, int minimum)
- Throws RangeException if 'anInt' is not greater than 'minimum';
otherwise, does nothing.
- Parameters:
anInt
- value to verify as greater than 'minimum'minimum
- largest unacceptable value for 'anInt'- Throws:
- RangeException - if 'anInt' is not greater than 'minimum'
noGreaterThan
public static void noGreaterThan(int anInt, int maximum)
- Throws RangeException if 'anInt' is greater than 'maximum'; otherwise,
does nothing.
- Parameters:
anInt
- value to verify as not greater than 'maximum'maximum
- largest acceptable value for 'anInt'- Throws:
- RangeException - if 'anInt' is greater than 'maximum'
lessThan
public static void lessThan(int anInt, int maximum)
- Throws RangeException if 'anInt' is not less than 'maximum';
otherwise, does nothing.
- Parameters:
anInt
- value to verify as less than 'minimum'maximum
- smallest unacceptable value for 'anInt'- Throws:
- RangeException - if 'anInt' is not less than 'maximum'
noLessThan
public static void noLessThan(double aDouble, double minimum)
- Throws RangeException if 'aDouble' is less than 'minimum'; otherwise,
does nothing.
- Parameters:
aDouble
- value to verify as not less than 'minimum'minimum
- smallest acceptable value for 'aDouble'- Throws:
- RangeException - if 'aDouble' is less than 'minimum'
greaterThan
public static void greaterThan(double aDouble, double minimum)
- Throws RangeException if 'aDouble' is not greater than 'minimum';
otherwise, does nothing.
- Parameters:
aDouble
- value to verify as greater than 'minimum'minimum
- largest unacceptable value for 'aDouble'- Throws:
- RangeException - if 'aDouble' is not greater than 'minimum'
noGreaterThan
public static void noGreaterThan(double aDouble, double maximum)
- Throws RangeException if 'aDouble' is greater than
'maximum'; otherwise, does nothing.
- Parameters:
aDouble
- value to verify as not greater than 'maximum'maximum
- largest acceptable value for 'aDouble'- Throws:
- RangeException - if 'aDouble' is greater than 'maximum'
lessThan
public static void lessThan(double aDouble, double maximum)
- Throws RangeException if 'aDouble' is not less than 'maximum';
otherwise, does nothing.
- Parameters:
aDouble
- value to verify as less than 'minimum'maximum
- smallest unacceptable value for 'aDouble'- Throws:
- RangeException - if 'aDouble' is not less than 'maximum'
withinRange
public static void withinRange(int anInt, int minimum, int maximum)
- Throws RangeException if 'anInt' is less than 'minimum' or greater
than 'maximum'; otherwise, does nothing.
- Parameters:
anInt
- value to verify as not greater than 'maximum' and not less than 'minimum'minimum
- smallest acceptable value for 'anInt'maximum
- largest acceptable value for 'anInt'- Throws:
- RangeException - if 'anInt' is less than 'minimum' or greater than 'maximum'
withinRange
public static void withinRange(double aDouble, double minimum, double maximum)
- Throws RangeException if 'aDouble' is less than 'minimum' or greater
than 'maximum'; otherwise, does nothing.
- Parameters:
aDouble
- value to verify as not greater than 'maximum' and not less than 'minimum'minimum
- smallest acceptable value for 'aDouble'maximum
- largest acceptable value for 'aDouble'- Throws:
- RangeException - if 'aDouble' is less than 'minimum' or greater than 'maximum'
withinRange
public static void withinRange(int anInt, Range aRange)
- Throws RangeException if 'anInt' is not within 'aRange'; otherwise,
does nothing.
- Parameters:
anInt
- value to verify as within 'aRange'aRange
- acceptable range for 'anInt'- Throws:
- RangeException - if 'anInt' is not within 'aRange'
withinCount
public static void withinCount(int anInt, int count)
- Throws RangeException if 'anInt' is not within a sequence that starts
at 0 and has a length of 'count'; otherwise does nothing.
(e.g. withinCount(myInt, array.length) will verify that 'myInt' is not
less than 0 and not greater than 'array.length'-1)
- Parameters:
anInt
- value to verify as between 0 and 'count' - 1, inclusivecount
- length of sequence- Throws:
- RangeException - if 'anInt' is out of bounds
rangeWithinBounds
public static void rangeWithinBounds(Range aRange, int minimum, int maximum)
- Throws RangeException if 'aRange' is not completely between 'minimum'
and 'maximum', inclusive; otherwise, does nothing.
- Parameters:
aRange
- range to verify as between 'minimum' and 'maximum'minimum
- smallest acceptable index in 'aRange'maximum
- largest acceptable index in 'aRange'- Throws:
- RangeException - if 'aRange' is out of bounds
rangeWithinCount
public static void rangeWithinCount(Range aRange, int count)
- Throws RangeException if 'aRange' is not completely within a sequence
that starts at 0 and has a length of 'count'; otherwise does nothing.
(e.g. rangeWithinCount(range, array.length) will verify that 'range'
does not start before 0 and does not end after 'array.length'-1).
- Parameters:
aRange
- range to verify as between 0 and 'count' - 1, inclusivecount
- length of sequence- Throws:
- RangeException - if 'aRange' is out of bounds
rangeWithinString
public static void rangeWithinString(Range aRange, java.lang.String aString)
- Checks a string and a range which is intended to indicate a substring.
Throws IllegalArgumentException if either argument is null. Throws
RangeException if aRange does not indicate a valid substring of
aString.
- Parameters:
aRange
- A range which must be contained within the string.aString
- A string to use for verifying the range.- Throws:
- java.lang.IllegalArgumentException - if either argument is null
- RangeException - if the range is not contained within the string
isTrue
public static void isTrue(boolean generalTest, java.lang.String message)
- Throws IllegalArgumentException if 'generalTest' is false; otherwise,
does nothing. 'message' will be the message of the exception. 'message'
may be null, but use of a meaningful message is recommended.
- Parameters:
generalTest
- value to verify as truemessage
- message describing the failure- Throws:
- java.lang.IllegalArgumentException - if 'generalTest' is false
- See Also:
isFalse(boolean generalTest, String message)
isFalse
public static void isFalse(boolean generalTest, java.lang.String message)
- Identical to isTrue, except the test is inverted.
- Parameters:
generalTest
- value to verify as falsemessage
- message describing the failure- Throws:
- java.lang.IllegalArgumentException - if 'generalTest' is false
- See Also:
isTrue(boolean generalTest, String message)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |