You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2002/12/08 22:22:08 UTC

cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang/builder HashCodeBuilder.java

scolebourne    2002/12/08 13:22:07

  Modified:    lang/src/java/org/apache/commons/lang/builder
                        HashCodeBuilder.java
  Log:
  Add ability to build compound hashCode using superclass
  
  Revision  Changes    Path
  1.6       +17 -2     jakarta-commons/lang/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java
  
  Index: HashCodeBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HashCodeBuilder.java	17 Nov 2002 21:46:42 -0000	1.5
  +++ HashCodeBuilder.java	8 Dec 2002 21:22:07 -0000	1.6
  @@ -80,7 +80,7 @@
    *   public int hashCode() {
    *     // you pick a hard-coded, randomly chosen, non-zero, odd number
    *     // ideally different for each class
  - *     return new HashCodeBuilder(17, 37).   
  + *     return new HashCodeBuilder(17, 37).
    *       append(name).
    *       append(age).
    *       append(smoker).
  @@ -88,6 +88,8 @@
    *   }
    * }
    * </pre>
  + * 
  + * <p>If required, the superclass hashCode can be added using {@link #appendSuper}.</p>
    *
    * <p>Alternatively, there is a method that uses reflection to determine
    * the fields to test. Because these fields are usually private, the method, 
  @@ -295,6 +297,19 @@
           return hashCodeBuilder.toHashCode();
       }
   
  +    //-------------------------------------------------------------------------
  +    
  +    /**
  +     * <p>Adds the result of super.hashCode() to this builder.</p>
  +     *
  +     * @param superHashCode  the result of calling <code>super.hashCode()</code>
  +     * @return this HashCodeBuilder, used to chain calls.
  +     */
  +    public HashCodeBuilder appendSuper(int superHashCode) {
  +        iTotal = iTotal * iConstant + superHashCode;
  +        return this;
  +    }
  +    
       //-------------------------------------------------------------------------
       
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>