/*
 * Test.java
 *
 * Created on October 17, 2002, 2:52 PM
 *
 * Copyright (c) 2002, CreditTrade Ltd.
 */

package com.credittrade;

import org.apache.ojb.broker.accesslayer.*;

import org.apache.log4j.Logger;

import java.util.*;
/**
 *
 * @author  RowellM
 * @version 1.0
 */
public class Test {
    private static final Logger log = Logger.getLogger(Test.class);
    
    /**
     * Creates a new default instance of Test
     */
    public Test() {
    }
    
    public static void main(String[] args) throws Exception {
        
        // Create 3 instances of MyOJBIterator the middle one with an empty collection
        
        
        ArrayList allIterators = new ArrayList();
        ArrayList one = new ArrayList();
        one.add("a");
        one.add("b");
        one.add("c");
        allIterators.add( new MyOJBIterator(one));
        
        ArrayList two = new ArrayList();
        allIterators.add( new MyOJBIterator(two));
        
        ArrayList three = new ArrayList();
        three.add("d");
        three.add("e");
        three.add("f");
        allIterators.add( new MyOJBIterator(three));
        
        // Now step through chain
        ChainingIterator chain = new ChainingIterator(allIterators);
        while ( chain.hasNext() ) {
            System.out.println(chain.next());
        }
        
    }
    
    static class MyOJBIterator implements OJBIterator {
        
        private Iterator iter;
        private Collection coll;
        
        public MyOJBIterator( Collection coll ) {
            this.coll = coll;
            this.iter =coll.iterator();
        }
        public boolean absolute(int param) throws org.apache.ojb.broker.PersistenceBrokerException {
            return false;
        }
        
        /** Returns <tt>true</tt> if the iteration has more elements. (In other
         * words, returns <tt>true</tt> if <tt>next</tt> would return an element
         * rather than throwing an exception.)
         *
         * @return <tt>true</tt> if the iterator has more elements.
         */
        public boolean hasNext() {
            return iter.hasNext();
        }
        
        /** Returns the next element in the iteration.
         *
         * @return the next element in the iteration.
         * @exception NoSuchElementException iteration has no more elements.
         */
        public Object next() {
            return iter.next();
        }
        
        public boolean relative(int param) throws java.sql.SQLException {
            return false;
        }
        
        public void releaseDbResources() {
        }
        
        /**
         * Removes from the underlying collection the last element returned by the
         * iterator (optional operation).  This method can be called only once per
         * call to <tt>next</tt>.  The behavior of an iterator is unspecified if
         * the underlying collection is modified while the iteration is in
         * progress in any way other than by calling this method.
         *
         * @exception UnsupportedOperationException if the <tt>remove</tt>
         * 		  operation is not supported by this Iterator.
         *
         * @exception IllegalStateException if the <tt>next</tt> method has not
         * 		  yet been called, or the <tt>remove</tt> method has already
         * 		  been called after the last call to the <tt>next</tt>
         * 		  method.
         */
        public void remove() {
            
        }
        
        public int size() throws org.apache.ojb.broker.PersistenceBrokerException {
            return coll.size();
        }
        
    }
    
}

