org.apache.commons.lang
クラス Validate

java.lang.Object
  拡張org.apache.commons.lang.Validate

public class Validate
extends Object

Assists in validating arguments.

The class is based along the lines of JUnit. If an argument value is deemed invalid, an IllegalArgumentException is thrown. For example:

 Validate.isTrue( i > 0, "The value must be greater than zero: ", i);
 Validate.notNull( surname, "The surname must not be null");
 

導入されたバージョン:
2.0
バージョン:
$Id: Validate.java,v 1.1.1.1 2004/02/13 10:02:05 hioki Exp $
作成者:
Ola Berg, Stephen Colebourne, Gary Gregory
翻訳状況:
訳者募集中

コンストラクタの概要
Validate()
          Constructor.
 
メソッドの概要
static void isTrue(boolean expression)
          Validate an argument, throwing IllegalArgumentException if the test result is false.
static void isTrue(boolean expression, String message)
          Validate an argument, throwing IllegalArgumentException if the test result is false.
static void isTrue(boolean expression, String message, double value)
          Validate an argument, throwing IllegalArgumentException if the test result is false.
static void isTrue(boolean expression, String message, long value)
          Validate an argument, throwing IllegalArgumentException if the test result is false.
static void isTrue(boolean expression, String message, Object value)
          Validate an argument, throwing IllegalArgumentException if the test result is false.
static void noNullElements(Collection collection)
          Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null.
static void noNullElements(Collection collection, String message)
          Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null.
static void noNullElements(Object[] array)
          Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null.
static void noNullElements(Object[] array, String message)
          Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null.
static void notEmpty(Collection collection)
          Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements).
static void notEmpty(Collection collection, String message)
          Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements).
static void notEmpty(Map map)
          Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements).
static void notEmpty(Map map, String message)
          Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements).
static void notEmpty(Object[] array)
          Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements).
static void notEmpty(Object[] array, String message)
          Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements).
static void notEmpty(String string)
          Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).
static void notEmpty(String string, String message)
          Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).
static void notNull(Object object)
          Validate an argument, throwing IllegalArgumentException if the argument is null.
static void notNull(Object object, String message)
          Validate an argument, throwing IllegalArgumentException if the argument is null.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

コンストラクタの詳細

Validate

public Validate()
Constructor. This class should not normally be instantiated.

メソッドの詳細

isTrue

public static void isTrue(boolean expression,
                          String message,
                          Object value)

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( myObject.isOk(), "The object is not OK: ", myObject);
 

For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error.

パラメータ:
expression - a boolean expression
message - the exception message you would like to see if the expression is false
value - the value to append to the message in case of error
例外:
IllegalArgumentException - if expression is false

isTrue

public static void isTrue(boolean expression,
                          String message,
                          long value)

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( i > 0, "The value must be greater than zero: ", i);
 

For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error.

パラメータ:
expression - a boolean expression
message - the exception message you would like to see if the expression is false
value - the value to append to the message in case of error
例外:
IllegalArgumentException - if expression is false

isTrue

public static void isTrue(boolean expression,
                          String message,
                          double value)

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( d > 0.0, "The value must be greater than zero: ", d);
 

For performance reasons, the object is passed as a separate parameter and appended to the message string only in the case of an error.

パラメータ:
expression - a boolean expression
message - the exception message you would like to see if the expression is false
value - the value to append to the message in case of error
例外:
IllegalArgumentException - if expression is false

isTrue

public static void isTrue(boolean expression,
                          String message)

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( (i > 0), "The value must be greater than zero");
 Validate.isTrue( myObject.isOk(), "The object is not OK");
 

For performance reasons, the message string should not involve a string append, instead use the isTrue(boolean, String, Object) method.

パラメータ:
expression - a boolean expression
message - the exception message you would like to see if the expression is false
例外:
IllegalArgumentException - if expression is false

isTrue

public static void isTrue(boolean expression)

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( i > 0 );
 Validate.isTrue( myObject.isOk() );
 

The message in the exception is 'The validated expression is false'.

パラメータ:
expression - a boolean expression
例外:
IllegalArgumentException - if expression is false

notNull

public static void notNull(Object object,
                           String message)

Validate an argument, throwing IllegalArgumentException if the argument is null.

 Validate.notNull(myObject, "The object must not be null");
 

