org.ops4j.lang
Class NullArgumentException

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

public class NullArgumentException
extends IllegalArgumentException

Exception thrown when the argument to a method or constructor is null and not handled by the method/constructor/class.

The argument in the only constructor of this exception should only take the name of the declared argument that is null, for instance;

     public Person( String name, int age )
     {
         NullArgumentException.validateNotEmpty( name, "name" )
         if( age > 120 )
             throw new IllegalArgumentException( "age > 120" );
         if( age < 0 )
             throw new IllegalArgumentException( "age < 0" );
     }
 

Version:
$Id$
Author:
Open Particpation Software for Java
See Also:
Serialized Form

Constructor Summary
NullArgumentException(String msg)
          Constructor.
 
Method Summary
static void validateNotEmpty(Object[] arrayToCheck, String argumentName)
          Validates that the array instance is not null and that it has entries.
static void validateNotEmpty(Properties propertiesToCheck, String argumentName)
          Validates that the Properties instance is not null and that it has entries.
static void validateNotEmpty(String stringToCheck, boolean trim, String argumentName)
          Validates that the string is not null and not an empty string.
static void validateNotEmpty(String stringToCheck, String argumentName)
          Validates that the string is not null and not an empty string without trimming the string.
static void validateNotEmptyContent(String[] arrayToCheck, boolean trim, String argumentName)
          Validates that the string array instance is not null and that it has entries that are not null or empty.
static void validateNotEmptyContent(String[] arrayToCheck, String argumentName)
          Validates that the string array instance is not null and that it has entries that are not null or empty eithout trimming the string.
static void validateNotNull(Object obj, String objectName)
          Validates that the object obj is not 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

NullArgumentException

public NullArgumentException(String msg)
Constructor.

Parameters:
msg - The message to use in the exception describing the problem.
Method Detail

validateNotNull

public static void validateNotNull(Object obj,
                                   String objectName)
                            throws NullArgumentException
Validates that the object obj is not null.

Parameters:
obj - The object to be tested.
objectName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the stringToCheck is either null or zero characters long.

validateNotEmpty

public static void validateNotEmpty(String stringToCheck,
                                    String argumentName)
                             throws NullArgumentException
Validates that the string is not null and not an empty string without trimming the string.

Parameters:
stringToCheck - The object to be tested.
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the stringToCheck is either null or zero characters long.

validateNotEmpty

public static void validateNotEmpty(String stringToCheck,
                                    boolean trim,
                                    String argumentName)
                             throws NullArgumentException
Validates that the string is not null and not an empty string.

Parameters:
stringToCheck - The object to be tested.
trim - If the elements should be trimmed before checking if empty
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the stringToCheck is either null or zero characters long.

validateNotEmpty

public static void validateNotEmpty(Properties propertiesToCheck,
                                    String argumentName)
                             throws NullArgumentException
Validates that the Properties instance is not null and that it has entries.

Parameters:
propertiesToCheck - The object to be tested.
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the Properties instance is null or does not have any entries.

validateNotEmpty

public static void validateNotEmpty(Object[] arrayToCheck,
                                    String argumentName)
                             throws NullArgumentException
Validates that the array instance is not null and that it has entries.

Parameters:
arrayToCheck - The object to be tested.
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the array instance is null or does not have any entries.
Since:
0.5.0, January 18, 2008

validateNotEmptyContent

public static void validateNotEmptyContent(String[] arrayToCheck,
                                           String argumentName)
                                    throws NullArgumentException
Validates that the string array instance is not null and that it has entries that are not null or empty eithout trimming the string.

Parameters:
arrayToCheck - The object to be tested.
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the array instance is null or does not have any entries.
Since:
0.5.0, January 18, 2008

validateNotEmptyContent

public static void validateNotEmptyContent(String[] arrayToCheck,
                                           boolean trim,
                                           String argumentName)
                                    throws NullArgumentException
Validates that the string array instance is not null and that it has entries that are not null or empty.

Parameters:
arrayToCheck - The object to be tested.
trim - If the elements should be trimmed before checking if empty
argumentName - The name of the object, which is used to construct the exception message.
Throws:
NullArgumentException - if the array instance is null or does not have any entries.
Since:
0.5.0, January 18, 2008


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