comparison operator objects in java -


are there object representation of these comparison operators (<, <=, ==, >=, >, !=) in java ?

e.g. use case:

void filterhotel( object operator, float rating ) {      string query = "select hotel.name hotel hotel.rating " +  operator.tostring() + rating;         // execute query } 

no. easy write, consider using enum custom method:

public enum operator {     equal("=="),     not_equal("<>"),     greater_than(">"),     greater_than_or_equal(">="),     less_than("<"),     less_than_or_equal("<=");      private final string representation;      private operator(string representation) {         this.representation = representation;     }      public string getrepresentation() {         return representation;     } } 

pass e.g. operator.less_than , extract actual operator using operator.getrepresentation().

also make sure user cannot put arbitrary string in place of operator avoid .


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -