Determine which condition caused an if statement to execute
<p>So I have an if statement that looks like the following:</p>

<pre><code>List&lt;Integer&gt; portsInUse = new ArrayList&lt;Integer&gt;();
. . .
if(portsInUse.contains((Integer) newPort1) 
        || portsInUse.contains((Integer) newPort2){

    fail(_____, "This port is already in use.");
}
</code></pre>

<p><code>newPort1</code> and <code>newPort2</code> are assigned by digging them out of an HttpServletRequest.  <code>fail(String parameter, String message)</code> is an internal method to alert the user that something went wrong.</p>

<p>What I'd like to do is be able to tell which condition caused the if statement to trigger, and then set the failure message accordingly.  Can I do that, or would I have to do something like this:</p>

<pre><code>List&lt;Integer&gt; portsInUse = new ArrayList&lt;Integer&gt;();
. . .
boolean port1 = portsInUse.contains((Integer) newPort1);
boolean port2 = portsInUse.contains((Integer) newPort2);
if(port1 || port2){
    if(port1)
        fail("newPort1", "This port is already in use.");
    else
        fail("newPort2", "This port is already in use.");
}
</code></pre>

<p>Or, third option, should I break up the conditions like this:</p>

<pre><code>List&lt;Integer&gt; portsInUse = new ArrayList&lt;Integer&gt;();
. . .
if(portsInUse.contains((Integer) newPort1) {
    fail("newPort1", "This port is already in use.");
}
if(portsInUse.contains((Integer) newPort2) {
    fail("newPort2", "This port is already in use.");
}
</code></pre>

<p>I'm sure I'm overcomplicating things, but thank you in advance.</p>
