Source:
<code>public MbusChannelElementsResponseDto execute(final DlmsConnectionHolder conn, final DlmsDevice device, final MbusChannelElementsDto requestDto) throws ProtocolAdapterException { LOGGER.debug("retrieving mbus info on e-meter"); ChannelElementValuesDto bestMatch = null; final List<ChannelElementValuesDto> channelElements = new ArrayList<>(); for (short channel = FIRST_CHANNEL; channel < FIRST_CHANNEL + NR_OF_CHANNELS; channel++) { final List<GetResult> resultList = this.getMBusClientAttributeValues(conn, device, channel); final ChannelElementValuesDto channelValues = this.makeChannelElementValues(channel, resultList); channelElements.add(channelValues); if (FindMatchingChannelHelper.matches(requestDto, channelValues)) { bestMatch = channelValues; break; } } if (bestMatch == null) { bestMatch = FindMatchingChannelHelper.bestMatch(requestDto, channelElements); } if (bestMatch == null && requestDto.getPrimaryAddress() != null) { <START> for (short channel = FIRST_CHANNEL; channel < FIRST_CHANNEL + NR_OF_CHANNELS; channel++) { <END> final List<GetResult> resultList = this.getMBusClientAttributeValues(conn, device, channel); if ((long) resultList.get(INDEX_IDENTIFICATION_NUMBER).getResultData().getValue() == 0L) { bestMatch = new ChannelElementValuesDto(channel, requestDto.getPrimaryAddress(), requestDto.getMbusIdentificationNumber(), requestDto.getMbusManufacturerIdentification(), requestDto.getMbusVersion(), requestDto.getMbusDeviceTypeIdentification()); break; } } channelElements.set(bestMatch.getChannel() - 1, this.writeUpdatedMbus(conn, bestMatch, requestDto)); } return new MbusChannelElementsResponseDto(requestDto, bestMatch == null ? null : bestMatch.getChannel(), channelElements); }</code><technical_language>put this for loop in a method ( e.g. findEmptyChannel() ). code easier read, understand</technical_language>

Target:
public MbusChannelElementsResponseDto execute(final DlmsConnectionHolder conn, final DlmsDevice device, final MbusChannelElementsDto requestDto) throws ProtocolAdapterException { LOGGER.debug("retrieving mbus info on e-meter"); ChannelElementValuesDto bestMatch = null; final List<ChannelElementValuesDto> channelElements = new ArrayList<>(); for (short channel = FIRST_CHANNEL; channel < FIRST_CHANNEL + NR_OF_CHANNELS; channel++) { final List<GetResult> resultList = this.getMBusClientAttributeValues(conn, device, channel); final ChannelElementValuesDto channelValues = this.makeChannelElementValues(channel, resultList); channelElements.add(channelValues); if (FindMatchingChannelHelper.matches(requestDto, channelValues)) { bestMatch = channelValues; break; } } if (bestMatch == null) { bestMatch = FindMatchingChannelHelper.bestMatch(requestDto, channelElements); } if (bestMatch == null && requestDto.getPrimaryAddress() != null) { bestMatch = this.findEmptyChannel(conn, device, requestDto, bestMatch); if (bestMatch != null) { final ChannelElementValuesDto updatedChannel = this.writeUpdatedMbus(conn, requestDto, bestMatch.getChannel()); channelElements.set(bestMatch.getChannel() - 1, updatedChannel); } } return new MbusChannelElementsResponseDto(requestDto, bestMatch == null ? null : bestMatch.getChannel(), channelElements); }