| 1 | package com.fwmotion.threescale.cms.support; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 4 | import com.fwmotion.threescale.cms.mappers.CmsSectionMapper; | |
| 5 | import com.fwmotion.threescale.cms.model.CmsSection; | |
| 6 | import com.redhat.threescale.rest.cms.ApiException; | |
| 7 | import com.redhat.threescale.rest.cms.api.SectionsApi; | |
| 8 | import com.redhat.threescale.rest.cms.model.SectionList; | |
| 9 | import jakarta.annotation.Nonnull; | |
| 10 | import jakarta.annotation.Nullable; | |
| 11 | import jakarta.validation.constraints.Positive; | |
| 12 | import jakarta.validation.constraints.PositiveOrZero; | |
| 13 | import org.apache.commons.collections4.ListUtils; | |
| 14 | import org.mapstruct.factory.Mappers; | |
| 15 | ||
| 16 | import java.util.*; | |
| 17 | import java.util.stream.Collectors; | |
| 18 | ||
| 19 | public class PagedSectionsSpliterator extends AbstractPagedRestApiSpliterator<CmsSection> { | |
| 20 | ||
| 21 | private static final CmsSectionMapper SECTION_MAPPER = Mappers.getMapper(CmsSectionMapper.class); | |
| 22 | ||
| 23 | private final SectionsApi sectionsApi; | |
| 24 | ||
| 25 | public PagedSectionsSpliterator(@Nonnull SectionsApi sectionsApi, @Nonnull ObjectMapper objectMapper) { | |
| 26 | super(Collections.emptySet(), objectMapper, 0); | |
| 27 | this.sectionsApi = sectionsApi; | |
| 28 | } | |
| 29 | ||
| 30 | public PagedSectionsSpliterator(@Nonnull SectionsApi sectionsApi, | |
| 31 | @Nonnull ObjectMapper objectMapper, | |
| 32 | @Positive int requestedPageSize) { | |
| 33 | super(requestedPageSize, objectMapper, Collections.emptySet(), 0); | |
| 34 | this.sectionsApi = sectionsApi; | |
| 35 | } | |
| 36 | ||
| 37 | private PagedSectionsSpliterator(@Nonnull SectionsApi sectionsApi, | |
| 38 | @Nonnull ObjectMapper objectMapper, | |
| 39 | @Positive int requestedPageSize, | |
| 40 | @Nonnull Collection<CmsSection> currentPage, | |
| 41 | @PositiveOrZero int currentPageNumber) { | |
| 42 | super(requestedPageSize, objectMapper, currentPage, currentPageNumber); | |
| 43 | this.sectionsApi = sectionsApi; | |
| 44 | } | |
| 45 | ||
| 46 | @Nullable | |
| 47 | @Override | |
| 48 | protected Collection<CmsSection> getPage(@PositiveOrZero int pageNumber, | |
| 49 | @Positive int pageSize) { | |
| 50 | try { | |
| 51 | SectionList sectionList = sectionsApi.listSections(pageNumber, pageSize); | |
| 52 | ||
| 53 | List<CmsSection> resultPage = | |
| 54 | ListUtils.emptyIfNull(sectionList.getCollection()) | |
| 55 | .stream() | |
| 56 | .map(SECTION_MAPPER::fromRest) | |
| 57 | .collect(Collectors.toList()); | |
| 58 | ||
| 59 |
1
1. getPage : removed call to com/fwmotion/threescale/cms/support/PagedSectionsSpliterator::validateResultPageSize → SURVIVED |
validateResultPageSize( |
| 60 | "section", | |
| 61 | pageNumber, | |
| 62 | pageSize, | |
| 63 | resultPage, | |
| 64 | sectionList.getMetadata()); | |
| 65 | ||
| 66 |
1
1. getPage : replaced return value with Collections.emptyList for com/fwmotion/threescale/cms/support/PagedSectionsSpliterator::getPage → KILLED |
return resultPage; |
| 67 | } catch (ApiException e) { | |
| 68 | throw handleApiException(e, "section", pageNumber, pageSize); | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | @Nonnull | |
| 73 | @Override | |
| 74 | protected AbstractPagedRestApiSpliterator<CmsSection> doSplit( | |
| 75 | @Positive int requestedPageSize, | |
| 76 | @Nonnull Collection<CmsSection> currentPage, | |
| 77 | @PositiveOrZero int currentPageNumber) { | |
| 78 |
1
1. doSplit : replaced return value with null for com/fwmotion/threescale/cms/support/PagedSectionsSpliterator::doSplit → KILLED |
return new PagedSectionsSpliterator(sectionsApi, getObjectMapper(), requestedPageSize, currentPage, currentPageNumber); |
| 79 | } | |
| 80 | ||
| 81 | @Override | |
| 82 | public int characteristics() { | |
| 83 |
1
1. characteristics : replaced int return with 0 for com/fwmotion/threescale/cms/support/PagedSectionsSpliterator::characteristics → SURVIVED |
return Spliterator.DISTINCT | |
| 84 | Spliterator.SORTED | | |
| 85 | Spliterator.ORDERED | | |
| 86 | Spliterator.NONNULL | | |
| 87 | Spliterator.IMMUTABLE; | |
| 88 | } | |
| 89 | ||
| 90 | @Nonnull | |
| 91 | @Override | |
| 92 | public Comparator<? super CmsSection> getComparator() { | |
| 93 |
1
1. getComparator : replaced return value with null for com/fwmotion/threescale/cms/support/PagedSectionsSpliterator::getComparator → SURVIVED |
return Comparator.comparing(CmsSection::getId); |
| 94 | } | |
| 95 | ||
| 96 | } | |
Mutations | ||
| 59 |
1.1 |
|
| 66 |
1.1 |
|
| 78 |
1.1 |
|
| 83 |
1.1 |
|
| 93 |
1.1 |