]
Kevin Pollet reassigned HV-515:
-------------------------------
Assignee: Kevin Pollet
Performance improvement for MinValidatorForString
-------------------------------------------------
Key: HV-515
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-515
Project: Hibernate Validator
Issue Type: Improvement
Components: validators
Affects Versions: 4.2.0.Final
Reporter: Henri Tremblay
Assignee: Kevin Pollet
Priority: Minor
Labels: hibernate, validation
Fix For: 4.3.0.next
For a minor performance improvement, MinValidatorForString minValue can be precalculated
to prevent the valueOf like it's done in DecimalMinValidatorForString (even if the JVM
will probably eventually optimize it).
{code:java}
public class MinValidatorForString implements ConstraintValidator<Min, String> {
private BigDecimal{color} minValue; // Modified: type in BigDecimal
public void initialize(Min minValue) {
this.minValue = BigDecimal.valueOf(minValue.value(); // Modified: Convert to
BigDecimal
}
public boolean isValid(String value, ConstraintValidatorContext
constraintValidatorContext) {
//null values are valid
if ( value == null ) {
return true;
}
try {
return new BigDecimal( ( String ) value ).compareTo( {color:blue}minValue{color} ) !=
-1; // Modified: Compare the BigDecimal directly
}
catch ( NumberFormatException nfe ) {
return false;
}
}
}
{code}
The same things applies to MaxValidatorForString.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: