SearchResponse extends AbstractResult { public SearchResponse subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResponse result = new SearchResponse(); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntries(e.getValue()); } i++; } return result; } SearchResponse();  SearchResponse(final DERBuffer buffer); void initialize(final SearchResponse result); Collection<LdapEntry> getEntries(); LdapEntry getEntry(); LdapEntry getEntry(final String dn); Set<String> getEntryDns(); void addEntries(final LdapEntry... entry); void addEntries(final Collection<LdapEntry> entries); int entrySize(); Collection<SearchResultReference> getReferences(); SearchResultReference getReference(); void addReferences(final SearchResultReference... reference); void addReferences(final Collection<SearchResultReference> references); int referenceSize(); SearchResponse subResult(final int fromIndex, final int toIndex); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); static SearchResponse sort(final SearchResponse sr); static SearchResponse merge(final SearchResponse result); static Builder builder(); static final int PROTOCOL_OP; }
@Test public void subResult() { final LdapEntry entry1 = LdapEntry.builder() .dn("uid=1").build(); final LdapEntry entry2 = LdapEntry.builder() .dn("uid=2").build(); final SearchResponse sr = new SearchResponse(); sr.addEntries(entry2, entry1); Assert.assertEquals(sr.subResult(2, 2).entrySize(), 0); Assert.assertEquals(sr.subResult(1, 2).entrySize(), 1); Assert.assertEquals(sr.subResult(0, 2).entrySize(), 2); try { sr.subResult(-1, 1); Assert.fail("Should have thrown IndexOutOfBoundsException"); } catch (Exception e) { Assert.assertEquals(e.getClass(), IndexOutOfBoundsException.class); } try { sr.subResult(0, 3); Assert.fail("Should have thrown IndexOutOfBoundsException"); } catch (Exception e) { Assert.assertEquals(e.getClass(), IndexOutOfBoundsException.class); } try { sr.subResult(1, 0); Assert.fail("Should have thrown IndexOutOfBoundsException"); } catch (Exception e) { Assert.assertEquals(e.getClass(), IndexOutOfBoundsException.class); } }