Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i make this "more groovy"

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wrote a Groovy script. I'm finally in the habit of using each() instead of a for loop and grep() instead of an if statement (for filtering.)

I'm not sure what to do with this if statement through. This code is supposed to loop through all the p's and print out objects that don't have any q's of the right type with a value set. I had to use a helper variable because I couldn't figure out how to do this the Groovy way. Ideas?

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is really groovier, but I might do something like this:



This also assumes that p has a toString() that would return its name.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gregg. That was what I was looking for.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made one slight adaptation. Greg's example printed out a bunch of lines with null on them. I changed it to:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic