vladimir 2002/11/19 01:21:09
Modified: java/src/org/apache/xindice/client/xmldb ResourceIteratorImpl.java Log: New version (with tests...) using an iterator. This fix the bug when you call getNext() if you're at the end of the list Revision Changes Path 1.4 +29 -24 xml-xindice/java/src/org/apache/xindice/client/xmldb/ResourceIteratorImpl.java Index: ResourceIteratorImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/ResourceIteratorImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ResourceIteratorImpl.java 31 Oct 2002 06:58:48 -0000 1.3 +++ ResourceIteratorImpl.java 19 Nov 2002 09:21:09 -0000 1.4 @@ -1,5 +1,3 @@ -package org.apache.xindice.client.xmldb; - /* * The Apache Software License, Version 1.1 * @@ -59,42 +57,49 @@ * $Id$ */ +package org.apache.xindice.client.xmldb; + import org.xmldb.api.base.ErrorCodes; import org.xmldb.api.base.Resource; import org.xmldb.api.base.ResourceIterator; import org.xmldb.api.base.XMLDBException; +import java.util.Iterator; import java.util.List; +/** + * An iterator over a collection of resources. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Vladimir R. Bossicard</a> + */ public class ResourceIteratorImpl implements ResourceIterator { - List resources = null; - int index = 0; - + + private Iterator iterator = null; + public ResourceIteratorImpl(List resources) { - this.resources = resources; + if (resources != null) { + this.iterator = resources.iterator(); + } } - - public boolean hasMoreResources () throws XMLDBException { - try { - if (resources.get(index) == null) { - return false; - } - - return true; + + public boolean hasMoreResources() + throws XMLDBException { + if (this.iterator != null) { + return this.iterator.hasNext(); } - catch (Exception e) { + else { return false; } } - public Resource nextResource () throws XMLDBException { - if (resources != null) { - Resource result = (Resource) resources.get(index); - index++; - return result; - } - else { - throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE); + public Resource nextResource() + throws XMLDBException { + if (this.iterator != null) { + if (this.iterator.hasNext()) { + return (Resource) iterator.next(); + } } + throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE); } + }