wood burning stoves 2.0*
The moose likes Groovy and the fly likes how do i make this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "how do i make this "more groovy"" Watch "how do i make this "more groovy"" New topic
Forums: Functional Programming Groovy
Author

how do i make this "more groovy"

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150


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?



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Thanks Gregg. That was what I was looking for.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

I made one slight adaptation. Greg's example printed out a bunch of lines with null on them. I changed it to:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i make this "more groovy"
 
Similar Threads
Some Groovy vs Python observations.
Help with Loops
JTextField does not refresh
Help with Iterating through objects to draw on panel
Implications....