title: Compare two custom objects in java with nullable fields
body: <p>I have a <code>Collection&lt;A&gt;</code></p>
  
  <pre><code>class A {
      String name;
      Long id;
  }
  </code></pre>
  
  <p>Now I have UI screen where I can provide name &amp; id value to match this collection and display the result.</p>
  
  <p>Now I have 3 criteria:</p>
  
  <ol>
  <li>Only Id provided: Display all the records matchs with Id although name is null</li>
  <li>Only name</li>
  <li>Both Name and Id.</li>
  </ol>
  
  <p>I can do it by three <code>if</code> check-based on null check of UI fields but I don't want to make <code>if-else</code> block because if I have multiple UI fileds it would be hectic to do nested <code>if-else</code> check.</p>
  
  <p>Please suggest a better way in java 7.</p>