We're updating the issue view to help you get more done. 

Performance improvement for MinValidatorForString

Description

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).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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; } } }

The same things applies to MaxValidatorForString.

Environment

None

Status

Assignee

Kevin Pollet

Reporter

Henri Tremblay

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

4.2.0.Final

Priority

Minor