[hibernate-issues] [Hibernate-JIRA] Updated: (HV-515) Performance improvement for MinValidatorForString
Kevin Pollet (JIRA)
noreply at atlassian.com
Tue Aug 30 04:55:04 EDT 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HV-515?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kevin Pollet updated HV-515:
----------------------------
Component/s: (was: annotation-processor)
validators
Fix Version/s: 4.3.0.next
> 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
> 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: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list