org.afcs.warts.util
Class ValidationUtils

java.lang.Object
  extended byorg.afcs.warts.util.ValidationUtils

public final class ValidationUtils
extends java.lang.Object

The ValidationUtils class contains various utility methods for validating values. These can be used for convenient argument checking.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 17 September 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Method Summary
static void checkArrayIndex(java.lang.String name, int index, int arrayLength)
          Checks that the specified index can be used to reference objects in an array of the specified length, throwing an IllegalArgumentException with the specified name if not.
static void checkIndexInRange(java.lang.String name, int index, int minValue, int maxValue)
          Checks that the specified index is within the specified range, throwing an IllegalArgumentException with the specified name if not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkArrayIndex

public static void checkArrayIndex(java.lang.String name,
                                   int index,
                                   int arrayLength)
Checks that the specified index can be used to reference objects in an array of the specified length, throwing an IllegalArgumentException with the specified name if not.

Parameters:
name - The name of the index being checked (usually the name of the variable in the calling method). This is used in the message of the thrown exception.
index - The index to check.
arrayLength - The length of the array that the index refers to.
Throws:
java.lang.IllegalArgumentException - If index is less than 0 or greater than arrayLength-1.

checkIndexInRange

public static void checkIndexInRange(java.lang.String name,
                                     int index,
                                     int minValue,
                                     int maxValue)
Checks that the specified index is within the specified range, throwing an IllegalArgumentException with the specified name if not.

Parameters:
name - The name of the index being checked (usually the name of the variable in the calling method). This is used in the message of the thrown exception.
index - The index to check.
minValue - The minimum legal value for index.
maxValue - The maximum legal value for index.
Throws:
java.lang.IllegalArgumentException - If index is less than minValue or greater than maxValue.