Class Guardian
assertXXX methods which can be used to internally check
the arguments passed to methods.
All functions have been implemented with extreme caution in order to provide a maximum performance.
- Version:
- $Revision$ $Date$
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertEquals(String exprText, boolean exprValue, boolean expectedValue) Checks if the given values are equal.static voidassertEquals(String exprText, long exprValue, long expectedValue) Checks if the given values are equal.static voidassertEquals(String exprText, Object exprValue, Object expectedValue) Checks if the given objects are equal.static voidassertGreaterThan(String exprText, long exprValue, long limit) Checks if the given value is greater than the given limit.static voidassertNotNull(String exprText, Object exprValue) Checks whether the given argument value is notnull.static voidassertNotNullOrEmpty(String exprText, byte[] exprValue) static voidassertNotNullOrEmpty(String exprText, char[] exprValue) static voidassertNotNullOrEmpty(String exprText, double[] exprValue) static voidassertNotNullOrEmpty(String exprText, float[] exprValue) static voidassertNotNullOrEmpty(String exprText, int[] exprValue) static voidassertNotNullOrEmpty(String exprText, short[] exprValue) static voidassertNotNullOrEmpty(String exprText, Object[] exprValue) static voidassertNotNullOrEmpty(String exprText, String exprValue) Checks whether the given (parameter) value string is notnulland not empty.static voidassertSame(String exprText, Object exprValue, Object expectedValue) Checks if the given objects are the same instances.static voidassertTrue(String message, boolean condition) Checks whether the given argument value istrue.static voidassertWithinRange(String exprText, double exprValue, double rangeMin, double rangeMax) Checks if the given value are in the given range.static voidassertWithinRange(String exprText, long exprValue, long rangeMin, long rangeMax) Checks if the given value are in the given range.
-
Constructor Details
-
Guardian
public Guardian()
-
-
Method Details
-
assertTrue
Checks whether the given argument value istrue. If not, anIllegalArgumentExceptionis thrown with the given message text.This utility method is used to check arguments passed into methods:
public void setOrigin(double[] point) { Guardian.assertTrue("point.length == 2 || point.length == 3", point.length == 2 || point.length == 3); ... }- Parameters:
message- the message textcondition- the condition which must be true- Throws:
IllegalArgumentException- ifconditionisfalse
-
assertNotNull
Checks whether the given argument value is notnull. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied parameter name.This utility method is used to check arguments passed into methods:
public void setBounds(Rectangle bounds) { Guardian.assertNotNull("bounds", bounds); _bounds = rect; }- Parameters:
exprText- the test expression as textexprValue- the test expression result- Throws:
IllegalArgumentException- ifexprValueisnull
-
assertNotNullOrEmpty
Checks whether the given (parameter) value string is notnulland not empty. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied parameter name.This utility method is used to check arguments passed into methods:
public void setProductId(String productId) { Guardian.assertNotNullOrEmpty("productId", productId); _productId = productId; }- Parameters:
exprText- the test expression as textexprValue- the test expression result- Throws:
IllegalArgumentException- ifexprValueisnullor an empty string
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertNotNullOrEmpty
-
assertGreaterThan
Checks if the given value is greater than the given limit. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied argument name.This utility method is used to check arguments passed into methods:
public void setWeight(long weight) { Guardian.assertGreaterThan("weight", weight, 0); _weight = weight; }- Parameters:
exprText- the test expression as textexprValue- the test expression resultlimit- the lower limit for the expression result- Throws:
IllegalArgumentException- if theexprValueis less than or equal tolimit
-
assertEquals
Checks if the given values are equal. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied message.This utility method is used to check arguments passed into methods:
public void writeDataAtRegion(int x, inty, int w, int h, byte[] data) { Guardian.assertEquals("data.length", data.length, w * h); ... }- Parameters:
exprText- the test expression as textexprValue- the test expression resultexpectedValue- the expected value- Throws:
IllegalArgumentException- if theexprValueis not equal toexpectedValue
-
assertEquals
Checks if the given values are equal. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied message.This utility method is used to check arguments passed into methods:
public void writeDataAtRegion(int x, inty, int w, int h, byte[] data) { Guardian.assertEquals("data.length", data.length, w * h); ... }- Parameters:
exprText- the test expression as textexprValue- the test expression resultexpectedValue- the expected value- Throws:
IllegalArgumentException- if theexprValueis not equal toexpectedValue
-
assertEquals
Checks if the given objects are equal. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied message.This utility method is used to check arguments passed into methods:
public NewBandDialog(final Window parent, ProductNodeList products) { Guardian.assertNotNull("products", products); Guardian.assertEquals("not the expected element type", Product.class, products.getElemType()); ... }- Parameters:
exprText- the test expression as textexprValue- the test expression resultexpectedValue- the expected value- Throws:
IllegalArgumentException- if theexprValueis not equal toexpectedValue
-
assertSame
Checks if the given objects are the same instances. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied message.This utility method is used to check arguments passed into methods:
public NewBandDialog(final Window parent, ProductNodeList products) { Guardian.assertNotNull("products", products); Guardian.assertEquals("not the expected element type", Product.class, products.getElemType()); ... }- Parameters:
exprText- the test expression as textexprValue- the actual valueexpectedValue- the expected value- Throws:
IllegalArgumentException- if theexpectedis not identical toactual
-
assertWithinRange
Checks if the given value are in the given range. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied value name.This utility method is used to check arguments passed into methods:
public void writeDataAtRegion(int x, inty, int w, int h, byte[] data) { Guardian.assertWithinRange("w", w, 0, data.length -1); ... }- Parameters:
exprText- the test expression as textexprValue- the expression resultrangeMin- the range lower limitrangeMax- the range upper limit- Throws:
IllegalArgumentException- if theexprValueis less thanrangeMinor greater thanrangeMax
-
assertWithinRange
public static void assertWithinRange(String exprText, double exprValue, double rangeMin, double rangeMax) Checks if the given value are in the given range. If not, anIllegalArgumentExceptionis thrown with a standardized message text using the supplied value name.This utility method is used to check arguments passed into methods:
public void writeDataAtRegion(int x, inty, int w, int h, byte[] data) { Guardian.assertWithinRange("w", w, 0, data.length); ... }- Parameters:
exprText- the test expression as textexprValue- the expression resultrangeMin- the range lower limitrangeMax- the range upper limit- Throws:
IllegalArgumentException- if theexprValueis less thanrangeMinor greater thanrangeMax
-