|
20 | 20 | import org.slf4j.Logger;
|
21 | 21 | import org.slf4j.LoggerFactory;
|
22 | 22 |
|
23 |
| -import java.util.ArrayList; |
24 | 23 | import java.util.Collections;
|
25 | 24 | import java.util.LinkedHashSet;
|
26 |
| -import java.util.List; |
| 25 | +import java.util.HashSet; |
27 | 26 | import java.util.Set;
|
28 | 27 |
|
29 | 28 | public class EnumValidator extends BaseJsonValidator implements JsonValidator {
|
30 | 29 | private static final Logger logger = LoggerFactory.getLogger(EnumValidator.class);
|
31 | 30 |
|
32 |
| - private List<JsonNode> nodes; |
33 |
| - private String error; |
| 31 | + private final Set<JsonNode> nodes; |
| 32 | + private final String error; |
34 | 33 |
|
35 | 34 | public EnumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
|
36 |
| - super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.ENUM, validationContext); |
37 |
| - nodes = new ArrayList<JsonNode>(); |
38 |
| - error = "[none]"; |
| 35 | + super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.ENUM, validationContext); |
39 | 36 |
|
40 | 37 | if (schemaNode != null && schemaNode.isArray()) {
|
41 |
| - error = "["; |
42 |
| - int i = 0; |
| 38 | + nodes = new HashSet<JsonNode>(); |
| 39 | + StringBuilder sb = new StringBuilder(); |
| 40 | + |
| 41 | + sb.append('['); |
| 42 | + String separator = ""; |
| 43 | + |
43 | 44 | for (JsonNode n : schemaNode) {
|
44 | 45 | nodes.add(n);
|
45 | 46 |
|
46 |
| - String v = n.asText(); |
47 |
| - error = error + (i == 0 ? "" : ", ") + v; |
48 |
| - i++; |
49 |
| - |
| 47 | + sb.append(separator); |
| 48 | + sb.append(n.asText()); |
| 49 | + separator = ", "; |
50 | 50 | }
|
51 |
| - error = error + "]"; |
| 51 | + |
| 52 | + sb.append(']'); |
| 53 | + |
| 54 | + error = sb.toString(); |
| 55 | + } else { |
| 56 | + nodes = Collections.emptySet(); |
| 57 | + error = "[none]"; |
52 | 58 | }
|
53 | 59 |
|
54 | 60 | parseErrorCode(getValidatorType().getErrorCodeKey());
|
|
0 commit comments