Class Guardian
- java.lang.Object
-
- org.esa.snap.core.util.Guardian
-
public class Guardian extends Object
This utility class which provides several staticassert
XXX 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 Constructor Description Guardian()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertEquals(String exprText, boolean exprValue, boolean expectedValue)
Checks if the given values are equal.static void
assertEquals(String exprText, long exprValue, long expectedValue)
Checks if the given values are equal.static void
assertEquals(String exprText, Object exprValue, Object expectedValue)
Checks if the given objects are equal.static void
assertGreaterThan(String exprText, long exprValue, long limit)
Checks if the given value is greater than the given limit.static void
assertNotNull(String exprText, Object exprValue)
Checks whether the given argument value is notnull
.static void
assertNotNullOrEmpty(String exprText, byte[] exprValue)
static void
assertNotNullOrEmpty(String exprText, char[] exprValue)
static void
assertNotNullOrEmpty(String exprText, double[] exprValue)
static void
assertNotNullOrEmpty(String exprText, float[] exprValue)
static void
assertNotNullOrEmpty(String exprText, int[] exprValue)
static void
assertNotNullOrEmpty(String exprText, short[] exprValue)
static void
assertNotNullOrEmpty(String exprText, Object[] exprValue)
static void
assertNotNullOrEmpty(String exprText, String exprValue)
Checks whether the given (parameter) value string is notnull
and not empty.static void
assertSame(String exprText, Object exprValue, Object expectedValue)
Checks if the given objects are the same instances.static void
assertTrue(String message, boolean condition)
Checks whether the given argument value istrue
.static void
assertWithinRange(String exprText, double exprValue, double rangeMin, double rangeMax)
Checks if the given value are in the given range.static void
assertWithinRange(String exprText, long exprValue, long rangeMin, long rangeMax)
Checks if the given value are in the given range.
-
-
-
Method Detail
-
assertTrue
public static void assertTrue(String message, boolean condition)
Checks whether the given argument value istrue
. If not, anIllegalArgumentException
is 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
- ifcondition
isfalse
-
assertNotNull
public static void assertNotNull(String exprText, Object exprValue)
Checks whether the given argument value is notnull
. If not, anIllegalArgumentException
is 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
- ifexprValue
isnull
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, String exprValue)
Checks whether the given (parameter) value string is notnull
and not empty. If not, anIllegalArgumentException
is 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
- ifexprValue
isnull
or an empty string
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, byte[] exprValue)
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, char[] exprValue)
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, short[] exprValue)
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, int[] exprValue)
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, float[] exprValue)
-
assertNotNullOrEmpty
public static void assertNotNullOrEmpty(String exprText, double[] exprValue)
-
assertGreaterThan
public static void assertGreaterThan(String exprText, long exprValue, long limit)
Checks if the given value is greater than the given limit. If not, anIllegalArgumentException
is 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 theexprValue
is less than or equal tolimit
-
assertEquals
public static void assertEquals(String exprText, boolean exprValue, boolean expectedValue)
Checks if the given values are equal. If not, anIllegalArgumentException
is 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 theexprValue
is not equal toexpectedValue
-
assertEquals
public static void assertEquals(String exprText, long exprValue, long expectedValue)
Checks if the given values are equal. If not, anIllegalArgumentException
is 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 theexprValue
is not equal toexpectedValue
-
assertEquals
public static void assertEquals(String exprText, Object exprValue, Object expectedValue)
Checks if the given objects are equal. If not, anIllegalArgumentException
is 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 theexprValue
is not equal toexpectedValue
-
assertSame
public static void assertSame(String exprText, Object exprValue, Object expectedValue)
Checks if the given objects are the same instances. If not, anIllegalArgumentException
is 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 theexpected
is not identical toactual
-
assertWithinRange
public static void assertWithinRange(String exprText, long exprValue, long rangeMin, long rangeMax)
Checks if the given value are in the given range. If not, anIllegalArgumentException
is 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 theexprValue
is less thanrangeMin
or 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, anIllegalArgumentException
is 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 theexprValue
is less thanrangeMin
or greater thanrangeMax
-
-