com.osomapps.pt.tokenemail.NameValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate(Object,Errors) 0 9 4
A supports(Class) 0 3 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