org.ops4j.lang
Class PreConditionException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by org.ops4j.lang.PreConditionException
All Implemented Interfaces:
Serializable

public class PreConditionException
extends RuntimeException

PreConditionException is used to validate incoming arguments to methods and if not within the supported ranges, throw an appropriate exception describing the problem.

This Exception is used to make the code more robust, and ensure that clients use it as expected.

See Also:
Serialized Form

Constructor Summary
PreConditionException(String message)
          PreCondition constructor.
 
Method Summary
static void validateEqualTo(double value, double condition, String identifier)
          Validates that the value under test is a particular value.
static void validateEqualTo(long value, long condition, String identifier)
          Validates that the value under test is a particular value.
static void validateEqualTo(Number value, Number condition, String identifier)
          Validates that the value under test is a particular value.
static void validateGreaterThan(double value, double limit, String identifier)
          Validates that the value is greater than a limit.
static void validateGreaterThan(long value, long limit, String identifier)
          Validates that the value is greater than a limit.
static void validateGreaterThan(Number value, Number limit, String identifier)
          Validates that the value is greater than a limit.
static void validateLesserThan(double value, double limit, String identifier)
          Validates that the value is lesser than a limit.
static void validateLesserThan(long value, long limit, String identifier)
          Validates that the value is lesser than a limit.
static void validateLesserThan(Number value, Number limit, String identifier)
          Validates that the value is lesser than a limit.
static void validateNotNull(Object object, String identifier)
          Validates that the object is not null.
static void validateNull(Object object, String identifier)
          Validates that the object is null.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PreConditionException

public PreConditionException(String message)
PreCondition constructor.

Parameters:
message - The composed error message.
Method Detail

validateNotNull

public static void validateNotNull(Object object,
                                   String identifier)
                            throws PreConditionException
Validates that the object is not null.

Parameters:
object - The object to be validated.
identifier - The name of the object.
Throws:
PreConditionException - if the object is null.

validateNull

public static void validateNull(Object object,
                                String identifier)
                         throws PreConditionException
Validates that the object is null.

Parameters:
object - The object to be validated.
identifier - The name of the object.
Throws:
PreConditionException - if the object is not null.

validateGreaterThan

public static void validateGreaterThan(long value,
                                       long limit,
                                       String identifier)
                                throws PreConditionException
Validates that the value is greater than a limit.

This method ensures that value > limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must exceed.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateGreaterThan

public static void validateGreaterThan(double value,
                                       double limit,
                                       String identifier)
                                throws PreConditionException
Validates that the value is greater than a limit.

This method ensures that value > limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must exceed.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateGreaterThan

public static void validateGreaterThan(Number value,
                                       Number limit,
                                       String identifier)
                                throws PreConditionException
Validates that the value is greater than a limit.

This method ensures that value > limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must exceed.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateLesserThan

public static void validateLesserThan(long value,
                                      long limit,
                                      String identifier)
                               throws PreConditionException
Validates that the value is lesser than a limit.

This method ensures that value < limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must be smaller than.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateLesserThan

public static void validateLesserThan(double value,
                                      double limit,
                                      String identifier)
                               throws PreConditionException
Validates that the value is lesser than a limit.

This method ensures that value < limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must be smaller than.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateLesserThan

public static void validateLesserThan(Number value,
                                      Number limit,
                                      String identifier)
                               throws PreConditionException
Validates that the value is lesser than a limit.

This method ensures that value < limit.

Parameters:
identifier - The name of the object.
limit - The limit that the value must be smaller than.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateEqualTo

public static void validateEqualTo(long value,
                                   long condition,
                                   String identifier)
                            throws PreConditionException
Validates that the value under test is a particular value.

This method ensures that value == condition.

Parameters:
identifier - The name of the object.
condition - The condition value.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateEqualTo

public static void validateEqualTo(double value,
                                   double condition,
                                   String identifier)
                            throws PreConditionException
Validates that the value under test is a particular value.

This method ensures that value == condition.

Parameters:
identifier - The name of the object.
condition - The condition value.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.

validateEqualTo

public static void validateEqualTo(Number value,
                                   Number condition,
                                   String identifier)
                            throws PreConditionException
Validates that the value under test is a particular value.

This method ensures that value == condition.

Parameters:
identifier - The name of the object.
condition - The condition value.
value - The value to be tested.
Throws:
PreConditionException - if the condition is not met.


Copyright © 2006-2013 OPS4J - Open Participation Software for Java. All Rights Reserved.