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.extras.controls.syncrepl.syncDone;
21  
22  
23  import java.util.Arrays;
24  
25  import org.apache.directory.api.ldap.model.message.controls.AbstractControl;
26  import org.apache.directory.api.util.Strings;
27  
28  
29  /**
30   * A simple {@link SyncDoneValue} implementation to store control properties.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   * @version $Rev$, $Date$
34   */
35  public class SyncDoneValueImpl extends AbstractControl implements SyncDoneValue
36  {
37      /** The Sync cookie */
38      private byte[] cookie;
39  
40      /** the refreshDeletes flag */
41      private boolean refreshDeletes;
42  
43  
44      /**
45       * Creates a new instance of SyncDoneValueImpl.
46       */
47      public SyncDoneValueImpl()
48      {
49          super( OID );
50      }
51  
52  
53      /**
54       *
55       * Creates a new instance of SyncDoneValueImpl.
56       *
57       * @param isCritical The critical flag
58       */
59      public SyncDoneValueImpl( boolean isCritical )
60      {
61          super( OID, isCritical );
62      }
63  
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public byte[] getCookie()
70      {
71          return cookie;
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      @Override
79      public void setCookie( byte[] cookie )
80      {
81          this.cookie = cookie;
82      }
83  
84  
85      /**
86       * {@inheritDoc}
87       */
88      @Override
89      public boolean isRefreshDeletes()
90      {
91          return refreshDeletes;
92      }
93  
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public void setRefreshDeletes( boolean refreshDeletes )
100     {
101         this.refreshDeletes = refreshDeletes;
102     }
103 
104 
105     /**
106      * @see Object#hashCode()
107      */
108     @Override
109     public int hashCode()
110     {
111         int h = 37;
112 
113         h = h * 17 + super.hashCode();
114         h = h * 17 + ( refreshDeletes ? 1 : 0 );
115 
116         if ( cookie != null )
117         {
118             for ( byte b : cookie )
119             {
120                 h = h * 17 + b;
121             }
122         }
123 
124         return h;
125     }
126 
127 
128     /**
129      * @see Object#equals(Object)
130      */
131     @Override
132     public boolean equals( Object o )
133     {
134         if ( this == o )
135         {
136             return true;
137         }
138 
139         if ( !( o instanceof SyncDoneValue ) )
140         {
141             return false;
142         }
143 
144         SyncDoneValue otherControl = ( SyncDoneValue ) o;
145 
146         return ( refreshDeletes == otherControl.isRefreshDeletes() )
147             && ( Arrays.equals( cookie, otherControl.getCookie() ) )
148             && ( isCritical() == otherControl.isCritical() );
149     }
150 
151 
152     /**
153      * @see Object#toString()
154      */
155     @Override
156     public String toString()
157     {
158         StringBuilder sb = new StringBuilder();
159 
160         sb.append( "    SyncDoneValue control :\n" );
161         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
162         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
163         sb.append( "        cookie            : '" ).append( Strings.dumpBytes( getCookie() ) ).append( "'\n" );
164         sb.append( "        refreshDeletes : '" ).append( isRefreshDeletes() ).append( "'\n" );
165 
166         return sb.toString();
167     }
168 }