supports(Class)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
package com.osomapps.pt.tokenemail;
2
3
import org.springframework.stereotype.Component;
4
import org.springframework.validation.Errors;
5
import org.springframework.validation.Validator;
6
7
@Component
8
public class NameValidator implements Validator {
9
    @Override
10
    public boolean supports(final Class<?> aClass) {
11
        return String.class.equals(aClass);
12
    }
13
14
    @Override
15
    public void validate(final Object obj, final Errors errors) {
16
        final String name = (String) obj;
17
        if (name == null || name.trim().isEmpty()) {
18
            errors.reject("name", "Invalid empty name");
19
            return;
20
        }
21
        if (name.trim().length() < 2) {
22
            errors.reject("name", "Name should be at least 2 characters");
23
        }
24
    }
25
}
26