| Total Complexity | 5 |
| Total Lines | 19 |
| Duplicated Lines | 94.74 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | package com.osomapps.pt.admin.certificate; |
||
| 9 | View Code Duplication | @Component |
|
|
|
|||
| 10 | class CertificateValidator implements Validator { |
||
| 11 | private static final Pattern CERTIFICATE_PATTERN = Pattern.compile("^[A-Z]{4}[0-9]{4}$"); |
||
| 12 | |||
| 13 | @Override |
||
| 14 | public boolean supports(final Class<?> aClass) { |
||
| 15 | return String.class.equals(aClass); |
||
| 16 | } |
||
| 17 | |||
| 18 | @Override |
||
| 19 | public void validate(final Object obj, final Errors errors) { |
||
| 20 | final String certificate = (String) obj; |
||
| 21 | if (certificate == null || certificate.trim().isEmpty()) { |
||
| 22 | errors.reject("certificate", "Invalid empty certificate"); |
||
| 23 | return; |
||
| 24 | } |
||
| 25 | final Matcher matcher = CERTIFICATE_PATTERN.matcher(certificate); |
||
| 26 | if (!matcher.matches()) { |
||
| 27 | errors.reject("certificate", "Invalid certificate code (" + certificate + ")"); |
||
| 28 | } |
||
| 31 |