ExpressionUtils { public static boolean isBoolean( String expression, Map<String, Object> vars ) { try { Object result = evaluate( expression, vars ); return ( result instanceof Boolean ); } catch ( JexlException | NumberFormatException ex ) { return false; } }  static Object evaluate( String expression, Map<String, Object> vars ); static Double evaluateToDouble( String expression, Map<String, Object> vars ); static boolean isTrue( String expression, Map<String, Object> vars ); static boolean isBoolean( String expression, Map<String, Object> vars ); static boolean isValid( String expression, Map<String, Object> vars ); static boolean isNumeric( String value ); static String asSql( String expression ); static Object evaluate( String expression );  }
@Test public void testIsBoolean() { Map<String, Object> vars = new HashMap<>(); vars.put( "uA2hsh8j26j", "FEMALE" ); vars.put( "v2", "12" ); assertTrue( ExpressionUtils.isBoolean( "2 > 1", null ) ); assertTrue( ExpressionUtils.isBoolean( "(2 * 3) == 6", null ) ); assertTrue( ExpressionUtils.isBoolean( "\"a\" == \"a\"", null ) ); assertTrue( ExpressionUtils.isBoolean( "'b' == 'b'", null ) ); assertTrue( ExpressionUtils.isBoolean( "('b' == 'b') && ('c' == 'c')", null ) ); assertTrue( ExpressionUtils.isBoolean( "'goat' == 'goat'", null ) ); assertFalse( ExpressionUtils.isBoolean( "4", null ) ); assertFalse( ExpressionUtils.isBoolean( "3 + 2", null ) ); assertFalse( ExpressionUtils.isBoolean( "someinvalid expr", null ) ); }