001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2010 Sun Microsystems, Inc. 025 * Portions Copyright 2013-2015 ForgeRock AS. 026 */ 027package org.opends.server.replication.plugin; 028 029import org.forgerock.opendj.ldap.ByteString; 030import org.opends.server.replication.common.CSN; 031 032/** AttrValueHistorical is the historical information of the modification of one attribute value. */ 033public class AttrValueHistorical 034{ 035 private ByteString value; 036 private CSN valueDeleteTime; 037 private CSN valueUpdateTime; 038 039 /** 040 * Build an AttrValueHistorical for a provided attribute value, providing 041 * the last time the provided value is either updated or deleted. 042 * @param value the provided attributeValue 043 * @param csnUpdate last time when this value was updated 044 * @param csnDelete last time when this value for deleted 045 */ 046 public AttrValueHistorical(ByteString value, CSN csnUpdate, CSN csnDelete) 047 { 048 this.value = value; 049 this.valueUpdateTime = csnUpdate; 050 this.valueDeleteTime = csnDelete; 051 } 052 053 @Override 054 public boolean equals(Object obj) 055 { 056 if (obj instanceof AttrValueHistorical) 057 { 058 AttrValueHistorical objVal = (AttrValueHistorical) obj; 059 return value.equals(objVal.getAttributeValue()); 060 } 061 return false; 062 } 063 064 @Override 065 public int hashCode() 066 { 067 return value.hashCode(); 068 } 069 070 /** 071 * Get the last time when the value was deleted. 072 * @return the last time when the value was deleted 073 */ 074 public CSN getValueDeleteTime() 075 { 076 return valueDeleteTime; 077 } 078 079 /** 080 * Get the last time when the value was updated. 081 * @return the last time when the value was updated 082 */ 083 public CSN getValueUpdateTime() 084 { 085 return valueUpdateTime; 086 } 087 088 /** 089 * Get the attributeValue for which this object was generated. 090 * @return the value for which this object was generated 091 */ 092 public ByteString getAttributeValue() 093 { 094 return value; 095 } 096 097 /** 098 * Check if the value associated with this object was updated. 099 * @return true if the value associated with this object was updated 100 */ 101 public boolean isUpdate() 102 { 103 return valueUpdateTime != null; 104 } 105 106 @Override 107 public String toString() 108 { 109 if (valueUpdateTime != null) 110 { 111 return valueDeleteTime != null 112 // valueUpdateTime and valueDeleteTime should have the same value 113 ? valueUpdateTime + ":replace:" + value 114 : valueUpdateTime + ":add:" + value; 115 } 116 else 117 { 118 return valueDeleteTime != null 119 ? valueDeleteTime + ":delete:" + value 120 : "????:" + value; 121 } 122 } 123}