Package org.ldaptive

Class SearchResponse

  • All Implemented Interfaces:
    Message, Result

    public class SearchResponse
    extends AbstractResult
    Response that encapsulates the result elements of a search request. This class formally decodes the SearchResultDone LDAP message defined as:
       SearchResultDone ::= [APPLICATION 5] LDAPResult
     
    • Field Detail

      • HASH_CODE_SEED

        private static final int HASH_CODE_SEED
        hash code seed.
        See Also:
        Constant Field Values
      • RESULT_CODE_PATH

        private static final DERPath RESULT_CODE_PATH
        DER path to result code.
      • MATCHED_DN_PATH

        private static final DERPath MATCHED_DN_PATH
        DER path to matched DN.
      • DIAGNOSTIC_MESSAGE_PATH

        private static final DERPath DIAGNOSTIC_MESSAGE_PATH
        DER path to diagnostic message.
      • REFERRAL_PATH

        private static final DERPath REFERRAL_PATH
        DER path to referral.
      • resultEntries

        private final List<LdapEntry> resultEntries
        Entries contained in this result.
      • resultReferences

        private final List<SearchResultReference> resultReferences
        Search result references contained in this result.
    • Constructor Detail

      • SearchResponse

        public SearchResponse()
        Default constructor.
      • SearchResponse

        public SearchResponse​(DERBuffer buffer)
        Creates a new search result done.
        Parameters:
        buffer - to decode
    • Method Detail

      • initialize

        public void initialize​(SearchResponse result)
        Copies the values of the supplied search result done to this synthetic result.
        Parameters:
        result - of values to copy
      • getEntries

        public Collection<LdapEntry> getEntries()
        Returns a collection of ldap entry.
        Returns:
        collection of ldap entry
      • getEntry

        public LdapEntry getEntry()
        Returns a single entry of this result. If multiple entries exist the first entry returned by the underlying iterator is used. If no entries exist null is returned.
        Returns:
        search result entry
      • getEntry

        public LdapEntry getEntry​(String dn)
        Returns the ldap entry in this result with the supplied DN. DN comparison is attempted with a normalized string comparison, see DefaultRDnNormalizer.
        Parameters:
        dn - of the entry to return
        Returns:
        search result entry or null if no entry matching the dn could be found
        Throws:
        IllegalArgumentException - if the supplied dn cannot be normalized
      • getEntryDns

        public Set<String> getEntryDns()
        Returns the entry DNs in this result.
        Returns:
        string array of entry DNs
      • addEntries

        public void addEntries​(LdapEntry... entry)
        Adds an entry to this search result.
        Parameters:
        entry - entry to add
      • addEntries

        public void addEntries​(Collection<LdapEntry> entries)
        Adds entry(s) to this search result.
        Parameters:
        entries - collection of entries to add
      • entrySize

        public int entrySize()
        Returns the number of entries in this search result.
        Returns:
        number of entries in this search result
      • getReference

        public SearchResultReference getReference()
        Returns a single search reference of this result. If multiple references exist the first references returned by the underlying iterator is used. If no references exist null is returned.
        Returns:
        search result references
      • addReferences

        public void addReferences​(SearchResultReference... reference)
        Adds a reference to this search result.
        Parameters:
        reference - reference to add
      • addReferences

        public void addReferences​(Collection<SearchResultReference> references)
        Adds references(s) to this search result.
        Parameters:
        references - collection of references to add
      • referenceSize

        public int referenceSize()
        Returns the number of references in this search result.
        Returns:
        number of references in this search result
      • subResult

        public SearchResponse subResult​(int fromIndex,
                                        int toIndex)
        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.
        Parameters:
        fromIndex - low endpoint of the search result (inclusive)
        toIndex - high endpoint of the search result (exclusive)
        Returns:
        portion of this search result
        Throws:
        IndexOutOfBoundsException - for illegal index values
      • hashCode

        public int hashCode()
        Description copied from class: AbstractMessage
        Returns the hash code for this object.
        Specified by:
        hashCode in class AbstractMessage
        Returns:
        hash code
      • merge

        public static SearchResponse merge​(SearchResponse result)
        Merges the entries in the supplied result into a single entry. This method always returns a search result of size zero or one.
        Parameters:
        result - search result containing entries to merge
        Returns:
        search result containing a single merged entry
      • builder

        public static SearchResponse.Builder builder()
        Creates a builder for this class.
        Returns:
        new builder