Conditions | 9 |
Total Lines | 60 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | package com.hltech.vaunt.validator.schema; |
||
20 | public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
||
21 | List<String> errors = new ArrayList<>(); |
||
22 | |||
23 | if (!equals(consumerSchema.get$ref(), providerSchema.get$ref())) { |
||
24 | errors.add(String.format(ERROR_FORMAT, |
||
25 | consumerSchema.getId(), |
||
26 | "$ref", |
||
27 | consumerSchema.get$ref(), |
||
28 | providerSchema.get$ref())); |
||
29 | } |
||
30 | |||
31 | if (!equals(consumerSchema.get$schema(), providerSchema.get$schema())) { |
||
32 | errors.add(String.format(ERROR_FORMAT, |
||
33 | consumerSchema.getId(), |
||
34 | "$schema", |
||
35 | consumerSchema.get$schema(), |
||
36 | providerSchema.get$schema())); |
||
37 | } |
||
38 | |||
39 | if (!arraysEquals(consumerSchema.getDisallow(), providerSchema.getDisallow(), Object::equals)) { |
||
40 | errors.add(String.format(ERROR_FORMAT, |
||
41 | consumerSchema.getId(), |
||
42 | "disallow", |
||
43 | jsonArrayToString(consumerSchema.getDisallow()), |
||
44 | jsonArrayToString(providerSchema.getDisallow()))); |
||
45 | } |
||
46 | |||
47 | if (!arraysEquals(consumerSchema.getExtends(), providerSchema.getExtends(), Object::equals)) { |
||
48 | errors.add(String.format(ERROR_FORMAT, |
||
49 | consumerSchema.getId(), |
||
50 | "extends", |
||
51 | jsonArrayToString(consumerSchema.getExtends()), |
||
52 | jsonArrayToString(providerSchema.getExtends()))); |
||
53 | } |
||
54 | |||
55 | if (isRequired(consumerSchema) && !isRequired(providerSchema)) { |
||
56 | errors.add(String.format(ERROR_FORMAT, |
||
57 | consumerSchema.getId(), |
||
58 | "required", |
||
59 | consumerSchema.getRequired(), |
||
60 | providerSchema.getRequired())); |
||
61 | } |
||
62 | |||
63 | if (!equals(consumerSchema.getReadonly(), providerSchema.getReadonly())) { |
||
64 | errors.add(String.format(ERROR_FORMAT, |
||
65 | consumerSchema.getId(), |
||
66 | "readonly", |
||
67 | consumerSchema.getReadonly(), |
||
68 | providerSchema.getReadonly())); |
||
69 | } |
||
70 | |||
71 | if (!equals(consumerSchema.getDescription(), providerSchema.getDescription())) { |
||
72 | errors.add(String.format(ERROR_FORMAT, |
||
73 | consumerSchema.getId(), |
||
74 | "description", |
||
75 | consumerSchema.getDescription(), |
||
76 | providerSchema.getDescription())); |
||
77 | } |
||
78 | |||
79 | return errors; |
||
80 | } |
||
134 |