Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Peter Lawrey commented, this is almost certainly going to be simpler as nested loops. More over, the <a href="http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">Guava documentation</a> gives this warning:</p> <blockquote> <p>Imperative code should be your default, your first choice as of Java 7. You should not use functional idioms unless you are absolutely sure of one of the following:</p> <ul> <li>Use of functional idioms will result in net savings of lines of code for your entire project. Moving the definition of a function to another file, or a constant, does not help. </li> <li>For efficiency, you need a lazily computed view of the transformed collection and cannot settle for an explicitly computed collection. Additionally, you have read and reread Effective Java, item 55, and besides following those instructions, you have actually done benchmarking to prove that this version is faster, and can cite numbers to prove it. </li> </ul> <p>Please be sure, when using Guava's functional utilities, that the traditional imperative way of doing things isn't more readable. Try writing it out. Was that so bad? Was that more readable than the preposterously awkward functional approach you were about to try?</p> </blockquote> <p>However, if you're insistent on ignoring advice, you could use something like this monstrosity (note I haven't actually tried to compile or run this):</p> <pre><code>FluentIterable.from(continentList) .transform(new Function&lt;Continent, Void&gt;() { public Void apply(Continent continent) { return FluentIterable.from(continent.getCountries()) .transform(new Function&lt;Country, Void&gt;() { public Void apply(Country country) { return FluentIterable.from(country.getCities()) .transform(new Function&lt;City, Void&gt;() { public Void apply(City city) { // do stuff with city object return null; } }); } }); } }); </code></pre> <p>Now ask yourself: Which would you want to maintain? Which is going to be the most efficient?</p> <p>There are valid use-cases for Guava's functional idiom. Replacing Java for loops, even nested for loops, is not one of them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload