[stringtemplate-interest] Maps with object keys

Caleb Lyness caleb.lyness at ezswitch.net
Wed Nov 28 02:12:50 PST 2007


Terence Parr wrote:
> Hi Caleb! :)
>
> Heh, yeah, you're right...this is weird, though consistent with what  
> (x) means..(x) means "take the value of" or "immediately eval" rather  
> than lazy eval.  Sometimes you need to render an expression such as  
> for keys with maps.  It's an indirection and immediate eval.
>
> m.x gives m.get("x")
> m.(x) gives m.get(x.toString())
> m.(x+"foo") gives m.get(x + "foo")
>
> hmm...we do need a map look up with an object...i wonder what to do...
>   
Well as a step toward resolving the problem have a look at the attached 
test case.
Perhaps you would like to add it to TestStringTemplate and create an 
issue report
for the problem?

Cheers
     Caleb
> Ter
>
> On Nov 23, 2007, at 3:34 AM, Caleb Lyness wrote:
>
>   
>> Hi all,
>>
>> I have not been keeping up to date with my string template mails...  
>> perhaps this has been covered before, just point me at the thread  
>> if already covered...
>> This is also being tested against ST-3.0.
>>
>> Here is a segment of a test template:
>>
>>   $products: {product |
>>   <tr>
>>      <td>$product$</td>
>>      <td>$report.productReadStats.(product);null="0"$</td>
>>      <td>$report.productActivationsStats.(product);null="0"$</td>
>>      <td>$report.productIssuedStats.(product);null="0"$</td>
>>   </tr>}$
>>
>> On the model side I had:
>>
>> public HashMap<Product, Integer> productReadStats = new  
>> HashMap<Product, Integer>();
>> public HashMap<Product, Integer> productIssuedStats = new  
>> HashMap<Product, Integer>();
>> public HashMap<Product, Integer> productActivationsStats = new  
>> HashMap<Product, Integer>();
>>
>> String template would always report the stats as 0 (via the null  
>> setting). My guess from what I am seeing
>> is that ST-3.0 is dereferencing (product) to a string and not an  
>> object. When looking up the value in the
>> map the string does not result in the correct map reference.
>>
>> Changing my map to a string based key:
>>
>> public HashMap<String, Integer> productReadStats = new  
>> HashMap<String, Integer>();
>> ... etc ...
>>
>> resulted in the correct values.
>>
>> Is this a known problem/limitation? Or is this considered the  
>> correct behaviour. Surely an attempt should be
>> made to lookup the object directly and then use the object.toString 
>> () as the key as a 2nd attempt?
>>
>> Cheers
>>       Caleb.
>>
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>>     
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071128/4f851ab6/attachment.html 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.java
Url: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071128/4f851ab6/attachment.pl 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3269 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071128/4f851ab6/attachment.bin 


More information about the stringtemplate-interest mailing list