title: Handling nested if/else statements using Java 8 streams
body: <p>I have a condition where there are some checks to be made in order to create an object. 
  I am using <code>Stream</code>s for this, and I'm having a tough time in getting this done. </p>
  
  <p>The input is a <code>HashMap</code> object with key/value pairs and output should be below. </p>
  
  <pre><code>| userrole   | userid | username | output   |
  |------------|--------|----------|----------|
  | "" (blank) | 111    | amathews | 111      |
  | ""         |        | amathews | amathews |
  | Admin      | 111    | amathews | 111      |
  | Admin      | 111    | ""       | 111      |
  | Admin      |        | amathews | Admin    |
  </code></pre>
  
  <p>This is how the precedence is: userid>userrole>username.</p>
  
  <p>Each <code>HashMap</code> object will contain userrole/username/userid as key and its values along with other key/value pairs.
  We will have a bunch of nested if/else statements to accomplish this task in prior versions of Java.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>map.entrySet().stream()
          .filter(e -&gt; e.getValue() instanceof String || e.getValue() instanceof Integer)
          .filter(e -&gt; e.getKey().contains("userrole") || e.getKey().contains("userid") || e.getKey().contains("username") )
          .map(e -&gt; e.getValue())
          .collect(Collectors.toList());
  </code></pre>
  
  <p>I know that the way I have written map function in the <code>Stream</code> is not correct too.
  How to accomplish this in java 8? I do not know how to add the nested if/else part here. </p>
  
  <p>Edit : Sorry If I hadn't stated the problem precisely. Here is the code snippet:</p>
  
  <pre><code>public List&lt;UserAction&gt; getUserActionList(Map&lt;String, String&gt; map)
      {
          String userRole = map.get("userrole");
          String userName = map.get("username");
          String userId = map.get("userid");
  
          String output = null;
          // if userrole, userid and username are not null/empty, then output is userid 
          if(!checkForNullEmpty(userRole) &amp;&amp; !checkForNullEmpty(userId) &amp;&amp; !checkForNullEmpty(userName))
              output = userId;
          // if userrole and userid are null/empty and username is not empty/null, then output is username
          else if(checkForNullEmpty(userRole) &amp;&amp; checkForNullEmpty(userId) &amp;&amp; !checkForNullEmpty(userName))
              output = userName;
          // if userid and username are null/empty and userrole is not empty/null, then output is userrole
          else if(!checkForNullEmpty(userRole) &amp;&amp; checkForNullEmpty(userId) &amp;&amp; checkForNullEmpty(userName))
              output = userRole;
  
          List&lt;UserAction&gt; udList = new ArrayList&lt;&gt;();
          // Add the map and output into a UserAction object
          udList.add(new UserAction(map, output));
  
          return udList;
  
      }
  </code></pre>
  
  <p>I had handled only 3 conditions here as per the table. So this has to refactored to use java 8 <code>Stream</code>s. I hope it makes sense now. </p>