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