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

io.mosip.kernel.masterdata.validator.StringTrimmer Maven / Gradle / Ivy

There is a newer version: 1.2.1.0
Show newest version
package io.mosip.kernel.masterdata.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import lombok.Data;

/**
 * The Class StringTrimmer.
 */

/**
 * Instantiates a new string trimmer.
 */
@Data
public class StringTrimmer implements ConstraintValidator {

	/** The min. */
	private int min = 0;

	/** The max. */
	private int max = Integer.MAX_VALUE;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.validation.ConstraintValidator#initialize(java.lang.annotation.
	 * Annotation)
	 */
	@Override
	public void initialize(StringFormatter constraintAnnotation) {
		max = constraintAnnotation.max();
		min = constraintAnnotation.min();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
	 * javax.validation.ConstraintValidatorContext)
	 */
	@Override
	public boolean isValid(String arg0, ConstraintValidatorContext arg1) {

		return !(arg0 != null && (arg0.trim().length() == 0 || arg0.trim().isEmpty() || arg0.trim().length() < min
				|| arg0.trim().length() > max));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy