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.syncState;
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 SyncStateValue Control implementation.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   * @version $Rev$, $Date$
34   */
35  public class SyncStateValueImpl extends AbstractControl implements SyncStateValue
36  {
37      /** The syncStateEnum type */
38      private SyncStateTypeEnum type;
39  
40      /** The Sync cookie */
41      private byte[] cookie;
42  
43      /** The entryUUID */
44      private byte[] entryUuid;
45  
46  
47      /**SyncStateValueImpl
48       * Creates a new instance of SyncDoneValueImpl.
49       */
50      public SyncStateValueImpl()
51      {
52          super( OID );
53      }
54  
55  
56      /**
57       *
58       * Creates a new instance of SyncStateValueImpl.
59       *
60       * @param isCritical The critical flag
61       */
62      public SyncStateValueImpl( boolean isCritical )
63      {
64          super( OID, isCritical );
65      }
66  
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public byte[] getCookie()
73      {
74          return cookie;
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public void setCookie( byte[] cookie )
83      {
84          this.cookie = cookie;
85      }
86  
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public SyncStateTypeEnum getSyncStateType()
93      {
94          return type;
95      }
96  
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     public void setSyncStateType( SyncStateTypeEnum syncStateType )
103     {
104         this.type = syncStateType;
105     }
106 
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public byte[] getEntryUUID()
113     {
114         return entryUuid;
115     }
116 
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     public void setEntryUUID( byte[] entryUUID )
123     {
124         this.entryUuid = entryUUID;
125     }
126 
127 
128     /**
129      * @see Object#hashCode()
130      */
131     @Override
132     public int hashCode()
133     {
134         int h = 37;
135 
136         h = h * 17 + super.hashCode();
137         h = h * 17 + type.getValue();
138 
139         if ( cookie != null )
140         {
141             for ( byte b : cookie )
142             {
143                 h = h * 17 + b;
144             }
145         }
146 
147         if ( entryUuid != null )
148         {
149             for ( byte b : entryUuid )
150             {
151                 h = h * 17 + b;
152             }
153         }
154 
155         return h;
156     }
157 
158 
159     /**
160      * @see Object#equals(Object)
161      */
162     @Override
163     public boolean equals( Object o )
164     {
165         if ( !super.equals( o ) )
166         {
167             return false;
168         }
169 
170         if ( !( o instanceof SyncStateValue ) )
171         {
172             return false;
173         }
174 
175         SyncStateValue otherControl = ( SyncStateValue ) o;
176 
177         return ( type == otherControl.getSyncStateType() )
178             && ( Arrays.equals( entryUuid, otherControl.getEntryUUID() ) )
179             && ( Arrays.equals( cookie, otherControl.getCookie() ) )
180             && ( isCritical() == otherControl.isCritical() );
181     }
182 
183 
184     /**
185      * @see Object#toString()
186      */
187     @Override
188     public String toString()
189     {
190         StringBuilder sb = new StringBuilder();
191 
192         sb.append( "    SyncStateValue control :\n" );
193         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
194         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
195         sb.append( "        syncStateType     : '" ).append( getSyncStateType() ).append( "'\n" );
196         sb.append( "        entryUUID         : '" ).append( Strings.dumpBytes( getEntryUUID() ) ).append( "'\n" );
197         sb.append( "        cookie            : '" ).append( Strings.dumpBytes( getCookie() ) ).append( "'\n" );
198 
199         return sb.toString();
200     }
201 }