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