org.esa.beam.util
Class Guardian

java.lang.Object
  extended by org.esa.beam.util.Guardian

public class Guardian
extends Object

This utility class which provides several static 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$
Author:
Norman Fomferra, Sabine Embacher

Constructor Summary
Guardian()
           
 
Method Summary
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 not null.
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, Object[] exprValue)
           
static void assertNotNullOrEmpty(String exprText, short[] exprValue)
           
static void assertNotNullOrEmpty(String exprText, String exprValue)
          Checks whether the given (parameter) value string is not null 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 is true.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Guardian

public Guardian()
Method Detail

assertTrue

public static void assertTrue(String message,
                              boolean condition)
Checks whether the given argument value is true. If not, an IllegalArgumentException 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 text
condition - the condition which must be true
Throws:
IllegalArgumentException - if condition is false

assertNotNull

public static void assertNotNull(String exprText,
                                 Object exprValue)
Checks whether the given argument value is not null. If not, an IllegalArgumentException 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 text
exprValue - the test expression result
Throws:
IllegalArgumentException - if exprValue is null

assertNotNullOrEmpty

public static void assertNotNullOrEmpty(String exprText,
                                        String exprValue)
Checks whether the given (parameter) value string is not null and not empty. If not, an IllegalArgumentException 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 text
exprValue - the test expression result
Throws:
IllegalArgumentException - if exprValue is null 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)

assertNotNullOrEmpty

public static void assertNotNullOrEmpty(String exprText,
                                        Object[] 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, an IllegalArgumentException 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 text
exprValue - the test expression result
limit - the lower limit for the expression result
Throws:
IllegalArgumentException - if the exprValue is less than or equal to limit

assertEquals

public static void assertEquals(String exprText,
                                boolean exprValue,
                                boolean expectedValue)
Checks if the given values are equal. If not, an IllegalArgumentException 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 text
exprValue - the test expression result
expectedValue - the expected value
Throws:
IllegalArgumentException - if the exprValue is not equal to expectedValue

assertEquals

public static void assertEquals(String exprText,
                                long exprValue,
                                long expectedValue)
Checks if the given values are equal. If not, an IllegalArgumentException 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 text
exprValue - the test expression result
expectedValue - the expected value
Throws:
IllegalArgumentException - if the exprValue is not equal to expectedValue

assertEquals

public static void assertEquals(String exprText,
                                Object exprValue,
                                Object expectedValue)
Checks if the given objects are equal. If not, an IllegalArgumentException 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 text
exprValue - the test expression result
expectedValue - the expected value
Throws:
IllegalArgumentException - if the exprValue is not equal to expectedValue

assertSame

public static void assertSame(String exprText,
                              Object exprValue,
                              Object expectedValue)
Checks if the given objects are the same instances. If not, an IllegalArgumentException 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 text
exprValue - the actual value
expectedValue - the expected value
Throws:
IllegalArgumentException - if the expected is not identical to actual

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, an IllegalArgumentException 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 text
exprValue - the expression result
rangeMin - the range lower limit
rangeMax - the range upper limit
Throws:
IllegalArgumentException - if the exprValue is less than rangeMin or greater than rangeMax

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, an IllegalArgumentException 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 text
exprValue - the expression result
rangeMin - the range lower limit
rangeMax - the range upper limit
Throws:
IllegalArgumentException - if the exprValue is less than rangeMin or greater than rangeMax


Copyright © 2002-2012 Brockmann Consult GmbH. All Rights Reserved.