private List generateDto(Map, Group> results, boolean withParams, boolean withPublicCards, boolean toProfileDto) { return results.entrySet().stream().map(item -> { Long hasConflict = (Long) item.getKey().get(1); Long hasMatchCountryCode = (Long) item.getKey().get(2); Boolean notInSC = (Boolean) item.getKey().get(3); String connectionUuid = (String) item.getKey().get(4); Long isFollowedByUser = (Long) item.getKey().get(5); Long isRetail = (Long) item.getKey().get(6); Boolean hasOriginalVersion = null; if (item.getKey().size() > 7) { Long hasOriginal = (Long) item.getKey().get(7); hasOriginalVersion = hasOriginal != null && hasOriginal > 0; } return toDetailedDto((Profile) item.getKey().get(0), item.getValue().getSet(new QCard("card")), item.getValue().getGroup(GroupBy.map(new QField("strangeField"), GroupBy.set(new QField("childField")))), hasConflict != null && hasConflict > 0, hasMatchCountryCode != null && hasMatchCountryCode > 0, notInSC != null ? notInSC : false, connectionUuid, isFollowedByUser != null && isFollowedByUser > 0, isRetail != null && isRetail > 0, hasOriginalVersion, Boolean.FALSE, // result of the task toProfileDto); }).collect(toList()); }