Are there any object representation of these comparison operators (<, <=, ==, >=, >, !=) in Java ?
E.g. use case:
void filterHotel( Object operator, float rating ) {
String query = "SELECT hotel.name from hotel where hotel.rating " +
operator.toString() + rating;
// execute query
}
No. But it is easy to write, consider using
enumwith custom method:Pass e.g.
Operator.LESS_THANand extract actual operator usingoperator.getRepresentation().Also make sure user cannot put arbitrary string in place of
operatorto avoid sql-injection.