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