File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Groovy Fundamentals video training course this week in the Groovy 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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32077
    
207


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?



[OCA 8 book] [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: 15302
    
    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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32077
    
207

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

Joined: May 26, 2003
Posts: 32077
    
207

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"