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.controls;
021
022/**
023 * Implementation of SortResponseControl.
024 *
025 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
026 */
027public class SortResponseControlImpl extends AbstractControl  implements SortResponse
028{
029    /** the sort operations result code */
030    private SortResultCode result;
031    
032    /** name of the first offending attribute */
033    private String attributeName;
034    
035    public SortResponseControlImpl()
036    {
037        super( OID );
038    }
039
040    @Override
041    public void setSortResult( SortResultCode result )
042    {
043        this.result = result;
044    }
045
046    @Override
047    public SortResultCode getSortResult()
048    {
049        return result;
050    }
051
052    @Override
053    public void setAttributeName( String attributeName )
054    {
055        this.attributeName = attributeName;
056    }
057
058    @Override
059    public String getAttributeName()
060    {
061        return attributeName;
062    }
063
064    @Override
065    public int hashCode()
066    {
067        final int prime = 31;
068        int result = super.hashCode();
069        result = prime * result + ( ( attributeName == null ) ? 0 : attributeName.hashCode() );
070        result = prime * result + ( ( this.result == null ) ? 0 : this.result.hashCode() );
071        return result;
072    }
073
074    @Override
075    public boolean equals( Object o )
076    {
077        if( !super.equals( o ) )
078        {
079            return false;
080        }
081        
082        SortResponse that = ( SortResponse ) o;
083        
084        if( result != that.getSortResult() )
085        {
086            return false;
087        }
088        
089        if( attributeName != null )
090        {
091            return ( attributeName.equalsIgnoreCase( that.getAttributeName() ) );
092        }
093        else if( that.getAttributeName() == null )
094        {
095            return true;
096        }
097        
098        return false;
099    }
100
101    @Override
102    public String toString()
103    {
104        return "SortResponseControlImpl [result=" + result + ", attributeName=" + attributeName + "]";
105    }
106    
107}