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