View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.api.ldap.model.message.controls;
21  
22  /**
23   * Implementation of SortResponseControl.
24   *
25   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
26   */
27  public class SortResponseControlImpl extends AbstractControl  implements SortResponse
28  {
29      /** the sort operations result code */
30      private SortResultCode result;
31      
32      /** name of the first offending attribute */
33      private String attributeName;
34      
35      /**
36       * Creates a new SortResponseControlImpl instance
37       */
38      public SortResponseControlImpl()
39      {
40          super( OID );
41      }
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      public void setSortResult( SortResultCode result )
48      {
49          this.result = result;
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public SortResultCode getSortResult()
57      {
58          return result;
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      public void setAttributeName( String attributeName )
66      {
67          this.attributeName = attributeName;
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      public String getAttributeName()
75      {
76          return attributeName;
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public int hashCode()
84      {
85          final int prime = 31;
86          int hash = super.hashCode();
87          hash = prime * hash + ( ( attributeName == null ) ? 0 : attributeName.hashCode() );
88          hash = prime * hash + ( ( this.result == null ) ? 0 : this.result.hashCode() );
89          
90          return hash;
91      }
92  
93      /**
94       * {@inheritDoc}
95       */
96      @Override
97      public boolean equals( Object o )
98      {
99          if ( !super.equals( o ) )
100         {
101             return false;
102         }
103         
104         SortResponse that = ( SortResponse ) o;
105         
106         if ( result != that.getSortResult() )
107         {
108             return false;
109         }
110         
111         if ( attributeName != null )
112         {
113             return attributeName.equalsIgnoreCase( that.getAttributeName() );
114         }
115         else if ( that.getAttributeName() == null )
116         {
117             return true;
118         }
119         
120         return false;
121     }
122 
123     /**
124      * {@inheritDoc}
125      */
126     @Override
127     public String toString()
128     {
129         return "SortResponseControlImpl [result=" + result + ", attributeName=" + attributeName + "]";
130     }
131     
132 }