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   *     https://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 SortResponseImpl 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 SortResponseImpl()
39      {
40          super( OID );
41      }
42  
43      
44      /**
45       * {@inheritDoc}
46       */
47      @Override
48      public void setSortResult( SortResultCode result )
49      {
50          this.result = result;
51      }
52  
53      
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58      public SortResultCode getSortResult()
59      {
60          return result;
61      }
62  
63      
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public void setAttributeName( String attributeName )
69      {
70          this.attributeName = attributeName;
71      }
72  
73      
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public String getAttributeName()
79      {
80          return attributeName;
81      }
82  
83      
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public int hashCode()
89      {
90          int hash = super.hashCode();
91          
92          hash = 37 * hash + ( ( attributeName == null ) ? 0 : attributeName.hashCode() );
93          hash = 37 * hash + ( ( this.result == null ) ? 0 : this.result.hashCode() );
94          
95          return hash;
96      }
97  
98      
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public boolean equals( Object o )
104     {
105         if ( this == o )
106         {
107             return true;
108         }
109         
110         if ( !( o instanceof SortResponse ) )
111         {
112             return false;
113         }
114         
115         SortResponse that = ( SortResponse ) o;
116         
117         if ( !super.equals( o ) )
118         {
119             return false;
120         }
121         
122         if ( result != that.getSortResult() )
123         {
124             return false;
125         }
126         
127         if ( attributeName != null )
128         {
129             return attributeName.equalsIgnoreCase( that.getAttributeName() );
130         }
131         else if ( that.getAttributeName() == null )
132         {
133             return true;
134         }
135         
136         return false;
137     }
138 
139     
140     /**
141      * {@inheritDoc}
142      */
143     @Override
144     public String toString()
145     {
146         return "SortResponseControlImpl [result=" + result + ", attributeName=" + attributeName + "]";
147     }
148 }