This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-validator.git
commit 787ecc577b408e6150e096d3708a75f62c3acdbc Author: Gary Gregory <[email protected]> AuthorDate: Fri Jun 19 21:23:16 2026 +0000 Javadoc --- .../validator/routines/BigDecimalValidator.java | 174 +++++++++------------ 1 file changed, 74 insertions(+), 100 deletions(-) diff --git a/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java b/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java index 377144bd..c339e6f5 100644 --- a/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java +++ b/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.validator.routines; import java.math.BigDecimal; @@ -23,45 +24,41 @@ import java.util.Locale; /** * <strong>BigDecimal Validation</strong> and Conversion routines ({@code java.math.BigDecimal}). - * - * <p>This validator provides a number of methods for - * validating/converting a {@link String} value to - * a {@code BigDecimal} using {@link NumberFormat} - * to parse either:</p> - * <ul> - * <li>using the default format for the default {@link Locale}</li> - * <li>using a specified pattern with the default {@link Locale}</li> - * <li>using the default format for a specified {@link Locale}</li> - * <li>using a specified pattern with a specified {@link Locale}</li> - * </ul> - * - * <p>Use one of the {@code isValid()} methods to just validate or - * one of the {@code validate()} methods to validate and receive a - * <em>converted</em> {@code BigDecimal} value.</p> - * - * <p>Fraction/decimal values are automatically trimmed to the appropriate length.</p> - * - * <p>Once a value has been successfully converted the following - * methods can be used to perform minimum, maximum and range checks:</p> - * <ul> - * <li>{@code minValue()} checks whether the value is greater - * than or equal to a specified minimum.</li> - * <li>{@code maxValue()} checks whether the value is less - * than or equal to a specified maximum.</li> - * <li>{@code isInRange()} checks whether the value is within - * a specified range of values.</li> - * </ul> - * - * <p>So that the same mechanism used for parsing an <em>input</em> value - * for validation can be used to format <em>output</em>, corresponding - * {@code format()} methods are also provided. That is you can - * format either:</p> - * <ul> - * <li>using the default format for the default {@link Locale}</li> - * <li>using a specified pattern with the default {@link Locale}</li> - * <li>using the default format for a specified {@link Locale}</li> - * <li>using a specified pattern with a specified {@link Locale}</li> - * </ul> + * <p> + * This validator provides a number of methods for validating/converting a {@link String} value to a {@code BigDecimal} using {@link NumberFormat} to parse + * either: + * </p> + * <ul> + * <li>using the default format for the default {@link Locale}</li> + * <li>using a specified pattern with the default {@link Locale}</li> + * <li>using the default format for a specified {@link Locale}</li> + * <li>using a specified pattern with a specified {@link Locale}</li> + * </ul> + * <p> + * Use one of the {@code isValid()} methods to just validate or one of the {@code validate()} methods to validate and receive a <em>converted</em> + * {@code BigDecimal} value. + * </p> + * <p> + * Fraction/decimal values are automatically trimmed to the appropriate length. + * </p> + * <p> + * Once a value has been successfully converted the following methods can be used to perform minimum, maximum and range checks: + * </p> + * <ul> + * <li>{@code minValue()} checks whether the value is greater than or equal to a specified minimum.</li> + * <li>{@code maxValue()} checks whether the value is less than or equal to a specified maximum.</li> + * <li>{@code isInRange()} checks whether the value is within a specified range of values.</li> + * </ul> + * <p> + * So that the same mechanism used for parsing an <em>input</em> value for validation can be used to format <em>output</em>, corresponding {@code format()} + * methods are also provided. That is you can format either: + * </p> + * <ul> + * <li>using the default format for the default {@link Locale}</li> + * <li>using a specified pattern with the default {@link Locale}</li> + * <li>using the default format for a specified {@link Locale}</li> + * <li>using a specified pattern with a specified {@link Locale}</li> + * </ul> * * @since 1.3.0 */ @@ -101,85 +98,71 @@ public class BigDecimalValidator extends AbstractNumberValidator { /** * Construct an instance with the specified strict setting. * - * @param strict {@code true} if strict - * {@code Format} parsing should be used. + * @param strict {@code true} if strict {@code Format} parsing should be used. */ public BigDecimalValidator(final boolean strict) { this(strict, STANDARD_FORMAT, true); } /** - * Construct an instance with the specified strict setting - * and format type. - * - * <p>The {@code formatType} specified what type of - * {@code NumberFormat} is created - valid types - * are:</p> - * <ul> - * <li>AbstractNumberValidator.STANDARD_FORMAT -to create - * <em>standard</em> number formats (the default).</li> - * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create - * <em>currency</em> number formats.</li> - * <li>AbstractNumberValidator.PERCENT_FORMAT -to create - * <em>percent</em> number formats (the default).</li> - * </ul> + * Constructs an instance with the specified strict setting and format type. + * <p> + * The {@code formatType} specified what type of {@code NumberFormat} is created - valid types are: + * </p> + * <ul> + * <li>AbstractNumberValidator.STANDARD_FORMAT -to create <em>standard</em> number formats (the default).</li> + * <li>AbstractNumberValidator.CURRENCY_FORMAT -to create <em>currency</em> number formats.</li> + * <li>AbstractNumberValidator.PERCENT_FORMAT -to create <em>percent</em> number formats (the default).</li> + * </ul> * - * @param strict {@code true} if strict - * {@code Format} parsing should be used. - * @param formatType The {@code NumberFormat} type to - * create for validation, default is STANDARD_FORMAT. - * @param allowFractions {@code true} if fractions are - * allowed or {@code false} if integers only. + * @param strict {@code true} if strict {@code Format} parsing should be used. + * @param formatType The {@code NumberFormat} type to create for validation, default is STANDARD_FORMAT. + * @param allowFractions {@code true} if fractions are allowed or {@code false} if integers only. */ - protected BigDecimalValidator(final boolean strict, final int formatType, - final boolean allowFractions) { + protected BigDecimalValidator(final boolean strict, final int formatType, final boolean allowFractions) { super(strict, formatType, allowFractions); } /** - * Check if the value is within a specified range. + * Tests if the value is within a specified range. * * @param value The {@code Number} value to check. - * @param min The minimum value of the range. - * @param max The maximum value of the range. - * @return {@code true} if the value is within the - * specified range. + * @param min The minimum value of the range. + * @param max The maximum value of the range. + * @return {@code true} if the value is within the specified range. */ public boolean isInRange(final BigDecimal value, final double min, final double max) { return minValue(value, min) && maxValue(value, max); } /** - * Check if the value is less than or equal to a maximum. + * Tests if the value is less than or equal to a maximum. * * @param value The value validation is being performed on. - * @param max The maximum value. - * @return {@code true} if the value is less than - * or equal to the maximum. + * @param max The maximum value. + * @return {@code true} if the value is less than or equal to the maximum. */ public boolean maxValue(final BigDecimal value, final double max) { return Double.isFinite(max) ? compareTo(value, max) <= 0 : value.doubleValue() <= max; } /** - * Check if the value is greater than or equal to a minimum. + * Tests if the value is greater than or equal to a minimum. * * @param value The value validation is being performed on. - * @param min The minimum value. - * @return {@code true} if the value is greater than - * or equal to the minimum. + * @param min The minimum value. + * @return {@code true} if the value is greater than or equal to the minimum. */ public boolean minValue(final BigDecimal value, final double min) { return Double.isFinite(min) ? compareTo(value, min) >= 0 : value.doubleValue() >= min; } /** - * Convert the parsed value to a {@code BigDecimal}. + * Converts the parsed value to a {@code BigDecimal}. * - * @param value The parsed {@code Number} object created. + * @param value The parsed {@code Number} object created. * @param formatter The Format used to parse the value with. - * @return The parsed {@code Number} converted to a - * {@code BigDecimal}. + * @return The parsed {@code Number} converted to a {@code BigDecimal}. */ @Override protected Object processParsedValue(final Object value, final Format formatter) { @@ -189,32 +172,27 @@ public class BigDecimalValidator extends AbstractNumberValidator { } else { decimal = new BigDecimal(value.toString()); } - final int scale = determineScale((NumberFormat) formatter); if (scale >= 0) { decimal = decimal.setScale(scale, BigDecimal.ROUND_DOWN); } - return decimal; } /** - * Validate/convert a {@code BigDecimal} using the default - * {@link Locale}. + * Validates and converts a {@code BigDecimal} using the default {@link Locale}. * * @param value The value validation is being performed on. - * @return The parsed {@code BigDecimal} if valid or {@code null} - * if invalid. + * @return The parsed {@code BigDecimal} if valid or {@code null} if invalid. */ public BigDecimal validate(final String value) { return (BigDecimal) parse(value, (String) null, (Locale) null); } /** - * Validate/convert a {@code BigDecimal} using the - * specified {@link Locale}. + * Validates and converts a {@code BigDecimal} using the specified {@link Locale}. * - * @param value The value validation is being performed on. + * @param value The value validation is being performed on. * @param locale The locale to use for the number format, system default if null. * @return The parsed {@code BigDecimal} if valid or {@code null} if invalid. */ @@ -223,12 +201,10 @@ public class BigDecimalValidator extends AbstractNumberValidator { } /** - * Validate/convert a {@code BigDecimal} using the - * specified <em>pattern</em>. + * Validates and converts a {@code BigDecimal} using the specified <em>pattern</em>. * - * @param value The value validation is being performed on. - * @param pattern The pattern used to validate the value against, or the - * default for the {@link Locale} if {@code null}. + * @param value The value validation is being performed on. + * @param pattern The pattern used to validate the value against, or the default for the {@link Locale} if {@code null}. * @return The parsed {@code BigDecimal} if valid or {@code null} if invalid. */ public BigDecimal validate(final String value, final String pattern) { @@ -236,13 +212,11 @@ public class BigDecimalValidator extends AbstractNumberValidator { } /** - * Validate/convert a {@code BigDecimal} using the - * specified pattern and/ or {@link Locale}. + * Validates and converts a {@code BigDecimal} using the specified pattern and/ or {@link Locale}. * - * @param value The value validation is being performed on. - * @param pattern The pattern used to validate the value against, or the - * default for the {@link Locale} if {@code null}. - * @param locale The locale to use for the date format, system default if null. + * @param value The value validation is being performed on. + * @param pattern The pattern used to validate the value against, or the default for the {@link Locale} if {@code null}. + * @param locale The locale to use for the date format, system default if null. * @return The parsed {@code BigDecimal} if valid or {@code null} if invalid. */ public BigDecimal validate(final String value, final String pattern, final Locale locale) {
