Felix Knecht wrote:
> Hi all
>
> I have found at different locations [1] an implementation (more or less
> similar) for an EmptyIterator, e.g.
>
> static class EmptyIterator implements Iterator {
> public boolean hasNext() { return false; }
> public Object next() { return null; }
> public void remove() {}
> }
>
> Many of them are lacking the same problem:
> Iterator next() [2] method says to throws an exception when there are no more
> elements to return (what would be the case
> here). In fact null is returned instead of an error.
>
> Is this done this way on purpose?
No, it's a mistake - I never read the java docs correctly :(
So it should throw an exception.
Carsten
>
> Implementing in a way like
> static class EmptyIterator implements Iterator {
> public boolean hasNext() { return false; }
> public Object next() { throw new NoSuchElementException(); }
> public void remove() {}
> }
>
> will at least make
> testJXForEach(org.apache.cocoon.template.jxtg.JXTemplateGeneratorTestCase)
> failing.
> It's (ForEach) implementation of the EmtpyIter looks even less logical
>
> protected static final Iterator NULL_ITER = new Iterator() {
> public boolean hasNext() {
> return true;
> }
> public Object next() {
> return null;
> }
> public void remove() {
> // EMPTY
> }
> };
>
> Why does a NULL_ITER returns 'true' when calling hasNext()?
>
> Maybe Carsten (commit 568847) or Grzegorz can have/give some more information?
>
> Felix
>
>
> [1] org.apache.cocoon.components.source.impl.BlobSource
> org.apache.cocoon.el.impl.AbstractExpression
> org.apache.cocoon.template.expression.JXTExpression
> org.apache.cocoon.template.instruction.ForEach
>
> [2] http://java.sun.com/j2se/1.4.2/docs/api/java/util/Iterator.html#next()
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Iterator.html#next()
>
--
Carsten Ziegeler
[EMAIL PROTECTED]