net.sf.webmancer.util
Class ContractChecker

java.lang.Object
  extended by net.sf.webmancer.util.ContractChecker

public class ContractChecker
extends java.lang.Object

This class defines a set of methods for contract checking.

Author:
Michal Burda

Method Summary
static void checkState(boolean legalState, java.lang.String errorMessage)
          Throw the IllegalStateException with the given errorMessage if the legalState is false.
static void mustBe(boolean condition, java.lang.String message)
          Throws the IllegalArgumentException if the given condition is false.
static void mustBeGreater(double parameter, double ref, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is lower or equal to the given reference value ref.
static void mustBeGreaterEq(double parameter, double ref, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is lower than the given reference value ref.
static void mustBeInRange(double parameter, double lowerBound, double upperBound, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is not in the range specified by the lowerBound and upperBound values.
static void mustBeInstanceOf(java.lang.Object parameter, java.lang.Class[] classes, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is not an instance of either class in classes.
static void mustBeInstanceOf(java.lang.Object parameter, java.lang.Class clazz, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is not an instance of class clazz.
static void mustBeLess(double parameter, double ref, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is greater or equal to the given reference value ref.
static void mustBeLessEq(double parameter, double ref, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is greater than the given reference value ref.
static void mustBeNegative(double parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is greater or equal to zero.
static void mustBePositive(double parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is lower or equal to zero.
static void mustNotBeEmpty(java.lang.Object[] parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is null or an array of size 0.
static void mustNotBeEmpty(java.lang.String parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is null or empty string (after trim).
static void mustNotBeNegative(double parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is lower than zero.
static void mustNotBeNull(java.lang.Object parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is null.
static void mustNotBePositive(double parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is greater than zero.
static void mustNotBeZero(double parameter, java.lang.String name)
          Throws the IllegalArgumentException if the given parameter is equal to zero
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkState

public static void checkState(boolean legalState,
                              java.lang.String errorMessage)
                       throws java.lang.IllegalStateException
Throw the IllegalStateException with the given errorMessage if the legalState is false.

Parameters:
legalState - The state to be checked
errorMessage - The error message
Throws:
java.lang.IllegalStateException - Thrown if the legalState is false

mustBe

public static void mustBe(boolean condition,
                          java.lang.String message)
                   throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given condition is false.

Parameters:
condition - The condition that must be true or the exception is thrown
message - The error message
Throws:
java.lang.IllegalArgumentException - Thrown if the condition is false

mustBeInstanceOf

public static void mustBeInstanceOf(java.lang.Object parameter,
                                    java.lang.Class clazz,
                                    java.lang.String name)
                             throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is not an instance of class clazz.

Parameters:
parameter - The parameter being checked
clazz - The reference class
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeInstanceOf

public static void mustBeInstanceOf(java.lang.Object parameter,
                                    java.lang.Class[] classes,
                                    java.lang.String name)
                             throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is not an instance of either class in classes.

Parameters:
parameter - The parameter being checked
classes - The array of classes
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustNotBeNull

public static void mustNotBeNull(java.lang.Object parameter,
                                 java.lang.String name)
                          throws java.lang.NullPointerException
Throws the IllegalArgumentException if the given parameter is null.

Parameters:
parameter - The parameter that has to be non-null
name - The name of the parameter being checked
Throws:
java.lang.NullPointerException - Thrown if the checked condition is not satisfied

mustNotBeEmpty

public static void mustNotBeEmpty(java.lang.String parameter,
                                  java.lang.String name)
                           throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is null or empty string (after trim).

Parameters:
parameter - The parameter that has to be non-null and non-empty string
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustNotBeEmpty

public static void mustNotBeEmpty(java.lang.Object[] parameter,
                                  java.lang.String name)
                           throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is null or an array of size 0.

Parameters:
parameter - The parameter that has to be non-null and non-zero-length array
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeNegative

public static void mustBeNegative(double parameter,
                                  java.lang.String name)
                           throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is greater or equal to zero.

Parameters:
parameter - The parameter that has to be negative
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBePositive

public static void mustBePositive(double parameter,
                                  java.lang.String name)
                           throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is lower or equal to zero.

Parameters:
parameter - The parameter that has to be positive
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustNotBeNegative

public static void mustNotBeNegative(double parameter,
                                     java.lang.String name)
                              throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is lower than zero.

Parameters:
parameter - The parameter that has to be positive or zero
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustNotBePositive

public static void mustNotBePositive(double parameter,
                                     java.lang.String name)
                              throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is greater than zero.

Parameters:
parameter - The parameter that has to be negative or zero
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustNotBeZero

public static void mustNotBeZero(double parameter,
                                 java.lang.String name)
                          throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is equal to zero

Parameters:
parameter - The parameter that has to be non-zero
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeGreater

public static void mustBeGreater(double parameter,
                                 double ref,
                                 java.lang.String name)
                          throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is lower or equal to the given reference value ref.

Parameters:
parameter - The parameter that has to be greater than given reference value ref
ref - The reference value the parameter is compared to
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeGreaterEq

public static void mustBeGreaterEq(double parameter,
                                   double ref,
                                   java.lang.String name)
                            throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is lower than the given reference value ref.

Parameters:
parameter - The parameter that has to be greater or equal to the given reference value ref
ref - The reference value the parameter is compared to
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeLess

public static void mustBeLess(double parameter,
                              double ref,
                              java.lang.String name)
                       throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is greater or equal to the given reference value ref.

Parameters:
parameter - The parameter that has to be lower than given reference value ref
ref - The reference value the parameter is compared to
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeLessEq

public static void mustBeLessEq(double parameter,
                                double ref,
                                java.lang.String name)
                         throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is greater than the given reference value ref.

Parameters:
parameter - The parameter that has to be lower or equal to the given reference value ref
ref - The reference value the parameter is compared to
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied

mustBeInRange

public static void mustBeInRange(double parameter,
                                 double lowerBound,
                                 double upperBound,
                                 java.lang.String name)
                          throws java.lang.IllegalArgumentException
Throws the IllegalArgumentException if the given parameter is not in the range specified by the lowerBound and upperBound values.

Parameters:
parameter - The parameter that has to be in the range specified by the lowerBound and upperBound values.
lowerBound - The lower bound of the interval the parameter is compared to
upperBound - The upper bound of the interval the parameter is compared to
name - The name of the parameter being checked
Throws:
java.lang.IllegalArgumentException - Thrown if the checked condition is not satisfied


Copyright © 2006-2007. All Rights Reserved.