QueryUtils { public static String parseFilterOperator( String operator, String value ) { if ( StringUtils.isEmpty( operator ) ) { throw new QueryParserException( "Filter Operator is null" ); } switch ( operator ) { case "eq": { return "= " + QueryUtils.parseValue( value ); } case "!eq": { return "!= " + QueryUtils.parseValue( value ); } case "ne": { return "!= " + QueryUtils.parseValue( value ); } case "neq": { return "!= " + QueryUtils.parseValue( value ); } case "gt": { return "> " + QueryUtils.parseValue( value ); } case "lt": { return "< " + QueryUtils.parseValue( value ); } case "gte": { return ">= " + QueryUtils.parseValue( value ); } case "ge": { return ">= " + QueryUtils.parseValue( value ); } case "lte": { return "<= " + QueryUtils.parseValue( value ); } case "le": { return "<= " + QueryUtils.parseValue( value ); } case "like": { return "like '%" + value + "%'"; } case "!like": { return "not like '%" + value + "%'"; } case "^like": { return " like '" + value + "%'"; } case "!^like": { return " not like '" + value + "%'"; } case "$like": { return " like '%" + value + "'"; } case "!$like": { return " not like '%" + value + "'"; } case "ilike": { return " ilike '%" + value + "%'"; } case "!ilike": { return " not ilike '%" + value + "%'"; } case "^ilike": { return " ilike '" + value + "%'"; } case "!^ilike": { return " not ilike '" + value + "%'"; } case "$ilike": { return " ilike '%" + value + "'"; } case "!$ilike": { return " not ilike '%" + value + "'"; } case "in": { return "in " + QueryUtils.convertCollectionValue( value ); } case "!in": { return " not in " + QueryUtils.convertCollectionValue( value ); } case "null": { return "is null"; } case "!null": { return "is not null"; } default: { throw new QueryParserException( "`" + operator + "` is not a valid operator." ); } } }  static T parseValue( Class<T> klass, Object objectValue ); @SuppressWarnings( "unchecked" ) static T parseValue( Class<T> klass, Class<?> secondaryKlass, Object objectValue ); @SuppressWarnings( { "unchecked", "rawtypes" } ) static T getEnumValue( Class<T> klass, String value ); static Object parseValue( String value ); static String parseSelectFields( List<String> fields ); static String convertCollectionValue( String value ); static String parseFilterOperator( String operator, String value ); @Nonnull static List<Order> convertOrderStrings( @Nullable Collection<String> orders, @Nonnull Schema schema ); static T getSingleResult( TypedQuery<T> query );  }
@Test public void testParseFilterOperator() { assertEquals( "= 5", QueryUtils.parseFilterOperator( "eq", "5" ) ); assertEquals( "= 'ABC'", QueryUtils.parseFilterOperator( "eq", "ABC" ) ); assertEquals( "like '%abc%'", QueryUtils.parseFilterOperator( "like", "abc" ) ); assertEquals( " like '%abc'", QueryUtils.parseFilterOperator( "$like", "abc" ) ); assertEquals( "in ('a','b','c')", QueryUtils.parseFilterOperator( "in", "[a,b,c]" ) ); assertEquals( "in (1,2,3)", QueryUtils.parseFilterOperator( "in", "[1,2,3]" ) ); assertEquals( "is not null", QueryUtils.parseFilterOperator( "!null", null ) ); }