commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/primitives TestIntList.java
Date Fri, 10 Jan 2003 21:13:20 GMT
rwaldhoff    2003/01/10 13:13:19

  Modified:    collections/src/java/org/apache/commons/collections/primitives
                        IntList.java
               collections/src/test/org/apache/commons/collections/primitives
                        TestIntList.java
  Log:
  document IntList.equals and IntList.hashCode contracts
  add test ensuring proper implementation of IntList.hashCode
  
  Revision  Changes    Path
  1.8       +38 -3     jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntList.java
  
  Index: IntList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntList.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IntList.java	10 Jan 2003 19:24:10 -0000	1.7
  +++ IntList.java	10 Jan 2003 21:13:19 -0000	1.8
  @@ -108,6 +108,23 @@
        */
       boolean addAll(int index, IntCollection collection);
       
  +    /**
  +     * Returns <code>true</code> iff <i>that</i> is an <code>IntList</code>
  +     * that contains the same elements in the same order as me.
  +     * In other words, returns <code>true</code> iff <i>that</i>
is
  +     * an <code>IntList</code> that has the same {@link #size} as me,
  +     * and for which the elements returned that its 
  +     * {@link IntList#iterator iterator} are equal (<code>==</code>) to
  +     * the corresponding elements within me.
  +     * (This contract ensures that this method works properly across 
  +     * different implementations of the <code>IntList</code> interface.
  +     * 
  +     * @param that the object to compare to me
  +     * @return <code>true</code> iff <i>that</i> is an <code>IntList</code>
  +     *         that contains the same elements in the same order as me
  +     */
  +    boolean equals(Object that);
  +    
       /** 
        * Returns the element at the specified position within 
        * me. 
  @@ -117,7 +134,25 @@
        * @throws IndexOutOfBoundsException if the specified index is out of range
        */
       int get(int index);
  -    
  +        
  +    /**
  +     * Returns my hash code.
  +     * <p>
  +     * The hash code of an <code>IntList</code> is defined to be the
  +     * result of the following calculation:
  +     * <pre>int hash = 1;
  +     * for(IntIterator iter = iterator(); iter.hasNext(); ) {
  +     *   hash = 31*hash + iter.next();
  +     * }</pre>
  +     * <p>
  +     * This contract ensures that this method is consistent with 
  +     * {@link #equals} and with the {@link java.util.List#hashCode hashCode}
  +     * method of a {@link java.util.List List} of {@link Integer}s. 
  +     * 
  +     * @return my hash code
  +     */
  +    int hashCode();
  +
       /** 
        * Returns the index of the first occurrence 
        * of the specified element within me, 
  
  
  
  1.2       +11 -2     jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java
  
  Index: TestIntList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestIntList.java	10 Jan 2003 13:27:55 -0000	1.1
  +++ TestIntList.java	10 Jan 2003 21:13:19 -0000	1.2
  @@ -140,6 +140,15 @@
       // tests
       // ------------------------------------------------------------------------
   
  +    public void testHashCodeSpecification() {
  +        IntList list = makeFullIntList();
  +        int hash = 1;
  +        for(IntIterator iter = list.iterator(); iter.hasNext(); ) {
  +            hash = 31*hash + iter.next();
  +        }
  +        assertEquals(hash,list.hashCode());
  +    }
  +
       public void testEqualsWithTwoIntLists() {
           IntList one = makeEmptyIntList();
           assertEquals("Equals is reflexive on empty list",one,one);
  
  
  

--
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