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

com.github.ldeitos.validators.MinValidatorImpl Maven / Gradle / Ivy

package com.github.ldeitos.validators;

import java.math.BigDecimal;
import java.math.BigInteger;

import com.github.ldeitos.constraint.Min;

public class MinValidatorImpl extends  NumberComparativeValidator 
	implements MinValidator {
	
	private long min;
			
	public void initialize(Min constraintAnnotation) {
		this.min = constraintAnnotation.value();
	}


	@Override
	protected boolean compareValid(Number n) {
		boolean get = true;
		Class numberClass = n.getClass();

		if(BigDecimal.class.isAssignableFrom(numberClass)){
			BigDecimal value = BigDecimal.class.cast(n);
			get = value.compareTo(BigDecimal.valueOf(min)) >= 0;
		} else if(BigInteger.class.isAssignableFrom(numberClass)){
			BigInteger value = BigInteger.class.cast(n);
			get = value.compareTo(BigInteger.valueOf(min)) >= 0;
		} else {
			long value =  n.longValue();
			get = value >= min;
		}
		
		return get;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy