[rules-users] Trouble with the MVEL Map syntax
Wolfgang Laun
wolfgang.laun at gmail.com
Wed Mar 21 03:14:38 EDT 2012
See below.
On 21/03/2012, barnesjd <barnesjd+nabble at gmail.com> wrote:
> I'm interested in using the
> http://mvel.codehaus.org/Inline+List,+Maps+and+Arrays compact syntax
> available for Maps in MVEL , but I can't quite get it right. I am
> attempting to write a simple function to convert English numbers (i.e.
> "one", "two", etc) to the integer value. This is how I would LIKE it to
> work:
>
> /function int englishToInt(String englishNumber)
> {
> return ["one":1, "two":2, "three":3, "four":4,
> "five":5].get(englishNumber.toLowerCase());
> }/
>
> The closest I've gotten to having it work is this:
>
> /function int englishToInt(String englishNumber)
> {
> Map m = ["one":1, "two":2, "three":3, "four":4, "five":5];
> Object obj = m.get(englishNumber.toLowerCase());
>
> if(obj != null)
> return Integer.parseInt(obj.toString());
> }/
>
> But I get this rather unhelpful error message:
> /
> Error importing : 'defaultpkg.EnglishToInt.englishToInt'
> [ function englishToIntenglishToInt (line:7): Syntax error on tokens, delete
> these tokens
> ]/
>
> ... What tokens?? lol
The given line is the one with "function int..." - so delete all of it :)
When using MVEL like this, inserting
dialect "mvel"
up front helps a lot.
-W
>
> Thanks,
> Joe
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Trouble-with-the-MVEL-Map-syntax-tp3844609p3844609.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list