package com.bonus.canteen.core.drp.utils;


import com.bonus.canteen.core.drp.anno.NotLessThanZero;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;

public class NotLessThanZeroValidator implements ConstraintValidator<NotLessThanZero, Object> {
   public boolean isValid(Object value, ConstraintValidatorContext context) {
      if (null == value) {
         return false;
      } else if (value instanceof Number) {
         BigDecimal target = new BigDecimal(value.toString());
         return target.compareTo(BigDecimal.ZERO) > 0;
      } else {
         return false;
      }
   }
}
