1 /*
2  * Hibernate Validator, declare and validate application constraints
3  *
4  * License: Apache License, Version 2.0
5  * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6  */

7 package org.hibernate.validator.internal.constraintvalidators.bv.notempty;
8
9 import javax.validation.ConstraintValidator;
10 import javax.validation.ConstraintValidatorContext;
11 import javax.validation.constraints.NotEmpty;
12
13 /**
14  * Check that the character sequence is not null and its length is strictly superior to 0.
15  *
16  * @author Guillaume Smet
17  */

18 public class NotEmptyValidatorForCharSequence implements ConstraintValidator<NotEmpty, CharSequence> {
19
20     /**
21      * Checks the character sequence is not {@code null} and not empty.
22      *
23      * @param charSequence the character sequence to validate
24      * @param constraintValidatorContext context in which the constraint is evaluated
25      * @return returns {@code trueif the character sequence is not {@code null} and not empty.
26      */

27     @Override
28     public boolean isValid(CharSequence charSequence, ConstraintValidatorContext constraintValidatorContext) {
29         if ( charSequence == null ) {
30             return false;
31         }
32         return charSequence.length() > 0;
33     }
34 }
35