CombinedMaster implements AbstractMaster<D> { protected void applyPaging(AbstractDocumentsResult<D> result, PagingRequest originalRequest) { result.setPaging(Paging.of(originalRequest, result.getDocuments().size())); int docSize = result.getDocuments().size(); int firstItem = originalRequest.getFirstItem() > docSize ? docSize : originalRequest.getFirstItem(); int lastItem = originalRequest.getLastItem() > docSize ? docSize : originalRequest.getLastItem(); ArrayList<D> resultDocuments = Lists.newArrayList(result.getDocuments().subList(firstItem, lastItem)); result.setDocuments(resultDocuments); } protected  CombinedMaster(List<M> masterList); @Override D get(final UniqueId uniqueId); @Override D get(final ObjectIdentifiable objectId, final VersionCorrection versionCorrection); @Override D add(final D document); @Override D update(final D document); @Override void remove(final ObjectIdentifiable objectIdentifiable); @Override D correct(final D document); @Override final List<UniqueId> replaceVersion(final UniqueId uniqueId, final List<D> replacementDocuments); @Override final List<UniqueId> replaceAllVersions(final ObjectIdentifiable objectId, final List<D> replacementDocuments); @Override List<UniqueId> replaceVersions(final ObjectIdentifiable objectId, final List<D> replacementDocuments); @Override final void removeVersion(final UniqueId uniqueId); @Override final UniqueId replaceVersion(D replacementDocument); @Override final UniqueId addVersion(ObjectIdentifiable objectId, D documentToAdd); @Override Map<UniqueId, D> get(Collection<UniqueId> uniqueIds);  }
@Test public void applyPaging() { HolidayDocument m1h1 = holidayDocWithId("m1", "1"); HolidayDocument m1h2 = holidayDocWithId("m1", "2"); HolidayDocument m1h3 = holidayDocWithId("m1", "3"); HolidayDocument m1h4 = holidayDocWithId("m1", "4"); HolidaySearchResult sr; sr = new HolidaySearchResult(ImmutableList.of(m1h1, m1h2, m1h3, m1h4)); PagingRequest ofIndex ; ofIndex = PagingRequest.ofIndex(1, 3); cMaster.applyPaging(sr, ofIndex); assertEquals(Paging.of(ofIndex, 4), sr.getPaging()); assertEquals(ImmutableList.of(m1h2, m1h3, m1h4), sr.getDocuments()); sr = new HolidaySearchResult(ImmutableList.of(m1h1, m1h2, m1h3, m1h4)); ofIndex = PagingRequest.ofIndex(100, 103); cMaster.applyPaging(sr, ofIndex); assertEquals(Paging.of(ofIndex, 4), sr.getPaging()); assertEquals(ImmutableList.of(), sr.getDocuments()); }