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