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.syncDone; 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 {@link SyncDoneValue} implementation to store control properties. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 * @version $Rev$, $Date$ 034 */ 035public class SyncDoneValueImpl extends AbstractControl implements SyncDoneValue 036{ 037 /** The Sync cookie */ 038 private byte[] cookie; 039 040 /** the refreshDeletes flag */ 041 private boolean refreshDeletes; 042 043 044 /** 045 * Creates a new instance of SyncDoneValueImpl. 046 */ 047 public SyncDoneValueImpl() 048 { 049 super( OID ); 050 } 051 052 053 /** 054 * 055 * Creates a new instance of SyncDoneValueImpl. 056 * 057 * @param isCritical The critical flag 058 */ 059 public SyncDoneValueImpl( boolean isCritical ) 060 { 061 super( OID, isCritical ); 062 } 063 064 065 /** 066 * {@inheritDoc} 067 */ 068 @Override 069 public byte[] getCookie() 070 { 071 return cookie; 072 } 073 074 075 /** 076 * {@inheritDoc} 077 */ 078 @Override 079 public void setCookie( byte[] cookie ) 080 { 081 this.cookie = cookie; 082 } 083 084 085 /** 086 * {@inheritDoc} 087 */ 088 @Override 089 public boolean isRefreshDeletes() 090 { 091 return refreshDeletes; 092 } 093 094 095 /** 096 * {@inheritDoc} 097 */ 098 @Override 099 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 = super.hashCode(); 112 113 h = h * 17 + ( refreshDeletes ? 1 : 0 ); 114 115 if ( cookie != null ) 116 { 117 for ( byte b : cookie ) 118 { 119 h = h * 17 + b; 120 } 121 } 122 123 return h; 124 } 125 126 127 /** 128 * @see Object#equals(Object) 129 */ 130 @Override 131 public boolean equals( Object o ) 132 { 133 if ( this == o ) 134 { 135 return true; 136 } 137 138 if ( !( o instanceof SyncDoneValue ) ) 139 { 140 return false; 141 } 142 143 SyncDoneValue otherControl = ( SyncDoneValue ) o; 144 145 return super.equals( o ) 146 && ( 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}