title: How to reduce if condition's?
body: <p>I am developing a module in which there are 10 filters, on which a user can filter data shown in grid.
  Lets assume data is of team in a company in which there are 10 members and each person is given a task to do work. All the members of the team add those task in that module and submit it to their superiors telling them that they have done this work, on this date, in that much of time etc.</p>
  
  <p>And their superiors can have a look at these submissions as number of task is more in number they need few filter conditions to filter out data. For example, they might want to see only x-person task or what he has done, or in last 2 days, what task are submitted to them by person-y etc.</p>
  
  <p>All the filters are optional and <strong>none</strong> is applied when the page load and displays data first time.</p>
  
  <p>As the user add filters, the data gets filtered. But here is the <strong>problem - Managing these filters and adding new filters as requirement change has been very trouble some for me.</strong>
  Due to <strong>large</strong> number of <strong>IF Statements</strong>.</p>
  
  <p>At present my code something like this</p>
  
  <pre><code>if ((strIdList != null &amp;&amp; !strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty()) &amp;&amp; (lastModifiedDateTime == null || lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskIdQuery + " and " + taskStatusQuery;
              }
              if ((strIdList != null &amp;&amp; !strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty()) &amp;&amp; (lastModifiedDateTime != null &amp;&amp; !lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskIdQuery + " and " + lastModified + " and " + taskStatusQuery;
              }
              if ((strIdList == null || strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty()) &amp;&amp; (lastModifiedDateTime != null &amp;&amp; !lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + lastModified + " and " + taskStatusQuery;
              }
              if (strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; (strIdList == null || strIdList.isEmpty()) &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty())) {
                  query = query + " and " + taskDateQuery + " and " + taskStatusQuery;
              }
              if (strWorkDate != null &amp;&amp; !strWorkDate.isEmpty() &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (strIdList == null || strIdList.isEmpty())) {
                  query = query + " and " + workDateQuery + " and " + taskStatusQuery;
              }
              if (strWorkDate != null &amp;&amp; !strWorkDate.isEmpty() &amp;&amp; strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; strIdList != null &amp;&amp; !strIdList.isEmpty()) {
                  query = query + " and " + taskIdQuery + " and " + taskDateQuery + " and " + workDateQuery + " and " + taskStatusQuery;
              }
              if (strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; strWorkDate != null &amp;&amp; !strWorkDate.isEmpty() &amp;&amp; (strIdList == null || strIdList.isEmpty())) {
                  query = query + " and " + taskDateQuery + " and " + workDateQuery + " and " + taskStatusQuery;
              }
              if (strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty()) &amp;&amp; strIdList != null &amp;&amp; !strIdList.isEmpty()) {
                  query = query + " and " + taskIdQuery + " and " + taskDateQuery + " and " + taskStatusQuery;
              }
              if ((strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; strWorkDate != null &amp;&amp; !strWorkDate.isEmpty() &amp;&amp; strIdList != null &amp;&amp; !strIdList.isEmpty()) {
                  query = query + " and " + taskIdQuery + " and " + workDateQuery + " and " + taskStatusQuery;
              }
              if ((strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (strWorkDate == null || strWorkDate.isEmpty()) &amp;&amp; (strIdList == null || strIdList.isEmpty()) &amp;&amp; (lastModifiedDateTime == null || lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskStatusQuery;
              }
          } else if (filterParameter == 2) {
  
              query = query + " and " + noWorkPerformedQuery;
  
              if ((strIdList != null &amp;&amp; !strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (lastModifiedDateTime == null || lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskIdQuery + " and " + taskStatusQuery;
              }
              if ((strIdList != null &amp;&amp; !strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (lastModifiedDateTime != null &amp;&amp; !lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskIdQuery + " and" + lastModified + " and " + taskStatusQuery;
              }
              if ((strIdList == null || strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (lastModifiedDateTime != null &amp;&amp; !lastModifiedDateTime.isEmpty())) {
                  query = query + " and" + lastModified + " and " + taskStatusQuery;
              }
              if ((strIdList == null || strIdList.isEmpty()) &amp;&amp; (strTaskDate == null || strTaskDate.isEmpty()) &amp;&amp; (lastModifiedDateTime == null || lastModifiedDateTime.isEmpty())) {
                  query = query + " and " + taskStatusQuery;
              }
              if (strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; (strIdList == null || strIdList.isEmpty())) {
                  query = query + " and " + taskDateQuery + " and " + taskStatusQuery;
  
              }
              if (strTaskDate != null &amp;&amp; !strTaskDate.isEmpty() &amp;&amp; strIdList != null &amp;&amp; !strIdList.isEmpty()) {
                  query = query + " and " + taskIdQuery + " and " + taskDateQuery + " and " + taskStatusQuery;
  
              }
  </code></pre>
  
  <p>And there's more of that...
  I know this very bad, but don't know how to improve this code. Thought of using switch but it does't help that much. </p>
  
  <p>Why it has so many conditions because for example. 
  Lets say I have two optional filters on name and date, then scenarios</p>
  
  <pre><code>Name    Date
  True    True
  True    False
  False   True
  False   False
  </code></pre>
  
  <p>Now you can understand where I am going. So as the number of filters add up these conditions multiple simple maths. </p>
  
  <p>I hope someone can advice me how to handle such scenarios thanks!</p>