[stringtemplate-interest] Iterating over a map

Terence Parr parrt at cs.usfca.edu
Tue May 3 09:11:00 PDT 2005


On Apr 19, 2005, at 2:21 PM, Tom Bentley wrote:
>> No, you are right!  The only problem is that I'd have to create a 
>> "temp" object with fields key/value for each iteration.  I guess 
>> that's not so bad...I like it!  Ok, i'm putting on my to do list!
>
> I have some working code, if you're interested.
>
> I basically used entrySet() rather than values() in 
> ASTExpr.convertAnythingIterableToIterator(), this means iterator 
> expressions are now iterating over Map.Entrys, which thankfully have 
> getKey() and getValue(), so everything behaves as you might expect.
>
> There is a snag though: The implementation of Map.Entry (for a HashMap 
> at least) is not a public class, so you can't invoke the getKey() and 
> getValue() method using reflection because the method is not 
> accessible. I found this quite surprising. I had to write an extra 
> method to make a public method declared by a public interface, but 
> implemented by a non-public class accessible. [Sorry, this was maybe 
> more detail than you wanted to know ;-)]

Hi Tom.  Yeah, that's why i was thinking we'd need that temp object.  I 
don't like having to assume something is a map, but i already break 
this rule by allowing object.property ;)

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com



More information about the stringtemplate-interest mailing list