title: Java 8 streams: find items from one list that match conditions calculated based on values from another list
body: <p>Have two classes and two corresponding lists:</p>
  
  <pre><code>class Click {
     long campaignId;
     Date date;
  }
  
  class Campaign {
     long campaignId;
     Date start;
     Date end;
     String type;
  }
  
  List&lt;Click&gt; clicks = ..;
  List&lt;Campaign&gt; campaigns = ..;
  </code></pre>
  
  <p>And want to find all <code>Click</code>s in <code>clicks</code> that:</p>
  
  <ol>
  <li><p>Have a corresponding <code>Campaign</code> in <code>campaigns</code> list, i.e., <code>Campaign</code> with the same <code>campaignId</code> AND</p></li>
  <li><p>This <code>Campaign</code> has <code>type</code> = "prospective" AND</p></li>
  <li><p>This <code>Campaigns.start</code> &lt; <code>click.date</code> &lt; <code>Campaigns.end</code></p></li>
  </ol>
  
  <p>So far I have the following implementation (which seems confusing and complex to me):</p>
  
  <pre><code>clicks.
          stream().
          filter(click -&gt; campaigns.stream().anyMatch(
                  campaign -&gt; campaign.getCampaignType().equals("prospecting") &amp;&amp;
                          campaign.getCampaignId().equals(click.getCampaignId()) &amp;&amp;
                          campaign.getStart().after(click.getDate()) &amp;&amp;
                          campaign.getEnd().before(click.getDate()))).
          collect(toList());
  </code></pre>
  
  <p>I wonder if there is simpler solution for the problem.</p>