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 TestCollatingIterator.java
Date Wed, 10 Jul 2002 14:06:39 GMT
rwaldhoff    2002/07/10 07:06:39

  Modified:    collections/src/java/org/apache/commons/collections
                        CollatingIterator.java
               collections/src/test/org/apache/commons/collections
                        TestCollatingIterator.java
  Log:
  add no-arg constructor
  fix method name
  add some javadoc comments
  
  Revision  Changes    Path
  1.2       +51 -6     jakarta-commons/collections/src/java/org/apache/commons/collections/CollatingIterator.java
  
  Index: CollatingIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollatingIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CollatingIterator.java	9 Jul 2002 16:48:56 -0000	1.1
  +++ CollatingIterator.java	10 Jul 2002 14:06:39 -0000	1.2
  @@ -80,13 +80,17 @@
   
       //------------------------------------------------------------ Constructors
       
  +    public CollatingIterator() {
  +        this(null,2);
  +    }
  +    
       public CollatingIterator(Comparator comp) {
           this(comp,2);
       }
       
       public CollatingIterator(Comparator comp, int initIterCapacity) {
           iterators = new ArrayList(initIterCapacity);
  -        comparator = comp;
  +        setComparator(comp);
       }
       
       public CollatingIterator(Comparator comp, Iterator a, Iterator b) {
  @@ -97,17 +101,28 @@
   
       //--------------------------------------------------------- Public Methods
   
  +    /**
  +     * Add the given {@link Iterator} to my collection to collate.
  +     * @throws IllegalStateException if I've already started iterating
  +     */
       public void addIterator(Iterator iter) throws IllegalStateException {
           checkNotStarted();
           iterators.add(iter);
       }
   
  +    /**
  +     * Set the {@link Comparator} by which I collate.
  +     * @throws IllegalStateException if I've already started iterating
  +     */
       public void setComparator(Comparator comp) throws IllegalStateException {
           checkNotStarted();
           comparator = comp;
       }
   
  -    public Comparator getIterator() {
  +    /**
  +     * Get the {@link Comparator} by which I collate.
  +     */
  +    public Comparator getComparator() {
           return comparator;
       }
   
  @@ -145,6 +160,7 @@
   
       //--------------------------------------------------------- Private Methods
   
  +    /** Initialize my collating state if it hasn't been already. */
       private void start() {
           if(null == values) {
               values = new ArrayList(iterators.size());
  @@ -156,6 +172,15 @@
           }
       }
   
  +    /** 
  +     * Set the {@link #values} and {@link #valueSet} attributes 
  +     * at position <i>i</i> to the next value of the 
  +     * {@link #iterators iterator} at position <i>i</i>, or 
  +     * clear them if the <i>i</i><sup>th</sup> iterator
  +     * has no next value.
  +     *
  +     * @return <tt>false</tt> iff there was no value to set
  +     */
       private boolean set(int i) {
           Iterator iter = (Iterator)(iterators.get(i));
           if(iter.hasNext()) {
  @@ -169,17 +194,29 @@
           }
       }
   
  +    /** 
  +     * Clear the {@link #values} and {@link #valueSet} attributes 
  +     * at position <i>i</i>.
  +     */
       private void clear(int i) {
           values.set(i,null);
           valueSet.clear(i);
       }
   
  +    /** 
  +     * Throw {@link IllegalStateException} iff I've been {@link #start started}.
  +     * @throws IllegalStateException iff I've been {@link #start started}
  +     */
       private void checkNotStarted() throws IllegalStateException {
           if(null != values) {
               throw new IllegalStateException("Can't do that after next or hasNext has been
called.");
           }
       }
   
  +    /** 
  +     * Returns the index of the least element in {@link #values},
  +     * {@link #set(int) setting} any uninitialized values.
  +     */
       private int least() throws IllegalStateException {
           int leastIndex = -1;
           Object leastObject = null;                
  @@ -203,6 +240,10 @@
           return leastIndex;
       }
   
  +    /**
  +     * Returns <code>true</code> iff any bit in the given set is 
  +     * <code>true</code>.
  +     */
       private boolean anyValueSet(BitSet set) {
           for(int i=0;i<set.size();i++) {
               if(set.get(i)) {
  @@ -212,6 +253,10 @@
           return false;
       }
   
  +    /**
  +     * Returns <code>true</code> iff any {@link Iterator} 
  +     * in the given list has a next value.
  +     */
       private boolean anyHasNext(ArrayList iters) {
           for(int i=0;i<iters.size();i++) {
               Iterator iter = (Iterator)iters.get(i);
  
  
  
  1.2       +15 -10    jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollatingIterator.java
  
  Index: TestCollatingIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollatingIterator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCollatingIterator.java	9 Jul 2002 16:48:56 -0000	1.1
  +++ TestCollatingIterator.java	10 Jul 2002 14:06:39 -0000	1.2
  @@ -138,6 +138,15 @@
   
       //------------------------------------------------------------------- Tests
   
  +    public void testGetSetComparator() {
  +        CollatingIterator iter = new CollatingIterator();
  +        assertNull(iter.getComparator());
  +        iter.setComparator(comparator);
  +        assertSame(comparator,iter.getComparator());
  +        iter.setComparator(null);
  +        assertNull(iter.getComparator());
  +    }
  +
       public void testIterateEven() {
           CollatingIterator iter = new CollatingIterator(comparator);
           iter.addIterator(evens.iterator());
  @@ -149,9 +158,7 @@
       }
   
       public void testIterateEvenOdd() {
  -        CollatingIterator iter = new CollatingIterator(comparator);
  -        iter.addIterator(evens.iterator());
  -        iter.addIterator(odds.iterator());
  +        CollatingIterator iter = new CollatingIterator(comparator,evens.iterator(),odds.iterator());
           for(int i=0;i<20;i++) {
               assertTrue(iter.hasNext());
               assertEquals(new Integer(i),iter.next());
  @@ -160,9 +167,7 @@
       }
   
       public void testIterateOddEven() {
  -        CollatingIterator iter = new CollatingIterator(comparator);
  -        iter.addIterator(odds.iterator());
  -        iter.addIterator(evens.iterator());
  +        CollatingIterator iter = new CollatingIterator(comparator,odds.iterator(),evens.iterator());
           for(int i=0;i<20;i++) {
               assertTrue(iter.hasNext());
               assertEquals(new Integer(i),iter.next());
  
  
  

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