title: Using collect in drools to get similar objects
body: <p>I am trying to collect some objects in Drools, but I want to only collect objects which have the same attribute. To wit, imagine a TestData class:</p>
  
  <pre><code>public class TestData {
      int number;
      String name;
      //Getters, setters, rest of class
  }
  </code></pre>
  
  <p>I want to use collect to get all TestDatas which have the same name. For the following data set, I want a rule which can collect the first two (both having the name 'Test1') and the second two ('Test2') as separate collections.</p>
  
  <pre><code>custom.package.TestData&lt; number: 1, name:'Test1' &gt;
  custom.package.TestData&lt; number: 2, name:'Test1' &gt;
  custom.package.TestData&lt; number: 3, name:'Test2' &gt;
  custom.package.TestData&lt; number: 4, name:'Test2' &gt;
  </code></pre>
  
  <p>Something like </p>
  
  <pre><code>rule "Test Rule"
      when
          $matchingTestDatas : ArrayList( size &gt; 1 ) from collect ( TestData( *magic* ) )
      then
          //Code
  end
  </code></pre>
  
  <p>But obviously that won't work without the magic- it gets me an array of all the TestData entries with every name. I can use that as the basis for a rule, and do extended processing in the right hand side iterating over all the test data entries, but it feels like there should be something in drools which is smart enough to match this way.</p>