Jump to content









Photo

Listener If Expression, Context contains Key/Value

Listener Context Key Value

  • Please log in to reply
3 replies to this topic

#1 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 25 July 2013 - 12:16 PM

I have a Listener.  The If Expression is something like, "context.data.containsKey('unpacked')".  I'd rather like for some expression that is checking that unpacked = true or _t=str or _t=sta.  The .containsKey is only checking the key value.  

 

Is there a list of other methods that work with data so I can build an If Expression that looks check a key/value?

 

Thank you.



#2 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 25 July 2013 - 10:20 PM

Just to add a bit more, for those that might be checking.

 

An expression could be build with the method containsKey() or containsValue() to check for a specific key or a specific value among keys.  However, I's like, as I shown to have the express say, _t = 'str', which in and of itself works.  But, if the key may or may not be there, I only want to operate on if the key is there and is of a certain value.  So the key is unpacked.  The value is either true or false.  Unpacked may or may not be in the data set, and if it isn't there, it is assumed false.  I tried using unpacked = 'false' thinking that if the key wasn't there this would evaluate false, but that doesn't seem to be the case.



#3 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 103 posts
  • LocationMadrid, Spain.

Posted 26 July 2013 - 06:47 AM

Hi Zambiot!

 

I think that you can use context.data.get('unpacked') this return the value of key if exist or false if not exist.

 

You can learn more here: http://groovy.codehaus.org/Collections

 

Enjoy!



#4 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 26 July 2013 - 12:27 PM

Thank you!  That works and is exactly what I needed.  I am still trying to catchup on Groovy.







Also tagged with one or more of these keywords: Listener, Context, Key, Value

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users