パラメータ:
object - the object to check is not null
message - the exception message you would like to see if the object is null
例外:
IllegalArgumentException - if the object is null

notNull

public static void notNull(Object object)

Validate an argument, throwing IllegalArgumentException if the argument is null.

 Validate.notNull(myObject);
 

The message in the exception is 'The validated object is null'.

パラメータ:
object - the object to check is not null
例外:
IllegalArgumentException - if the object is null

notEmpty

public static void notEmpty(Object[] array,
                            String message)

Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements).

 Validate.notEmpty(myArray, "The array must not be empty");
 

パラメータ:
array - the array to check is not empty
message - the exception message you would like to see if the array is empty
例外:
IllegalArgumentException - if the array is empty

notEmpty

public static void notEmpty(Object[] array)

Validate an argument, throwing IllegalArgumentException if the argument array is empty (null or no elements).

 Validate.notEmpty(myArray);
 

The message in the exception is 'The validated array is empty'.

パラメータ:
array - the array to check is not empty
例外:
IllegalArgumentException - if the array is empty

notEmpty

public static void notEmpty(Collection collection,
                            String message)

Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements).

 Validate.notEmpty(myCollection, "The collection must not be empty");
 

パラメータ:
collection - the collection to check is not empty
message - the exception message you would like to see if the collection is empty
例外:
IllegalArgumentException - if the collection is empty

notEmpty

public static void notEmpty(Collection collection)

Validate an argument, throwing IllegalArgumentException if the argument Collection is empty (null or no elements).

 Validate.notEmpty(myCollection);
 

The message in the exception is 'The validated collection is empty'.

パラメータ:
collection - the collection to check is not empty
例外:
IllegalArgumentException - if the collection is empty

notEmpty

public static void notEmpty(Map map,
                            String message)

Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements).

 Validate.notEmpty(myMap, "The collection must not be empty");
 

パラメータ:
map - the map to check is not empty
message - the exception message you would like to see if the map is empty
例外:
IllegalArgumentException - if the map is empty

notEmpty

public static void notEmpty(Map map)

Validate an argument, throwing IllegalArgumentException if the argument Map is empty (null or no elements).

 Validate.notEmpty(myMap);
 

The message in the exception is 'The validated map is empty'.

パラメータ:
map - the map to check is not empty
例外:
IllegalArgumentException - if the map is empty

notEmpty

public static void notEmpty(String string,
                            String message)

Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).

 Validate.notEmpty(myString, "The string must not be empty");
 

パラメータ:
string - the string to check is not empty
message - the exception message you would like to see if the string is empty
例外:
IllegalArgumentException - if the string is empty

notEmpty

public static void notEmpty(String string)

Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).

 Validate.notEmpty(myString);
 

The message in the exception is 'The validated string is empty'.

パラメータ:
string - the string to check is not empty
例外:
IllegalArgumentException - if the string is empty

noNullElements

public static void noNullElements(Object[] array,
                                  String message)

Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null.

 Validate.notEmpty(myArray, "The array must not contain null elements");
 

パラメータ:
array - the array to check
message - the exception message if the array has null elements
例外:
IllegalArgumentException - if the array has null elements or is null

noNullElements

public static void noNullElements(Object[] array)

Validate an argument, throwing IllegalArgumentException if the argument array has null elements or is null.

 Validate.notEmpty(myArray);
 

The message in the exception is 'The validated array contains null element at index: '.

パラメータ:
array - the array to check
例外:
IllegalArgumentException - if the array has null elements or is null

noNullElements

public static void noNullElements(Collection collection,
                                  String message)

Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null.

 Validate.notEmpty(myCollection, "The collection must not contain null elements");
 

パラメータ:
collection - the collection to check
message - the exception message if the array has null elements
例外:
IllegalArgumentException - if the collection has null elements or is null

noNullElements

public static void noNullElements(Collection collection)

Validate an argument, throwing IllegalArgumentException if the argument collection has null elements or is null.

 Validate.notEmpty(myCollection);
 

The message in the exception is 'The validated collection contains null element at index: '.

パラメータ:
collection - the collection to check
例外:
IllegalArgumentException - if the collection has null elements or is null


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation