I think that the following code isn't really nice. I can't see however another way (other than a switch statement) to better implement this. Especially since I don't think replacing this with the strategy pattern for instance is a better way.
String status;
if(userHasContact&&contactHasUser) {
status = "HAS_CONTACT";
} else if(userHasContact&&!contactHasUser) {
status = "PENDING";
} else if(!userHasContact&&contactHasUser) {
status = "ACCEPT_REQUEST";
} else {
status = "ADD_CONTACT";
}
I want to return the value of status to the view (this code is from the controller) of the page to show to the user whether that profile he is seeing is already a contact, pending (he already sent a status), accept (it was sent to him), or remove (he already has him as contact).
switch
statement wouldn't work "out of the box" for this, as you would need to switch over two independent variables at once. – Simon André Forsberg yesterdayswitch((!userHasContact)+((!contactHasUser)<1)){
– hildred 23 hours agoindex
in my answer. – maaartinus 22 hours ago