title: Groovy filter criteria on findAll on a list
body: <p>I trying to build dynamic filters using findAll on a list. I have a variable that needs to be included in the filter only if not null. </p>
  
  <pre><code> @Test
      void testSample(){
          def list = [ new Employee(age:22, isManager:false), 
                       new Employee(age:23, isManager:true), 
                       new Employee(age:22, isManager:true) ] as Set
  
          def var = 22;
          String query1 = "it.age == var &amp;&amp; it.isManager == true "
          String query2 = "it.isManager == true"
  
          println list
          println list.findAll { var ? query1 : query2 } // Should give 1 record age = 22 and manager
          var = null;
          println list.findAll { var ? query1 : query2 } // should give 2 records-only manager
  
      }
  </code></pre>
  
  <p>Both of them giving all the records. Is there anyway I can achieve this in one condition without need to write muiltiple queries ?</p>
  
  <p>Looking some like below (this doesn't work though)</p>
  
  <pre><code>println list.findAll{
                  if(var) it.age == var &amp;&amp;
                  it.isManager == true
          }
  </code></pre>