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      public byte[] getCookie()
69      {
70          return cookie;
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      public void setCookie( byte[] cookie )
78      {
79          this.cookie = cookie;
80      }
81  
82  
83      /**
84       * {@inheritDoc}
85       */
86      public boolean isRefreshDeletes()
87      {
88          return refreshDeletes;
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      public void setRefreshDeletes( boolean refreshDeletes )
96      {
97          this.refreshDeletes = refreshDeletes;
98      }
99  
100 
101     /**
102      * @see Object#hashCode()
103      */
104     @Override
105     public int hashCode()
106     {
107         int h = 37;
108 
109         h = h * 17 + super.hashCode();
110         h = h * 17 + ( refreshDeletes ? 1 : 0 );
111 
112         if ( cookie != null )
113         {
114             for ( byte b : cookie )
115             {
116                 h = h * 17 + b;
117             }
118         }
119 
120         return h;
121     }
122 
123 
124     /**
125      * @see Object#equals(Object)
126      */
127     @Override
128     public boolean equals( Object o )
129     {
130         if ( this == o )
131         {
132             return true;
133         }
134 
135         if ( !( o instanceof SyncDoneValue ) )
136         {
137             return false;
138         }
139 
140         SyncDoneValue otherControl = ( SyncDoneValue ) o;
141 
142         return ( refreshDeletes == otherControl.isRefreshDeletes() ) &&
143             ( Arrays.equals( cookie, otherControl.getCookie() ) &&
144             ( isCritical() == otherControl.isCritical() ) );
145     }
146 
147 
148     /**
149      * @see Object#toString()
150      */
151     @Override
152     public String toString()
153     {
154         StringBuilder sb = new StringBuilder();
155 
156         sb.append( "    SyncDoneValue control :\n" );
157         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
158         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
159         sb.append( "        cookie            : '" ).append( Strings.dumpBytes( getCookie() ) ).append( "'\n" );
160         sb.append( "        refreshDeletes : '" ).append( isRefreshDeletes() ).append( "'\n" );
161 
162         return sb.toString();
163     }
164 }