title: How to dynamically do filtering in Java 8?
body: <p>I know in Java 8, I can do filtering like this :</p>
  
  <pre><code>List&lt;User&gt; olderUsers = users.stream().filter(u -&gt; u.age &gt; 30).collect(Collectors.toList());
  </code></pre>
  
  <p>But what if I have a collection and half a dozen filtering criteria, and I want to test the combination of the criteria ?</p>
  
  <p>For example I have a collection of objects and the following criteria : </p>
  
  <pre><code>&lt;1&gt; Size
  &lt;2&gt; Weight
  &lt;3&gt; Length
  &lt;4&gt; Top 50% by a certain order
  &lt;5&gt; Top 20% by a another certain ratio
  &lt;6&gt; True or false by yet another criteria
  </code></pre>
  
  <p>And I want to test the combination of the above criteria, something like :</p>
  
  <pre><code>&lt;1&gt; -&gt; &lt;2&gt; -&gt; &lt;3&gt; -&gt; &lt;4&gt; -&gt; &lt;5&gt;
  &lt;1&gt; -&gt; &lt;2&gt; -&gt; &lt;3&gt; -&gt; &lt;5&gt; -&gt; &lt;4&gt;
  &lt;1&gt; -&gt; &lt;2&gt; -&gt; &lt;5&gt; -&gt; &lt;4&gt; -&gt; &lt;3&gt;
  ...
  &lt;1&gt; -&gt; &lt;5&gt; -&gt; &lt;3&gt; -&gt; &lt;4&gt; -&gt; &lt;2&gt;
  &lt;3&gt; -&gt; &lt;2&gt; -&gt; &lt;1&gt; -&gt; &lt;4&gt; -&gt; &lt;5&gt;
  ...
  &lt;5&gt; -&gt; &lt;4&gt; -&gt; &lt;3&gt; -&gt; &lt;3&gt; -&gt; &lt;1&gt;
  </code></pre>
  
  <p>If each testing order may give me different results, how to write a loop to automatically filter through all the combinations ?</p>
  
  <p>What I can think of is to use another method that generates the testing order like the following :</p>
  
  <pre><code>int[][] getTestOrder(int criteriaCount)
  {
   ...
  }
  
  So if the criteriaCount is 2, it will return : {{1,2},{2,1}}
  If the criteriaCount is 3, it will return : {{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}}
  ...
  </code></pre>
  
  <p>But then how to most efficiently implement it with the filtering mechanism in concise expressions that comes with Java 8 ?</p>