| Total Complexity | 6 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package com.hltech.vaunt.validator; |
||
| 10 | public class StringSchemaValidator { |
||
| 11 | |||
| 12 | public static List<String> validate(StringSchema consumerSchema, StringSchema providerSchema) { |
||
| 13 | List<String> errors = new ArrayList<>(ValueTypeSchemaValidator.validate(consumerSchema, providerSchema)); |
||
| 14 | |||
| 15 | if (!equals(consumerSchema.getMinLength(), providerSchema.getMinLength())) { |
||
| 16 | errors.add(String.format(ERROR_FORMAT, |
||
| 17 | consumerSchema.getId(), |
||
| 18 | "minLength", |
||
| 19 | consumerSchema.getMinLength(), |
||
| 20 | providerSchema.getMinLength())); |
||
| 21 | } |
||
| 22 | |||
| 23 | if (!equals(consumerSchema.getMaxLength(), providerSchema.getMaxLength())) { |
||
| 24 | errors.add(String.format(ERROR_FORMAT, |
||
| 25 | consumerSchema.getId(), |
||
| 26 | "maxLength", |
||
| 27 | consumerSchema.getMaxLength(), |
||
| 28 | providerSchema.getMaxLength())); |
||
| 29 | } |
||
| 30 | |||
| 31 | if (!equals(consumerSchema.getPattern(), providerSchema.getPattern())) { |
||
| 32 | errors.add(String.format(ERROR_FORMAT, |
||
| 33 | consumerSchema.getId(), |
||
| 34 | "pattern", |
||
| 35 | consumerSchema.getPattern(), |
||
| 36 | providerSchema.getPattern())); |
||
| 37 | } |
||
| 38 | |||
| 39 | return errors; |
||
| 40 | } |
||
| 41 | |||
| 42 | private static boolean equals(Object object1, Object object2) { |
||
| 43 | if (object1 == null) { |
||
| 44 | return object2 == null; |
||
| 45 | } else { |
||
| 46 | return object1.equals(object2); |
||
| 47 | } |
||
| 50 |