001    /*
002     * Copyright 2007-2013 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2008-2013 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk;
022    
023    
024    
025    import com.unboundid.asn1.ASN1StreamReader;
026    import com.unboundid.asn1.ASN1StreamReaderSequence;
027    import com.unboundid.util.NotMutable;
028    import com.unboundid.util.ThreadSafety;
029    import com.unboundid.util.ThreadSafetyLevel;
030    
031    
032    
033    /**
034     * This class provides a data structure for holding information about the result
035     * of processing a compare operation.  It provides generic response elements as
036     * described in the {@link LDAPResult} class, and also includes a
037     * {@link CompareResult#compareMatched} method for determining whether the
038     * compare operation matched the target entry.
039     */
040    @NotMutable()
041    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
042    public final class CompareResult
043           extends LDAPResult
044    {
045      /**
046       * The serial version UID for this serializable class.
047       */
048      private static final long serialVersionUID = -6061844770039020617L;
049    
050    
051    
052      /**
053       * Creates a new compare result based on the provided LDAP result.
054       *
055       * @param  ldapResult  The LDAP result object to use to create this compare
056       *                     response.
057       */
058      public CompareResult(final LDAPResult ldapResult)
059      {
060        super(ldapResult);
061      }
062    
063    
064    
065      /**
066       * Creates a new compare result with the provided information.
067       *
068       * @param  messageID          The message ID for the LDAP message that is
069       *                            associated with this LDAP result.
070       * @param  resultCode         The result code from the response.
071       * @param  diagnosticMessage  The diagnostic message from the response, if
072       *                            available.
073       * @param  matchedDN          The matched DN from the response, if available.
074       * @param  referralURLs       The set of referral URLs from the response, if
075       *                            available.
076       * @param  responseControls   The set of controls from the response, if
077       *                            available.
078       */
079      public CompareResult(final int messageID, final ResultCode resultCode,
080                           final String diagnosticMessage, final String matchedDN,
081                           final String[] referralURLs,
082                           final Control[] responseControls)
083      {
084        super(messageID, resultCode, diagnosticMessage, matchedDN, referralURLs,
085              responseControls);
086      }
087    
088    
089    
090      /**
091       * Creates a new compare result object with the provided message ID and with
092       * the protocol op and controls read from the given ASN.1 stream reader.
093       *
094       * @param  messageID        The LDAP message ID for the LDAP message that is
095       *                          associated with this LDAP result.
096       * @param  messageSequence  The ASN.1 stream reader sequence used in the
097       *                          course of reading the LDAP message elements.
098       * @param  reader           The ASN.1 stream reader from which to read the
099       *                          protocol op and controls.
100       *
101       * @return  The decoded compare result.
102       *
103       * @throws  LDAPException  If a problem occurs while reading or decoding data
104       *                         from the ASN.1 stream reader.
105       */
106      static CompareResult readCompareResultFrom(final int messageID,
107                                final ASN1StreamReaderSequence messageSequence,
108                                final ASN1StreamReader reader)
109             throws LDAPException
110      {
111        return new CompareResult(LDAPResult.readLDAPResultFrom(messageID,
112                        messageSequence, reader));
113      }
114    
115    
116    
117      /**
118       * Indicates whether the compare operation matched the target entry.
119       *
120       * @return  {@code true} if the compare operation matched the target entry,
121       *          or {@code false} if not.
122       */
123      public boolean compareMatched()
124      {
125        return (getResultCode().equals(ResultCode.COMPARE_TRUE));
126      }
127    }