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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.replication.plugin;
028    
029    import org.opends.server.replication.common.ChangeNumber;
030    import org.opends.server.types.AttributeValue;
031    
032    /**
033     * Allows to store historical information about specific values
034     * for a given attribute.
035     */
036    public class ValueInfo
037    {
038      private AttributeValue value;
039      private ChangeNumber valueDeleteTime;
040      private ChangeNumber valueUpdateTime;
041    
042      /**
043       * Build a new ValueInfo.
044       * @param value value for which ValueInfo is built
045       * @param CNupdate last time when value was updated last
046       * @param CNdelete last time when value for deleted
047       */
048      public ValueInfo(AttributeValue value,
049                       ChangeNumber CNupdate,
050                       ChangeNumber CNdelete)
051      {
052        this.value = value;
053        this.valueUpdateTime = CNupdate;
054        this.valueDeleteTime = CNdelete;
055      }
056    
057      /**
058       * Compares this object with another ValueInfo object.
059       * Object are said equals when their values matches.
060       * @param obj object to be compared with this object
061       * @return true if equal, false otherwise
062       */
063      @Override
064      public boolean equals(Object obj)
065      {
066        if (obj instanceof ValueInfo)
067        {
068          ValueInfo objVal = (ValueInfo) obj;
069          return (value.equals(objVal.getValue()));
070        }
071        else
072        {
073          return false;
074        }
075      }
076    
077      /**
078       * calculates the hasCode for this object.
079       * Only value is used when calculating the hashCode
080       * @return the hashcode
081       */
082      @Override
083      public int hashCode()
084      {
085        return value.hashCode();
086      }
087    
088      /**
089       * Get the last time when the value was deleted.
090       * @return the last time when the value was deleted
091       */
092      public ChangeNumber getValueDeleteTime()
093      {
094        return valueDeleteTime;
095      }
096    
097      /**
098       * Get the last time when the value was updated.
099       * @return the last time when the value was updated
100       */
101      public ChangeNumber getValueUpdateTime()
102      {
103        return valueUpdateTime;
104      }
105    
106      /**
107       * Get the value for which this ValueInfo was generated.
108       * @return the value for which this ValueInfo was generated
109       */
110      public AttributeValue getValue()
111      {
112        return value;
113      }
114    
115      /**
116       * Check if the value associated with this ValueInfo was updated.
117       * @return true if the value associated with this ValueInfo was updated
118       */
119      public boolean isUpdate()
120      {
121        if (valueUpdateTime != null)
122          return true;
123        else
124          return false;
125      }
126    }