001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.model.message;
021
022
023/**
024 * SearchResponseDone implementation
025 * 
026 * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
027 */
028public class SearchResultDoneImpl extends AbstractResultResponse implements SearchResultDone
029{
030    static final long serialVersionUID = 8698484213877460215L;
031
032
033    /**
034     * Creates a SearchResponseDone as a reply to an SearchRequest to
035     * indicate the end of a search operation.
036     */
037    public SearchResultDoneImpl()
038    {
039        super( -1, MessageTypeEnum.SEARCH_RESULT_DONE );
040    }
041
042
043    /**
044     * Creates a SearchResponseDone as a reply to an SearchRequest to
045     * indicate the end of a search operation.
046     * 
047     * @param id the session unique message id
048     */
049    public SearchResultDoneImpl( final int id )
050    {
051        super( id, MessageTypeEnum.SEARCH_RESULT_DONE );
052    }
053
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public int hashCode()
060    {
061        int hash = 37;
062        hash = hash * 17 + getLdapResult().hashCode();
063        hash = hash * 17 + super.hashCode();
064
065        return hash;
066    }
067
068
069    /**
070     * Checks for equality by using the underlying LdapResult objects of this
071     * SearchResponseDone stub.
072     * 
073     * @param obj
074     *            the object to be tested for equality
075     * @return true if obj is equivalent to this SearchResponseDone impl
076     */
077    @Override
078    public boolean equals( Object obj )
079    {
080        // quickly return if the obj is this object
081        if ( obj == this )
082        {
083            return true;
084        }
085
086        if ( !super.equals( obj ) )
087        {
088            return false;
089        }
090
091        LdapResult result = ( ( SearchResultDone ) obj ).getLdapResult();
092
093        return getLdapResult().equals( result );
094    }
095
096
097    /**
098     * Get a String representation of a SearchResultDone
099     * 
100     * @return A SearchResultDone String
101     */
102    @Override
103    public String toString()
104    {
105        StringBuilder sb = new StringBuilder();
106
107        sb.append( "    Search Result Done\n" );
108        sb.append( super.toString() );
109
110        return super.toString( sb.toString() );
111    }
112}