001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.extras.controls.syncrepl.syncState; 021 022 023import java.util.Arrays; 024 025import org.apache.directory.api.ldap.model.message.controls.AbstractControl; 026import org.apache.directory.api.util.Strings; 027 028 029/** 030 * A simple SyncStateValue Control implementation. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 * @version $Rev$, $Date$ 034 */ 035public class SyncStateValueImpl extends AbstractControl implements SyncStateValue 036{ 037 /** The syncStateEnum type */ 038 private SyncStateTypeEnum type; 039 040 /** The Sync cookie */ 041 private byte[] cookie; 042 043 /** The entryUUID */ 044 private byte[] entryUuid; 045 046 047 /**SyncStateValueImpl 048 * Creates a new instance of SyncDoneValueImpl. 049 */ 050 public SyncStateValueImpl() 051 { 052 super( OID ); 053 } 054 055 056 /** 057 * 058 * Creates a new instance of SyncStateValueImpl. 059 * 060 * @param isCritical The critical flag 061 */ 062 public SyncStateValueImpl( boolean isCritical ) 063 { 064 super( OID, isCritical ); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 @Override 072 public byte[] getCookie() 073 { 074 return cookie; 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public void setCookie( byte[] cookie ) 083 { 084 this.cookie = cookie; 085 } 086 087 088 /** 089 * {@inheritDoc} 090 */ 091 @Override 092 public SyncStateTypeEnum getSyncStateType() 093 { 094 return type; 095 } 096 097 098 /** 099 * {@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 = super.hashCode(); 135 136 h = h * 17 + type.getValue(); 137 138 if ( cookie != null ) 139 { 140 for ( byte b : cookie ) 141 { 142 h = h * 17 + b; 143 } 144 } 145 146 if ( entryUuid != null ) 147 { 148 for ( byte b : entryUuid ) 149 { 150 h = h * 17 + b; 151 } 152 } 153 154 return h; 155 } 156 157 158 /** 159 * @see Object#equals(Object) 160 */ 161 @Override 162 public boolean equals( Object o ) 163 { 164 if ( this == o ) 165 { 166 return true; 167 } 168 169 if ( !( o instanceof SyncStateValue ) ) 170 { 171 return false; 172 } 173 174 SyncStateValue otherControl = ( SyncStateValue ) o; 175 176 return super.equals( o ) 177 && ( 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}