commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang/builder CompareToBuilderTest.java
Date Sun, 08 Dec 2002 21:43:34 GMT
scolebourne    2002/12/08 13:43:34

  Modified:    lang/src/java/org/apache/commons/lang/builder
                        CompareToBuilder.java
               lang/src/test/org/apache/commons/lang/builder
                        CompareToBuilderTest.java
  Log:
  Add support for calling superclass compareTo
  
  Revision  Changes    Path
  1.7       +19 -2     jakarta-commons/lang/src/java/org/apache/commons/lang/builder/CompareToBuilder.java
  
  Index: CompareToBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/builder/CompareToBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CompareToBuilder.java	8 Dec 2002 21:38:19 -0000	1.6
  +++ CompareToBuilder.java	8 Dec 2002 21:43:34 -0000	1.7
  @@ -83,9 +83,10 @@
    *  public int comapareTo(Object o) {
    *    MyClass rhs = (MyClass) o;
    *    return new CompareToBuilder()
  + *                 .appendSuper(super.compareTo(o)
    *                 .append(field1, rhs.field1)
    *                 .append(field2, rhs.field2)
  - *                 .appendb(field3, rhs.field3)
  + *                 .append(field3, rhs.field3)
    *                 .toComparison();
    *  }
    * </pre>
  @@ -212,6 +213,22 @@
           return compareToBuilder.toComparison();
       }
   
  +    //-------------------------------------------------------------------------
  +    
  +    /**
  +     * <p>Adds the result of super.hashCode() to this builder.</p>
  +     *
  +     * @param superHashCode  the result of calling <code>super.equals()</code>
  +     * @return CompareToBuilder - used to chain calls.
  +     */
  +    public CompareToBuilder appendSuper(int superHashCode) {
  +        if (comparison != 0) {
  +            return this;
  +        }
  +        comparison = superHashCode;
  +        return this;
  +    }
  +    
       //-------------------------------------------------------------------------
       
       /**
  
  
  
  1.3       +15 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/builder/CompareToBuilderTest.java
  
  Index: CompareToBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/builder/CompareToBuilderTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompareToBuilderTest.java	8 Dec 2002 21:37:25 -0000	1.2
  +++ CompareToBuilderTest.java	8 Dec 2002 21:43:34 -0000	1.3
  @@ -149,6 +149,20 @@
           } catch (ClassCastException ex) {}
       }
   
  +    public void testAppendSuper() {
  +        TestObject o1 = new TestObject(4);
  +        TestObject o2 = new TestObject(5);
  +        assertTrue(new CompareToBuilder().appendSuper(0).append(o1, o1).toComparison()
== 0);
  +        assertTrue(new CompareToBuilder().appendSuper(0).append(o1, o2).toComparison()
< 0);
  +        assertTrue(new CompareToBuilder().appendSuper(0).append(o2, o1).toComparison()
> 0);
  +        
  +        assertTrue(new CompareToBuilder().appendSuper(-1).append(o1, o1).toComparison()
< 0);
  +        assertTrue(new CompareToBuilder().appendSuper(-1).append(o1, o2).toComparison()
< 0);
  +        
  +        assertTrue(new CompareToBuilder().appendSuper(1).append(o1, o1).toComparison()
> 0);
  +        assertTrue(new CompareToBuilder().appendSuper(1).append(o1, o2).toComparison()
> 0);
  +    }
  +    
       public void testObject() {
           TestObject o1 = new TestObject(4);
           TestObject o2 = new TestObject(4);
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message