001 /* 002 * Copyright 2007-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2008-2015 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 028 029 030 /** 031 * This class provides a data structure for holding information about the result 032 * of processing a compare operation. It provides generic response elements as 033 * described in the {@code LDAPResult} class, and also includes a 034 * {@code CompareResult#compareMatched} method for determining whether the 035 * compare operation matched the target entry. 036 */ 037 public final class CompareResult 038 extends LDAPResult 039 { 040 /** 041 * The serial version UID for this serializable class. 042 */ 043 private static final long serialVersionUID = -6061844770039020617L; 044 045 046 047 /** 048 * Creates a new compare result based on the provided LDAP result. 049 * 050 * @param ldapResult The LDAP result object to use to create this compare 051 * response. 052 */ 053 public CompareResult(final LDAPResult ldapResult) 054 { 055 super(ldapResult); 056 } 057 058 059 060 /** 061 * Creates a new compare result from the provided {@code LDAPException}. 062 * 063 * @param exception The {@code LDAPException} to use to create this compare 064 * result. 065 */ 066 public CompareResult(final LDAPException exception) 067 { 068 super(exception.toLDAPResult()); 069 } 070 071 072 073 /** 074 * Creates a new compare result with the provided information. 075 * 076 * @param messageID The message ID for the LDAP message that is 077 * associated with this LDAP result. 078 * @param resultCode The result code from the response. 079 * @param diagnosticMessage The diagnostic message from the response, if 080 * available. 081 * @param matchedDN The matched DN from the response, if available. 082 * @param referralURLs The set of referral URLs from the response, if 083 * available. 084 * @param responseControls The set of controls from the response, if 085 * available. 086 */ 087 public CompareResult(final int messageID, final ResultCode resultCode, 088 final String diagnosticMessage, final String matchedDN, 089 final String[] referralURLs, 090 final Control[] responseControls) 091 { 092 super(messageID, resultCode, diagnosticMessage, matchedDN, referralURLs, 093 responseControls); 094 } 095 096 097 098 /** 099 * Creates a new compare result object with the provided message ID and with 100 * the protocol op and controls read from the given ASN.1 stream reader. 101 * 102 * @param messageID The LDAP message ID for the LDAP message that is 103 * associated with this LDAP result. 104 * @param messageSequence The ASN.1 stream reader sequence used in the 105 * course of reading the LDAP message elements. 106 * @param reader The ASN.1 stream reader from which to read the 107 * protocol op and controls. 108 * 109 * @return The decoded compare result. 110 * 111 * @throws LDAPException If a problem occurs while reading or decoding data 112 * from the ASN.1 stream reader. 113 */ 114 static CompareResult readCompareResultFrom(final int messageID, 115 final ASN1StreamReaderSequence messageSequence, 116 final ASN1StreamReader reader) 117 throws LDAPException 118 { 119 return new CompareResult(LDAPResult.readLDAPResultFrom(messageID, 120 messageSequence, reader)); 121 } 122 123 124 125 /** 126 * Indicates whether the compare operation matched the target entry. 127 * 128 * @return {@code true} if the compare operation matched the target entry, 129 * or {@code false} if not. 130 */ 131 public boolean compareMatched() 132 { 133 return (getResultCode().equals(ResultCode.COMPARE_TRUE)); 134 } 135 }