/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Tests sorted sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void sortedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry1, entries[0]); AssertJUnit.assertEquals(entry2, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests ordered sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void orderedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry2, entries[0]); AssertJUnit.assertEquals(entry1, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final SearchResult sr = new SearchResult(); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), sr.getSortBehavior()); AssertJUnit.assertEquals(0, sr.size()); AssertJUnit.assertNull(sr.getEntry()); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }