001    package edu.nrao.sss.util;
002    
003    /**
004     * An enumeration of the ways that two objects may be compared for equality.
005     * <p>
006     * <b>CVS Info:</b>
007     * <table style="margin-left:2em">
008     *   <tr><td>$Revision: 161 $</td></tr>
009     *   <tr><td>$Date: 2006-12-15 11:48:34 -0700 (Fri, 15 Dec 2006) $</td></tr>
010     *   <tr><td>$Author: btruitt $</td></tr>
011     * </table></p>
012     * 
013     * @author David M. Harland
014     * @since 2006-12-01
015     */
016    public enum EqualityMethod
017    {
018      /**
019       * Indicates that objects should be compared by reference, that is by
020       * the {@code ==} operator.
021       */
022      REFERENCE
023      {
024        public boolean deemsObjectsEqual(Object o1, Object o2)
025        {
026          return o1 == o2;
027        }
028      },
029      
030      /**
031       * Indicates that objects should be compared by value, that is by
032       * the {@code equals} method.
033       */
034      VALUE
035      {
036        public boolean deemsObjectsEqual(Object o1, Object o2)
037        {
038          if (REFERENCE.deemsObjectsEqual(o1, o2))
039            return true;
040          
041          //Both cannot be null if we get this far, but one, the other, or none c/b
042          if (o1 == null || o2 == null)
043            return false;
044          
045          //Neither is null
046          return o1.equals(o2);
047        }
048      };
049      
050      /**
051       * Returns <i>true</i> if {@code o1} is equal to {@code o2} according to the
052       * rules of this element.
053       * @param o1 an object to be compared to another for equality.
054       * @param o2 an object to be compared to another for equality.
055       * @return <i>true</i> if {@code o1} is equal to {@code o2}.
056       */
057      public abstract boolean deemsObjectsEqual(Object o1, Object o2);
058    }