Checkstyle and trailing spaces.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1083215 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oliver Heger 2011-03-19 16:36:39 +00:00
parent d12117713b
commit 4c8462b9f5
1 changed files with 191 additions and 177 deletions

View File

@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -22,22 +22,23 @@
import java.util.regex.Pattern;
/**
* <p>This class assists in validating arguments. The validation methods are
* based along the following principles:
* <p>This class assists in validating arguments. The validation methods are
* based along the following principles:
* <ul>
* <li>An invalid {@code null} argument causes a {@link NullPointerException}.</li>
* <li>A non-{@code null} argument causes an {@link IllegalArgumentException}.</li>
* <li>An invalid index into an array/collection/map/string causes an {@link IndexOutOfBoundsException}.</li>
* <li>An invalid index into an array/collection/map/string causes an {@link IndexOutOfBoundsException}.</li>
* </ul>
*
* <p>All exceptions messages are <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax">format strings</a>
*
* <p>All exceptions messages are
* <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax">format strings</a>
* as defined by the Java platform. For example:</p>
*
*
* <pre>
* Validate.isTrue(i > 0, "The value must be greater than zero: %d", i);
* Validate.notNull(surname, "The surname must not be %s", null);
* </pre>
*
*
* <p>#ThreadSafe#</p>
* @author Apache Software Foundation
* @author <a href="mailto:ola.berg@arkitema.se">Ola Berg</a>
@ -50,23 +51,31 @@
*/
public class Validate {
private static final String DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE = "The value %s is not in the specified exclusive range of %s to %s";
private static final String DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE = "The value %s is not in the specified inclusive range of %s to %s";
private static final String DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE =
"The value %s is not in the specified exclusive range of %s to %s";
private static final String DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE =
"The value %s is not in the specified inclusive range of %s to %s";
private static final String DEFAULT_MATCHES_PATTERN_EX = "The string %s does not match the pattern %s";
private static final String DEFAULT_IS_NULL_EX_MESSAGE = "The validated object is null";
private static final String DEFAULT_IS_TRUE_EX_MESSAGE = "The validated expression is false";
private static final String DEFAULT_NO_NULL_ELEMENTS_ARRAY_EX_MESSAGE = "The validated array contains null element at index: %d";
private static final String DEFAULT_NO_NULL_ELEMENTS_COLLECTION_EX_MESSAGE = "The validated collection contains null element at index: %d";
private static final String DEFAULT_NO_NULL_ELEMENTS_ARRAY_EX_MESSAGE =
"The validated array contains null element at index: %d";
private static final String DEFAULT_NO_NULL_ELEMENTS_COLLECTION_EX_MESSAGE =
"The validated collection contains null element at index: %d";
private static final String DEFAULT_NOT_BLANK_EX_MESSAGE = "The validated character sequence is blank";
private static final String DEFAULT_NOT_EMPTY_ARRAY_EX_MESSAGE = "The validated array is empty";
private static final String DEFAULT_NOT_EMPTY_CHAR_SEQUENCE_EX_MESSAGE = "The validated character sequence is empty";
private static final String DEFAULT_NOT_EMPTY_CHAR_SEQUENCE_EX_MESSAGE =
"The validated character sequence is empty";
private static final String DEFAULT_NOT_EMPTY_COLLECTION_EX_MESSAGE = "The validated collection is empty";
private static final String DEFAULT_NOT_EMPTY_MAP_EX_MESSAGE = "The validated map is empty";
private static final String DEFAULT_VALID_INDEX_ARRAY_EX_MESSAGE = "The validated array index is invalid: %d";
private static final String DEFAULT_VALID_INDEX_CHAR_SEQUENCE_EX_MESSAGE = "The validated character sequence index is invalid: %d";
private static final String DEFAULT_VALID_INDEX_COLLECTION_EX_MESSAGE = "The validated collection index is invalid: %d";
private static final String DEFAULT_VALID_INDEX_CHAR_SEQUENCE_EX_MESSAGE =
"The validated character sequence index is invalid: %d";
private static final String DEFAULT_VALID_INDEX_COLLECTION_EX_MESSAGE =
"The validated collection index is invalid: %d";
private static final String DEFAULT_VALID_STATE_EX_MESSAGE = "The validated state is false";
private static final String DEFAULT_IS_ASSIGNABLE_EX_MESSAGE = "The validated class can not be converted to the %s class";
private static final String DEFAULT_IS_ASSIGNABLE_EX_MESSAGE =
"The validated class can not be converted to the %s class";
private static final String DEFAULT_IS_INSTANCE_OF_EX_MESSAGE = "The validated object is not an instance of %s";
/**
@ -80,16 +89,16 @@ public Validate() {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the argument condition is {@code true}; otherwise
* <p>Validate that the argument condition is {@code true}; otherwise
* throwing an exception with the specified message. This method is useful when
* validating according to an arbitrary boolean expression, such as validating a
* validating according to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>Validate.isTrue(i > 0.0, "The value must be greater than zero: %d", i);</pre>
*
* <p>For performance reasons, the long value is passed as a separate parameter and
* appended to the exception message only in the case of an error.</p>
*
*
* @param expression the boolean expression to check
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param value the value to append to the message when invalid
@ -105,17 +114,17 @@ public static void isTrue(boolean expression, String message, long value) {
}
/**
* <p>Validate that the argument condition is {@code true}; otherwise
* <p>Validate that the argument condition is {@code true}; otherwise
* throwing an exception with the specified message. This method is useful when
* validating according to an arbitrary boolean expression, such as validating a
* validating according to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>Validate.isTrue(d > 0.0, "The value must be greater than zero: %s", d);</pre>
*
* <p>For performance reasons, the double value is passed as a separate parameter and
* appended to the exception message only in the case of an error.</p>
*
* @param expression the boolean expression to check
*
* @param expression the boolean expression to check
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param value the value to append to the message when invalid
* @throws IllegalArgumentException if expression is {@code false}
@ -130,16 +139,16 @@ public static void isTrue(boolean expression, String message, double value) {
}
/**
* <p>Validate that the argument condition is {@code true}; otherwise
* <p>Validate that the argument condition is {@code true}; otherwise
* throwing an exception with the specified message. This method is useful when
* validating according to an arbitrary boolean expression, such as validating a
* validating according to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>
* Validate.isTrue(i >= min && i <= max, "The value must be between %d and %d", min, max);
* Validate.isTrue(myObject.isOk(), "The object is not okay");</pre>
*
* @param expression the boolean expression to check
* @param expression the boolean expression to check
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalArgumentException if expression is {@code false}
@ -154,19 +163,19 @@ public static void isTrue(boolean expression, String message, Object... values)
}
/**
* <p>Validate that the argument condition is {@code true}; otherwise
* throwing an exception. This method is useful when validating according
* to an arbitrary boolean expression, such as validating a
* <p>Validate that the argument condition is {@code true}; otherwise
* throwing an exception. This method is useful when validating according
* to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>
* Validate.isTrue(i > 0);
* Validate.isTrue(myObject.isOk());</pre>
*
* <p>The message of the exception is &quot;The validated expression is
* <p>The message of the exception is &quot;The validated expression is
* false&quot;.</p>
*
* @param expression the boolean expression to check
*
* @param expression the boolean expression to check
* @throws IllegalArgumentException if expression is {@code false}
* @see #isTrue(boolean, String, long)
* @see #isTrue(boolean, String, double)
@ -182,14 +191,14 @@ public static void isTrue(boolean expression) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument is not {@code null};
* <p>Validate that the specified argument is not {@code null};
* otherwise throwing an exception.
*
* <pre>Validate.notNull(myObject, "The object must not be null");</pre>
*
* <p>The message of the exception is &quot;The validated object is
* <p>The message of the exception is &quot;The validated object is
* null&quot;.</p>
*
*
* @param <T> the object type
* @param object the object to check
* @return the validated object (never {@code null} for method chaining)
@ -201,11 +210,11 @@ public static <T> T notNull(T object) {
}
/**
* <p>Validate that the specified argument is not {@code null};
* <p>Validate that the specified argument is not {@code null};
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.notNull(myObject, "The object must not be null");</pre>
*
*
* @param <T> the object type
* @param object the object to check
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -225,12 +234,12 @@ public static <T> T notNull(T object, String message, Object... values) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument array is neither {@code null}
* nor a length of zero (no elements); otherwise throwing an exception
* <p>Validate that the specified argument array is neither {@code null}
* nor a length of zero (no elements); otherwise throwing an exception
* with the specified message.
*
* <pre>Validate.notEmpty(myArray, "The array must not be empty");</pre>
*
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -251,14 +260,14 @@ public static <T> T[] notEmpty(T[] array, String message, Object... values) {
}
/**
* <p>Validate that the specified argument array is neither {@code null}
* nor a length of zero (no elements); otherwise throwing an exception.
* <p>Validate that the specified argument array is neither {@code null}
* nor a length of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myArray);</pre>
*
* <p>The message in the exception is &quot;The validated array is
*
* <p>The message in the exception is &quot;The validated array is
* empty&quot;.
*
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @return the validated array (never {@code null} method for chaining)
@ -274,12 +283,12 @@ public static <T> T[] notEmpty(T[] array) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument collection is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception
* <p>Validate that the specified argument collection is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception
* with the specified message.
*
* <pre>Validate.notEmpty(myCollection, "The collection must not be empty");</pre>
*
*
* @param <T> the collection type
* @param collection the collection to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -300,14 +309,14 @@ public static <T extends Collection<?>> T notEmpty(T collection, String message,
}
/**
* <p>Validate that the specified argument collection is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
* <p>Validate that the specified argument collection is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myCollection);</pre>
*
* <p>The message in the exception is &quot;The validated collection is
*
* <p>The message in the exception is &quot;The validated collection is
* empty&quot;.</p>
*
*
* @param <T> the collection type
* @param collection the collection to check, validated not null by this method
* @return the validated collection (never {@code null} method for chaining)
@ -323,12 +332,12 @@ public static <T extends Collection<?>> T notEmpty(T collection) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument map is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception
* <p>Validate that the specified argument map is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception
* with the specified message.
*
* <pre>Validate.notEmpty(myMap, "The map must not be empty");</pre>
*
*
* @param <T> the map type
* @param map the map to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -349,14 +358,14 @@ public static <T extends Collection<?>> T notEmpty(T collection) {
}
/**
* <p>Validate that the specified argument map is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
* <p>Validate that the specified argument map is neither {@code null}
* nor a size of zero (no elements); otherwise throwing an exception.
*
* <pre>Validate.notEmpty(myMap);</pre>
*
* <p>The message in the exception is &quot;The validated map is
*
* <p>The message in the exception is &quot;The validated map is
* empty&quot;.</p>
*
*
* @param <T> the map type
* @param map the map to check, validated not null by this method
* @return the validated map (never {@code null} method for chaining)
@ -372,12 +381,12 @@ public static <T extends Collection<?>> T notEmpty(T collection) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.notEmpty(myString, "The string must not be empty");</pre>
*
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -398,15 +407,15 @@ public static <T extends CharSequence> T notEmpty(T chars, String message, Objec
}
/**
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);
* <p>Validate that the specified argument character sequence is
* neither {@code null} nor a length of zero (no characters);
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.notEmpty(myString);</pre>
*
* <p>The message in the exception is &quot;The validated
*
* <p>The message in the exception is &quot;The validated
* character sequence is empty&quot;.</p>
*
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @return the validated character sequence (never {@code null} method for chaining)
@ -422,13 +431,13 @@ public static <T extends CharSequence> T notEmpty(T chars) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument character sequence is
* <p>Validate that the specified argument character sequence is
* neither {@code null}, a length of zero (no characters), empty
* nor whitespace; otherwise throwing an exception with the specified
* nor whitespace; otherwise throwing an exception with the specified
* message.
*
* <pre>Validate.notBlank(myString, "The string must not be blank");</pre>
*
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -437,7 +446,7 @@ public static <T extends CharSequence> T notEmpty(T chars) {
* @throws NullPointerException if the character sequence is {@code null}
* @throws IllegalArgumentException if the character sequence is blank
* @see #notBlank(CharSequence)
*
*
* @since 3.0
*/
public static <T extends CharSequence> T notBlank(T chars, String message, Object... values) {
@ -451,22 +460,22 @@ public static <T extends CharSequence> T notBlank(T chars, String message, Objec
}
/**
* <p>Validate that the specified argument character sequence is
* <p>Validate that the specified argument character sequence is
* neither {@code null}, a length of zero (no characters), empty
* nor whitespace; otherwise throwing an exception.
*
* <pre>Validate.notBlank(myString);</pre>
*
* <p>The message in the exception is &quot;The validated character
*
* <p>The message in the exception is &quot;The validated character
* sequence is blank&quot;.</p>
*
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @return the validated character sequence (never {@code null} method for chaining)
* @throws NullPointerException if the character sequence is {@code null}
* @throws IllegalArgumentException if the character sequence is blank
* @see #notBlank(CharSequence, String, Object...)
*
*
* @since 3.0
*/
public static <T extends CharSequence> T notBlank(T chars) {
@ -477,19 +486,19 @@ public static <T extends CharSequence> T notBlank(T chars) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument array is neither
* <p>Validate that the specified argument array is neither
* {@code null} nor contains any elements that are {@code null};
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.noNullElements(myArray, "The array contain null at position %d");</pre>
*
* <p>If the array is {@code null}, then the message in the exception
*
* <p>If the array is {@code null}, then the message in the exception
* is &quot;The validated object is null&quot;.</p>
*
* <p>If the array has a {@code null} element, then the iteration
* index of the invalid element is appended to the {@code values}
*
* <p>If the array has a {@code null} element, then the iteration
* index of the invalid element is appended to the {@code values}
* argument.</p>
*
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
@ -511,17 +520,17 @@ public static <T> T[] noNullElements(T[] array, String message, Object... values
}
/**
* <p>Validate that the specified argument array is neither
* <p>Validate that the specified argument array is neither
* {@code null} nor contains any elements that are {@code null};
* otherwise throwing an exception.
*
* <pre>Validate.noNullElements(myArray);</pre>
*
* <p>If the array is {@code null}, then the message in the exception
*
* <p>If the array is {@code null}, then the message in the exception
* is &quot;The validated object is null&quot;.</p>
*
*
* <p>If the array has a {@code null} element, then the message in the
* exception is &quot;The validated array contains null element at index:
* exception is &quot;The validated array contains null element at index:
* &quot followed by the index.</p>
*
* @param <T> the array type
@ -539,17 +548,17 @@ public static <T> T[] noNullElements(T[] array) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the specified argument iterable is neither
* <p>Validate that the specified argument iterable is neither
* {@code null} nor contains any elements that are {@code null};
* otherwise throwing an exception with the specified message.
*
* <pre>Validate.noNullElements(myCollection, "The collection contains null at position %d");</pre>
*
* <p>If the iterable is {@code null}, then the message in the exception
*
* <p>If the iterable is {@code null}, then the message in the exception
* is &quot;The validated object is null&quot;.</p>
*
* <p>If the iterable has a {@code null} element, then the iteration
* index of the invalid element is appended to the {@code values}
*
* <p>If the iterable has a {@code null} element, then the iteration
* index of the invalid element is appended to the {@code values}
* argument.</p>
*
* @param <T> the iterable type
@ -574,17 +583,17 @@ public static <T extends Iterable<?>> T noNullElements(T iterable, String messag
}
/**
* <p>Validate that the specified argument iterable is neither
* <p>Validate that the specified argument iterable is neither
* {@code null} nor contains any elements that are {@code null};
* otherwise throwing an exception.
*
* <pre>Validate.noNullElements(myCollection);</pre>
*
* <p>If the iterable is {@code null}, then the message in the exception
*
* <p>If the iterable is {@code null}, then the message in the exception
* is &quot;The validated object is null&quot;.</p>
*
*
* <p>If the array has a {@code null} element, then the message in the
* exception is &quot;The validated iterable contains null element at index:
* exception is &quot;The validated iterable contains null element at index:
* &quot followed by the index.</p>
*
* @param <T> the iterable type
@ -602,14 +611,14 @@ public static <T extends Iterable<?>> T noNullElements(T iterable) {
//---------------------------------------------------------------------------------
/**
* <p>Validates that the index is within the bounds of the argument
* <p>Validates that the index is within the bounds of the argument
* array; otherwise throwing an exception with the specified message.</p>
*
* <pre>Validate.validIndex(myArray, 2, "The array index is invalid: ");</pre>
*
* <p>If the array is {@code null}, then the message of the exception
*
* <p>If the array is {@code null}, then the message of the exception
* is &quot;The validated object is null&quot;.</p>
*
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @param index the index to check
@ -619,7 +628,7 @@ public static <T extends Iterable<?>> T noNullElements(T iterable) {
* @throws NullPointerException if the array is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(Object[], int)
*
*
* @since 3.0
*/
public static <T> T[] validIndex(T[] array, int index, String message, Object... values) {
@ -631,18 +640,18 @@ public static <T> T[] validIndex(T[] array, int index, String message, Object...
}
/**
* <p>Validates that the index is within the bounds of the argument
* <p>Validates that the index is within the bounds of the argument
* array; otherwise throwing an exception.</p>
*
* <pre>Validate.validIndex(myArray, 2);</pre>
*
* <p>If the array is {@code null}, then the message of the exception
* is &quot;The validated object is null&quot;.</p>
*
* <p>If the index is invalid, then the message of the exception is
* &quot;The validated array index is invalid: &quot; followed by the
*
* <p>If the index is invalid, then the message of the exception is
* &quot;The validated array index is invalid: &quot; followed by the
* index.</p>
*
*
* @param <T> the array type
* @param array the array to check, validated not null by this method
* @param index the index to check
@ -650,7 +659,7 @@ public static <T> T[] validIndex(T[] array, int index, String message, Object...
* @throws NullPointerException if the array is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(Object[], int, String, Object...)
*
*
* @since 3.0
*/
public static <T> T[] validIndex(T[] array, int index) {
@ -661,12 +670,12 @@ public static <T> T[] validIndex(T[] array, int index) {
//---------------------------------------------------------------------------------
/**
* <p>Validates that the index is within the bounds of the argument
* <p>Validates that the index is within the bounds of the argument
* collection; otherwise throwing an exception with the specified message.</p>
*
* <pre>Validate.validIndex(myCollection, 2, "The collection index is invalid: ");</pre>
*
* <p>If the collection is {@code null}, then the message of the
*
* <p>If the collection is {@code null}, then the message of the
* exception is &quot;The validated object is null&quot;.</p>
*
* @param <T> the collection type
@ -678,7 +687,7 @@ public static <T> T[] validIndex(T[] array, int index) {
* @throws NullPointerException if the collection is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(Collection, int)
*
*
* @since 3.0
*/
public static <T extends Collection<?>> T validIndex(T collection, int index, String message, Object... values) {
@ -690,15 +699,15 @@ public static <T extends Collection<?>> T validIndex(T collection, int index, St
}
/**
* <p>Validates that the index is within the bounds of the argument
* <p>Validates that the index is within the bounds of the argument
* collection; otherwise throwing an exception.</p>
*
* <pre>Validate.validIndex(myCollection, 2);</pre>
*
* <p>If the index is invalid, then the message of the exception
* is &quot;The validated collection index is invalid: &quot;
* <p>If the index is invalid, then the message of the exception
* is &quot;The validated collection index is invalid: &quot;
* followed by the index.</p>
*
*
* @param <T> the collection type
* @param collection the collection to check, validated not null by this method
* @param index the index to check
@ -706,7 +715,7 @@ public static <T extends Collection<?>> T validIndex(T collection, int index, St
* @throws NullPointerException if the collection is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(Collection, int, String, Object...)
*
*
* @since 3.0
*/
public static <T extends Collection<?>> T validIndex(T collection, int index) {
@ -717,13 +726,13 @@ public static <T extends Collection<?>> T validIndex(T collection, int index) {
//---------------------------------------------------------------------------------
/**
* <p>Validates that the index is within the bounds of the argument
* character sequence; otherwise throwing an exception with the
* <p>Validates that the index is within the bounds of the argument
* character sequence; otherwise throwing an exception with the
* specified message.</p>
*
* <pre>Validate.validIndex(myStr, 2, "The string index is invalid: ");</pre>
*
* <p>If the character sequence is {@code null}, then the message
*
* <p>If the character sequence is {@code null}, then the message
* of the exception is &quot;The validated object is null&quot;.</p>
*
* @param <T> the character sequence type
@ -735,7 +744,7 @@ public static <T extends Collection<?>> T validIndex(T collection, int index) {
* @throws NullPointerException if the character sequence is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(CharSequence, int)
*
*
* @since 3.0
*/
public static <T extends CharSequence> T validIndex(T chars, int index, String message, Object... values) {
@ -747,19 +756,19 @@ public static <T extends CharSequence> T validIndex(T chars, int index, String m
}
/**
* <p>Validates that the index is within the bounds of the argument
* <p>Validates that the index is within the bounds of the argument
* character sequence; otherwise throwing an exception.</p>
*
*
* <pre>Validate.validIndex(myStr, 2);</pre>
*
* <p>If the character sequence is {@code null}, then the message
* of the exception is &quot;The validated object is
* <p>If the character sequence is {@code null}, then the message
* of the exception is &quot;The validated object is
* null&quot;.</p>
*
* <p>If the index is invalid, then the message of the exception
* is &quot;The validated character sequence index is invalid: &quot;
*
* <p>If the index is invalid, then the message of the exception
* is &quot;The validated character sequence index is invalid: &quot;
* followed by the index.</p>
*
*
* @param <T> the character sequence type
* @param chars the character sequence to check, validated not null by this method
* @param index the index to check
@ -767,7 +776,7 @@ public static <T extends CharSequence> T validIndex(T chars, int index, String m
* @throws NullPointerException if the character sequence is {@code null}
* @throws IndexOutOfBoundsException if the index is invalid
* @see #validIndex(CharSequence, int, String, Object...)
*
*
* @since 3.0
*/
public static <T extends CharSequence> T validIndex(T chars, int index) {
@ -778,22 +787,22 @@ public static <T extends CharSequence> T validIndex(T chars, int index) {
//---------------------------------------------------------------------------------
/**
* <p>Validate that the stateful condition is {@code true}; otherwise
* throwing an exception. This method is useful when validating according
* to an arbitrary boolean expression, such as validating a
* <p>Validate that the stateful condition is {@code true}; otherwise
* throwing an exception. This method is useful when validating according
* to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>
* Validate.validState(field > 0);
* Validate.validState(this.isOk());</pre>
*
* <p>The message of the exception is &quot;The validated state is
* <p>The message of the exception is &quot;The validated state is
* false&quot;.</p>
*
* @param expression the boolean expression to check
*
* @param expression the boolean expression to check
* @throws IllegalStateException if expression is {@code false}
* @see #validState(boolean, String, Object...)
*
*
* @since 3.0
*/
public static void validState(boolean expression) {
@ -803,19 +812,19 @@ public static void validState(boolean expression) {
}
/**
* <p>Validate that the stateful condition is {@code true}; otherwise
* <p>Validate that the stateful condition is {@code true}; otherwise
* throwing an exception with the specified message. This method is useful when
* validating according to an arbitrary boolean expression, such as validating a
* validating according to an arbitrary boolean expression, such as validating a
* primitive number or using your own custom validation expression.</p>
*
* <pre>Validate.validState(this.isOk(), "The state is not OK: %s", myObject);</pre>
*
* @param expression the boolean expression to check
* @param expression the boolean expression to check
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalStateException if expression is {@code false}
* @see #validState(boolean)
*
*
* @since 3.0
*/
public static void validState(boolean expression, String message, Object... values) {
@ -832,14 +841,14 @@ public static void validState(boolean expression, String message, Object... valu
* expression pattern; otherwise throwing an exception.</p>
*
* <pre>Validate.matchesPattern("hi", "[a-z]*");</pre>
*
*
* <p>The syntax of the pattern is the one used in the {@link Pattern} class.</p>
*
*
* @param input the character sequence to validate, not null
* @param pattern the regular expression pattern, not null
* @throws IllegalArgumentException if the character sequence does not match the pattern
* @see #matchesPattern(CharSequence, String, String, Object...)
*
*
* @since 3.0
*/
public static void matchesPattern(CharSequence input, String pattern) {
@ -853,16 +862,16 @@ public static void matchesPattern(CharSequence input, String pattern) {
* expression pattern; otherwise throwing an exception with the specified message.</p>
*
* <pre>Validate.matchesPattern("hi", "[a-z]*", "%s does not match %s", "hi" "[a-z]*");</pre>
*
*
* <p>The syntax of the pattern is the one used in the {@link Pattern} class.</p>
*
*
* @param input the character sequence to validate, not null
* @param pattern the regular expression pattern, not null
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalArgumentException if the character sequence does not match the pattern
* @see #matchesPattern(CharSequence, String)
*
*
* @since 3.0
*/
public static void matchesPattern(CharSequence input, String pattern, String message, Object... values) {
@ -879,13 +888,14 @@ public static void matchesPattern(CharSequence input, String pattern, String mes
* inclusive values specified; otherwise, throws an exception.</p>
*
* <pre>Validate.inclusiveBetween(0, 2, 1);</pre>
*
*
* @param <T> the type of the argument object
* @param start the inclusive start value, not null
* @param end the inclusive end value, not null
* @param value the object to validate, not null
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #inclusiveBetween(Object, Object, Comparable, String, Object...)
*
*
* @since 3.0
*/
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value) {
@ -900,7 +910,8 @@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value) {
* specified message.</p>
*
* <pre>Validate.inclusiveBetween(0, 2, 1, "Not in boundaries");</pre>
*
*
* @param <T> the type of the argument object
* @param start the inclusive start value, not null
* @param end the inclusive end value, not null
* @param value the object to validate, not null
@ -908,7 +919,7 @@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value) {
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #inclusiveBetween(Object, Object, Comparable)
*
*
* @since 3.0
*/
public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values) {
@ -925,13 +936,14 @@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, Str
* exclusive values specified; otherwise, throws an exception.</p>
*
* <pre>Validate.inclusiveBetween(0, 2, 1);</pre>
*
*
* @param <T> the type of the argument object
* @param start the exclusive start value, not null
* @param end the exclusive end value, not null
* @param value the object to validate, not null
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #exclusiveBetween(Object, Object, Comparable, String, Object...)
*
*
* @since 3.0
*/
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value) {
@ -946,7 +958,8 @@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value) {
* specified message.</p>
*
* <pre>Validate.inclusiveBetween(0, 2, 1, "Not in boundaries");</pre>
*
*
* @param <T> the type of the argument object
* @param start the exclusive start value, not null
* @param end the exclusive end value, not null
* @param value the object to validate, not null
@ -954,7 +967,7 @@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value) {
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalArgumentException if the value falls out of the boundaries
* @see #exclusiveBetween(Object, Object, Comparable)
*
*
* @since 3.0
*/
public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, String message, Object... values) {
@ -970,17 +983,17 @@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, Str
* <p>Validate that the argument is an instance of the specified class; otherwise
* throwing an exception. This method is useful when validating according to an arbitrary
* class</p>
*
*
* <pre>Validate.isInstanceOf(OkClass.class, object);</pre>
*
*
* <p>The message of the exception is &quot;The validated object is not an instance of&quot;
* followed by the name of the class</p>
*
*
* @param type the class the object must be validated against, not null
* @param obj the object to check, null throws an exception
* @throws IllegalArgumentException if argument is not of specified class
* @see #isInstanceOf(Class, Object, String, Object...)
*
*
* @since 3.0
*/
public static void isInstanceOf(Class<?> type, Object obj) {
@ -991,18 +1004,19 @@ public static void isInstanceOf(Class<?> type, Object obj) {
/**
* <p>Validate that the argument is an instance of the specified class; otherwise
* throwing an exception with the specified message. This method is useful when
* throwing an exception with the specified message. This method is useful when
* validating according to an arbitrary class</p>
*
* <pre>Validate.isInstanceOf(OkClass.classs, object, "Wrong class, object is of class %s", object.getClass().getName());</pre>
*
*
* <pre>Validate.isInstanceOf(OkClass.classs, object, "Wrong class, object is of class %s",
* object.getClass().getName());</pre>
*
* @param type the class the object must be validated against, not null
* @param obj the object to check, null throws an exception
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null
* @param values the optional values for the formatted exception message, null array not recommended
* @throws IllegalArgumentException if argument is not of specified class
* @see #isInstanceOf(Class, Object)
*
*
* @since 3.0
*/
public static void isInstanceOf(Class<?> type, Object obj, String message, Object... values) {
@ -1018,17 +1032,17 @@ public static void isInstanceOf(Class<?> type, Object obj, String message, Objec
* <p>Validate that the argument can be converted to the specified class; otherwise
* throwing an exception with the specified message. This method is useful when
* validating if there will be no casting errors.</p>
*
*
* <pre>Validate.isAssignableFrom(SuperClass.class, object.getClass());</pre>
*
*
* <p>The message of the exception is &quot;The validated object can not be converted to the&quot;
* followed by the name of the class and &quot;class&quot;</p>
*
*
* @param superType the class the class must be validated against, not null
* @param type the class to check, not null
* @throws IllegalArgumentException if argument can not be converted to the specified class
* @see #isAssignableFrom(Class, Class, String, Object...)
*
*
* @since 3.0
*/
public static void isAssignableFrom(Class<?> superType, Class<?> type) {
@ -1041,12 +1055,12 @@ public static void isAssignableFrom(Class<?> superType, Class<?> type) {
* <p>Validate that the argument can be converted to the specified class; otherwise
* throwing an exception. This method is useful when validating if there will be no
* casting errors.</p>
*
*
* <pre>Validate.isAssignableFrom(SuperClass.class, object.getClass());</pre>
*
*
* <p>The message of the exception is &quot;The validated object can not be converted to the&quot;
* followed by the name of the class and &quot;class&quot;</p>
*
*
* @param superType the class the class must be validated against, not null
* @param type the class to check, not null
* @param message the {@link String#format(String, Object...)} exception message if invalid, not null