All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForCharSequence Maven / Gradle / Ivy

There is a newer version: 8.0.1.Final
Show newest version
/*
 * Hibernate Validator, declare and validate application constraints
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package org.hibernate.validator.internal.constraintvalidators.bv.number.bound;

import java.math.BigDecimal;

/**
 * Check that the character sequence (e.g. string) validated represents a number, and has a value less than or equal to
 * the maximum value specified.
 *
 * @author Alaa Nassef
 * @author Kevin Pollet <[email protected]> (C) 2011 SERLI
 * @author Guillaume Smet
 */
public class MaxValidatorForCharSequence extends AbstractMaxValidator {

	@Override
	protected int compare(CharSequence number) {
		try {
			return NumberComparatorHelper.compare( new BigDecimal( number.toString() ), maxValue );
		}
		catch (NumberFormatException nfe) {
			return 1;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy