You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by ji...@respublica.fr on 2001/06/01 21:02:03 UTC

Re: iterator() && #foreach

This discussion is interesting
Don't you think we are ending up with too many fallbacks here?
There is the Iterator class, the Collection interface (not needed any 
more when we have the next one:), iterator() public method and single 
item iterator.

Can we get rid of the single item iterator?

We could provide a wrapper (like SingleItemIterator) to decide whether 
we want the object to be singled

Or if we want all objects of a class to be used as a single iterator, it 
would be only the matter of adding the method to the class:

   public Iterator iterator()
   {
       return new SingleItemIterator(this);
   }

The benefits of *not* creating automatically a new SingleItemIterator in 
the default case is that one can easily _add_ the iterating on a single 
object, but it is more difficult to _remove_ the iterator() method if we 
want to treat a collection as a single object (maybe with a wrapper?...)

My 2c


-- Denis.

On Monday, May 21, 2001, at 02:18  am, Geir Magnusson Jr. wrote:

>
>> We could make the getIterator() portion of Foreach pluggable.
>> maybe, and then allow folks to install whatever kind of iterator
>> fetcher that they want.  ie, our personal default: case would
>> be to create a new SingleItemIterator( listObj ) if that's what
>> we wanted.
>>
>> Though, not this week. ;)
>
> No. :)  However, I do sort-of believe that limiting the options here is
> a good idea - adding the single item iterator (if the search for
> supported iterators fails...), and having the .iterator() should really
> cover all the bases.
>
> What is added if it's pluggable?  We still would have to agree on what
> it would have to return to velocity so vel could iterate, and Iterator
> is a darn fine solution.  Therefore, if you have support for a  public
> Iterator iterator(), what would you need anything else for?
>
> In other words, if we do a pluggable, we would maybe decide that the
> pluggable interface thingy must return an Iterator to velocity...
>
> geir
>
>
>>         -bob
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> "still climbing up to the shoulders..."
>