Conditions | 3 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 dev.hltech.dredd.interfaces.rest.validation; |
||
18 | public static List<ContractValidationReportDto> toDtos(List<EnvironmentValidatorResult> validationResults, String serviceName, String serviceVersion) { |
||
19 | Map<ConsumerAndProviderDto, ContractValidationReportDto> result = newHashMap(); |
||
20 | validationResults |
||
21 | .stream() |
||
22 | .forEach(environmentValidatorResult -> { |
||
23 | environmentValidatorResult.getCapabilitiesValidationResults() |
||
24 | .stream() |
||
25 | .forEach(cvr -> { |
||
26 | ConsumerAndProviderDto key = new ConsumerAndProviderDto(cvr.getConsumerName(), cvr.getConsumerVersion(), serviceName, serviceVersion); |
||
27 | if (!result.containsKey(key)) { |
||
28 | result.put( |
||
29 | key, |
||
30 | new ContractValidationReportDto(key) |
||
31 | ); |
||
32 | } |
||
33 | result.get(key).addInteractions( |
||
34 | cvr.getInteractionValidationResults() |
||
35 | .stream() |
||
36 | .map(ivr -> new InteractionValidationReportDto( |
||
37 | environmentValidatorResult.getCommunicationInterface(), |
||
38 | ivr.getName(), |
||
39 | ivr.getStatus(), |
||
40 | ivr.getErrors() |
||
41 | )) |
||
42 | .collect(Collectors.toList()) |
||
43 | ); |
||
44 | }); |
||
45 | environmentValidatorResult.getExpectationValidationResults() |
||
46 | .stream() |
||
47 | .forEach(evr -> { |
||
48 | ConsumerAndProviderDto key = new ConsumerAndProviderDto(serviceName, serviceVersion, evr.getProviderName(), evr.getProviderVersion()); |
||
49 | if (!result.containsKey(key)) { |
||
50 | result.put( |
||
51 | key, |
||
52 | new ContractValidationReportDto(key) |
||
53 | ); |
||
54 | } |
||
55 | result.get(key).addInteractions( |
||
56 | evr.getInteractionValidationResults() |
||
57 | .stream() |
||
58 | .map(ivr -> new InteractionValidationReportDto( |
||
59 | environmentValidatorResult.getCommunicationInterface(), |
||
60 | ivr.getName(), |
||
61 | ivr.getStatus(), |
||
62 | ivr.getErrors() |
||
63 | )) |
||
64 | .collect(Collectors.toList()) |
||
65 | ); |
||
66 | }); |
||
67 | }); |
||
68 | |||
69 | return Ordering |
||
70 | .from((Comparator<ContractValidationReportDto>) (o1, o2) -> o1.getConsumerAndProvider().toString().compareTo(o2.getConsumerAndProvider().toString())) |
||
71 | .sortedCopy(result.values()); |
||
72 | } |
||
74 |