struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Boyko" <abo...@fabgear.com>
Subject RE: PATCH: taglib/form/OptionsTag - Map support
Date Wed, 15 Nov 2000 15:53:11 GMT
> Currently, the patch allows the mixing of Map and non Map entries
> since the if statement is inside the while. Is that what you intended ?
>
> Pulling the if outside the while would make the type checking 'instanceof'
> a one time overhead, instead of for each iteration.

True.  Sort of.  The type of the collection is buried in the
getIterator() function; without changing more code than I was
comfortable doing at 2AM, there's not a good way to determine
the type of the collection from its iterator until you
start iterating.

But, yes, the right answer would be to set an isMap flag
when getting the iterator, so we could skip the instanceof
here.  I'll do that soon.

Andy Boyko   aboyko@fabgear.com


> >         while (valuesIterator.hasNext()) {
> > -           String value = (String) valuesIterator.next();
> > -           String label = value;
> > -           if (labelsIterator.hasNext())
> > -               label = (String) labelsIterator.next();
> > +
> > +            Object next = valuesIterator.next();
> > +
> > +            String label, value;
> > +            if ( next instanceof Map.Entry ) {
> > +                Map.Entry entry = (Map.Entry) next;
> > +                value = (String) entry.getKey();
> > +                label = (String) entry.getValue();
> > +            } else {
> > +               value = (String) next;
> > +               label = value;
> > +               if (labelsIterator.hasNext())
> > +                   label = (String) labelsIterator.next();
> > +            }
>
> --
> Robert Leland			Robert@free2create.org
> 804 N. Kenmore Street		+01-703-525-3580
> Arlington VA 22201
>
>


Mime
View raw message