Conditions | 13 |
Total Lines | 27 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like com.hltech.vaunt.validator.VauntSchemaValidator.validate(JsonSchema,JsonSchema) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | package com.hltech.vaunt.validator; |
||
11 | public static List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
||
12 | |||
13 | if (consumerSchema.isBooleanSchema() && providerSchema.isBooleanSchema()) { |
||
14 | return new ArrayList<>(); |
||
15 | } |
||
16 | |||
17 | if (consumerSchema.isIntegerSchema() && providerSchema.isIntegerSchema()) { |
||
18 | return new ArrayList<>(); |
||
19 | } |
||
20 | |||
21 | if (consumerSchema.isNumberSchema() && providerSchema.isNumberSchema()) { |
||
22 | return new ArrayList<>(); |
||
23 | } |
||
24 | |||
25 | if (consumerSchema.isStringSchema() && providerSchema.isStringSchema()) { |
||
26 | return StringSchemaValidator.validate(consumerSchema.asStringSchema(), providerSchema.asStringSchema()); |
||
27 | } |
||
28 | |||
29 | if (consumerSchema.isArraySchema() && providerSchema.isArraySchema()) { |
||
30 | return new ArrayList<>(); |
||
31 | } |
||
32 | |||
33 | if (consumerSchema.isObjectSchema() && providerSchema.isObjectSchema()) { |
||
34 | return ObjectSchemaValidator.validate(consumerSchema.asObjectSchema(), providerSchema.asObjectSchema()); |
||
35 | } |
||
36 | |||
37 | return Lists.newArrayList("error"); |
||
38 | } |
||
40 |