dgraham     2003/07/02 20:08:44

  Modified:    src/share/org/apache/struts/util LabelValueBean.java
  Log:
  Added equals and hashCode() methods for PR# 20707.
  
  Revision  Changes    Path
  1.5       +38 -4     
jakarta-struts/src/share/org/apache/struts/util/LabelValueBean.java
  
  Index: LabelValueBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/LabelValueBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LabelValueBean.java       2 Jul 2003 04:34:24 -0000       1.4
  +++ LabelValueBean.java       3 Jul 2003 03:08:44 -0000       1.5
  @@ -71,6 +71,7 @@
    *
    * @author  Craig R. McClanahan
    * @author  Martin F N Cooper
  + * @author David Graham
    * @version $Revision$ $Date$
    */
   public class LabelValueBean implements Serializable {
  @@ -144,5 +145,38 @@
           return (sb.toString());
       }
   
  +    /**
  +     * LabelValueBeans are equal if their values are both null or equal.
  +     * @see java.lang.Object#equals(java.lang.Object)
  +     */
  +    public boolean equals(Object obj) {
  +        if (obj == this) {
  +            return true;
  +        }
  +
  +        if (!(obj instanceof LabelValueBean)) {
  +            return false;
  +        }
  +
  +        LabelValueBean bean = (LabelValueBean) obj;
  +        int nil = (this.getValue() == null) ? 1 : 0;
  +        nil += (bean.getValue() == null) ? 1 : 0;
  +
  +        if (nil == 2) {
  +            return true;
  +        } else if (nil == 1) {
  +            return false;
  +        } else {
  +            return this.getValue().equals(bean.getValue());
  +        }
  +
  +    }
   
  +    /**
  +     * The hash code is based on the object's value.
  +     * @see java.lang.Object#hashCode()
  +     */
  +    public int hashCode() {
  +        return (getValue() == null) ? super.hashCode() : getValue().hashCode();
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to