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; |
||
19 | public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
||
20 | List<String> errors = new ArrayList<>(); |
||
21 | |||
22 | if (!equals(consumerSchema.get$ref(), providerSchema.get$ref())) { |
||
23 | errors.add(String.format(ERROR_FORMAT, |
||
24 | consumerSchema.getId(), |
||
25 | "$ref", |
||
26 | consumerSchema.get$ref(), |
||
27 | providerSchema.get$ref())); |
||
28 | } |
||
29 | |||
30 | if (!equals(consumerSchema.get$schema(), providerSchema.get$schema())) { |
||
31 | errors.add(String.format(ERROR_FORMAT, |
||
32 | consumerSchema.getId(), |
||
33 | "$schema", |
||
34 | consumerSchema.get$schema(), |
||
35 | providerSchema.get$schema())); |
||
36 | } |
||
37 | |||
38 | if (!arraysEquals(consumerSchema.getDisallow(), providerSchema.getDisallow(), Object::equals)) { |
||
39 | errors.add(String.format(ERROR_FORMAT, |
||
40 | consumerSchema.getId(), |
||
41 | "disallow", |
||
42 | jsonArrayToString(consumerSchema.getDisallow()), |
||
43 | jsonArrayToString(providerSchema.getDisallow()))); |
||
44 | } |
||
45 | |||
46 | if (!arraysEquals(consumerSchema.getExtends(), providerSchema.getExtends(), Object::equals)) { |
||
47 | errors.add(String.format(ERROR_FORMAT, |
||
48 | consumerSchema.getId(), |
||
49 | "extends", |
||
50 | jsonArrayToString(consumerSchema.getExtends()), |
||
51 | jsonArrayToString(providerSchema.getExtends()))); |
||
52 | } |
||
53 | |||
54 | if (isRequired(consumerSchema) && !isRequired(providerSchema)) { |
||
55 | errors.add(String.format(ERROR_FORMAT, |
||
56 | consumerSchema.getId(), |
||
57 | "required", |
||
58 | consumerSchema.getRequired(), |
||
59 | providerSchema.getRequired())); |
||
60 | } |
||
61 | |||
62 | if (!equals(consumerSchema.getReadonly(), providerSchema.getReadonly())) { |
||
63 | errors.add(String.format(ERROR_FORMAT, |
||
64 | consumerSchema.getId(), |
||
65 | "readonly", |
||
66 | consumerSchema.getReadonly(), |
||
67 | providerSchema.getReadonly())); |
||
68 | } |
||
69 | |||
70 | if (!equals(consumerSchema.getDescription(), providerSchema.getDescription())) { |
||
71 | errors.add(String.format(ERROR_FORMAT, |
||
72 | consumerSchema.getId(), |
||
73 | "description", |
||
74 | consumerSchema.getDescription(), |
||
75 | providerSchema.getDescription())); |
||
76 | } |
||
77 | |||
78 | return errors; |
||
79 | } |
||
140 |