ceph3us - 1 year ago 74
Java Question

# consider evaluate all third if second true

i'm to tired to think :)

is in java any simple solution to this ?

``````A B | =         XOR -> NO
--------        AND -> NO
0 1 | 0         OR -> NO
0 0 | 0
1 1 | 0
1 0 | 1
``````

this came from

``````             condition 1       if condition 2    take condition 3
evaluated to       evaluated to         to consider
true               true

return         a        &&       if(b)      &&              c

else  only a

// i can make it like this
return (a && b) ? a && b && c : a;
// then simplifying
return b ? a && c : a;
``````

but if a is statement i need make solution/compute & substitute on right side

or maybe there's a simpler way to write this condition?

Does a && !b work? – bradimus

Maybe it's me -- but what are you asking? – Hovercraft Full Of Eels

example to consider:

``````public boolean isRequestInQue(Request<User> requestToCheck,
boolean checkCallerAlive) {
int id = requestToCheck.getId();
Request<User> requestInQue = _stateCallerRequestList.get(id);
return requestInQue != null
? checkCallerAlive
? requestToCheck.equals(requestInQue)
&& requestInQue.isCallerAlive()
: requestToCheck.equals(requestInQue)
: false;
}
``````

Ternary operator can be difficult to follow, especially if you are asking for help with the logic. Can you give an example using if statements? – dave

``````if(requestInQue!=null)
if(checkCallerAlive)
if(requestToCheck.equals(requestInQue))
if(requestInQue.isCallerAlive())
return true;
else if(requestToCheck.equals(requestInQue)
return true;
return false;
``````

``````true && (!false || true) = true
true && (!true || true) = true
true && (!true || false) = false
true && (!false || false) = true

public boolean checkWithCifB(boolean a, boolean b, boolean c) {
return a && (!b || c);
}
``````

``````return requestInQue != null && requestToCheck.equals(requestInQue) &&