001    package com.sptci.prevayler;
002    
003    import java.io.Serializable;
004    
005    /**
006     * A simple value object used to represent the class of a prevalent
007     * object and its objectId.  Instances of this class are used to represent
008     * indexed prevalent objects.
009     *
010     * <p>&copy; Copyright 2008 <a href='http://sptci.com/' target='_top'>Sans
011     * Pareil Technologies, Inc.</a></p>
012     * @author Rakesh Vidyadharan 2008-07-10
013     * @version $Id: IndexedObject.java 4379 2008-07-11 02:21:18Z rakesh $
014     */
015    public class IndexedObject implements Serializable
016    {
017      private static final long serialVersionUID = 1l;
018    
019      /** The field that stores the class of the prevalent object. */
020      public final Class type;
021    
022      /** The field that stores the objectId of the prevalent object. */
023      public final Object objectId;
024    
025      /**
026       * Create a new instance of the value object with the specified values
027       * for the instance members.
028       *
029       * @param type The {@link IndexedObject#type}
030       *   value to use.
031       * @param objectId The {@link IndexedObject#objectId}
032       *   value to use.
033       */
034      protected IndexedObject( final Class type, final Object objectId )
035      {
036        this.type = type;
037        this.objectId = objectId;
038      }
039    
040      /**
041       * Getter for property {@link #type}.
042       *
043       * @return Value for property {@link #type}.
044       */
045      public Class getType()
046      {
047        return type;
048      }
049    
050      /**
051       * Getter for property {@link #objectId}.
052       *
053       * @return Value for property {@link #objectId}.
054       */
055      public Object getObjectId()
056      {
057        return objectId;
058      }
059    
060      /**
061       * Compare the specified object with this instance for equality.  The
062       * specified object is equal if its is of the same type and have
063       * equivalent members.
064       *
065       * @param object The object that is to be compared for equality.
066       * @return Returns <code>true</code> if the object is of the same type
067       *   and has equivalent fields.
068       */
069      public boolean equals( final Object object )
070      {
071        if ( this == object ) return true;
072        if ( object == null || getClass() != object.getClass() ) return false;
073    
074        IndexedObject that = (IndexedObject) object;
075    
076        if ( objectId != null ? !objectId.equals( that.objectId ) : that.objectId != null )
077        {
078          return false;
079        }
080        if ( type != null ? !type.equals( that.type ) : that.type != null )
081        {
082          return false;
083        }
084    
085        return true;
086      }
087    
088      /**
089       * Return a hash code for this instance.  Computes the hash code based
090       * upon the hash codes for the fields.
091       *
092       * @return The hash code for this object.
093       */
094      public int hashCode()
095      {
096        int result;
097        result = ( type != null ? type.hashCode() : 0 );
098        result = 31 * result + ( objectId != null ? objectId.hashCode() : 0 );
099        return result;
100      }
101    }