luky luky - 1 month ago 7
Java Question

Strange java LatLng condition

Is the following original code (scroll to right)

boolean b = this.southwest.longitude <= this.northeast.longitude ? this.southwest.longitude <= var1 && var1 <= this.northeast.longitude :
this.southwest.longitude <= var1 || var1 <= this.northeast.longitude;


same as this? (my interpretation)

if (this.northeast.longitude)
{
boolean b = this.southwest.longitude <= var1 && var1 <= this.northeast.longitude;
} else {
boolean b = this.southwest.longitude <= var1 || var1 <= this.northeast.longitude;
}


because it feels it is more like this weird condition (mix of comparing boolean and longitude)

if (this.southwest.longitude)
{
boolean b = this.southwest.longitude <= (this.southwest.longitude <= var1 && var1 <= this.northeast.longitude);

} else {
boolean b = this.southwest.longitude <= (this.southwest.longitude <= var1 || var1 <= this.northeast.longitude);

}


What i am trying to do, is to manually build conditions of LatLngBounds.contains() to perform query on NOSQL db.

Answer

Neither, nor. It is:

boolean result;
if(this.southwest.longitude <= this.northeast.longitude){   
    result = this.southwest.longitude <= var1 && var1 <= this.northeast.longitude;
} else {
    result = this.southwest.longitude <= var1 || var1 <= this.northeast.longitude;
}

a ? b : c is just "syntactic sugar" for if a then b else c