unannoy.util
Class ArgCheck

java.lang.Object
  |
  +--unannoy.util.ArgCheck

public class ArgCheck
extends java.lang.Object

Generic functions for making sure your functions are not being given garbage. This replaces the code like

 if (myArg == null || myArg.length() == 0) {
   String error = "myArg should not be null or empty";
   throw new IllegalArgumentException(error);
 } 
 

with something like this

 ArgCheck.notNullOrEmpty("myArg", myArg);
 

Naturally, this is all nicely consolidated in one place, it tries to be somewhat intelligent about things and give you as precise error messages as it can

Version:
$Revision: 1.1.1.1 $
$Date: 2003/03/19 15:49:03 $
Author:
Eric Kow (kow at loria point fr)

Constructor Summary
ArgCheck()
           
 
Method Summary
static java.lang.String argString(java.lang.String argName)
          Returns an appropriate String to describe the name of the illegal argument (it puts quotation marks around it ; yippee)
static java.lang.String argString(java.lang.String argName, java.lang.String argValue)
          Returns an appropriate String to describe the illegal argument
static java.lang.String beginMessage(java.lang.String location)
          Returns an appropriate String to begin the message of an IllegalArgumentException.
static java.lang.String beginMessage(java.lang.String location, java.lang.String argName)
          Returns an appropriate String to begin the message of an IllegalArgumentException.
static java.lang.String beginMessage(java.lang.String location, java.lang.String argName, java.lang.String argValue)
          Returns an appropriate String to begin the message of an IllegalArgumentException.
static void notNull(java.lang.String argumentName, java.lang.Object argumentValue)
          Checks that an argument is not null
static void notNull(java.lang.String location, java.lang.String argumentName, java.lang.Object argumentValue)
          Checks that an argument is not null
static void notNullOrEmpty(java.lang.String argumentName, java.lang.String argumentValue)
          Checks that an argument's value is neither null or empty
static void notNullOrEmpty(java.lang.String location, java.lang.String argumentName, java.lang.String argumentValue)
          Checks that an argument's value is neither null or empty
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgCheck

public ArgCheck()
Method Detail

notNullOrEmpty

public static void notNullOrEmpty(java.lang.String argumentName,
                                  java.lang.String argumentValue)
                           throws NullArgumentException
Checks that an argument's value is neither null or empty

Parameters:
argumentName - the name or description of the argument
Throws:
NullArgumentException - if its value is null or empty

notNullOrEmpty

public static void notNullOrEmpty(java.lang.String location,
                                  java.lang.String argumentName,
                                  java.lang.String argumentValue)
                           throws NullArgumentException
Checks that an argument's value is neither null or empty

Parameters:
location - a description of where this check is performed
argumentName - the name or description of the argument
Throws:
NullArgumentException - if its value is null or empty

notNull

public static void notNull(java.lang.String argumentName,
                           java.lang.Object argumentValue)
                    throws NullArgumentException
Checks that an argument is not null

Parameters:
argumentName - the name or description of the argument
Throws:
NullArgumentException - if its value is null

notNull

public static void notNull(java.lang.String location,
                           java.lang.String argumentName,
                           java.lang.Object argumentValue)
                    throws NullArgumentException
Checks that an argument is not null

Parameters:
location - a description of where this check is performed
argumentName - the name or description of the argument
Throws:
NullArgumentException - if its value is null

beginMessage

public static java.lang.String beginMessage(java.lang.String location)
Returns an appropriate String to begin the message of an IllegalArgumentException. It should result in something like 'In "myFunction":' which you will then have to complete yourself.

Parameters:
location - a description of where the error occured
Returns:
a good beginning for an IllegalArgumentException message

beginMessage

public static java.lang.String beginMessage(java.lang.String location,
                                            java.lang.String argName)
Returns an appropriate String to begin the message of an IllegalArgumentException. It should result in something like 'In "myFunction": argument "blah" which you will have to complete yourself

Parameters:
location - a description of where the error occured
argName - the name of the illegal argument
Returns:
a good beginning for an IllegalArgumentException message

beginMessage

public static java.lang.String beginMessage(java.lang.String location,
                                            java.lang.String argName,
                                            java.lang.String argValue)
Returns an appropriate String to begin the message of an IllegalArgumentException. It should result in something like 'In "myFunction": argument "blah" with value "foo" ', which you will have to complete yourself

Parameters:
location - a description of where the error occured
argName - the name of the illegal argument
argValue - the value of the illegal argument
Returns:
a good beginning for an IllegalArgumentException message

argString

public static java.lang.String argString(java.lang.String argName)
Returns an appropriate String to describe the name of the illegal argument (it puts quotation marks around it ; yippee)


argString

public static java.lang.String argString(java.lang.String argName,
                                         java.lang.String argValue)
Returns an appropriate String to describe the illegal argument