@Test public void testValidVisibilityExpressions() { final String EXPRESSION1 = "(a&b)|c"; assertTrue(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("a", "b"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("a", "b", "c"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("c"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("a"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("b"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet("d"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION1, Sets.newHashSet())); final String EXPRESSION2 = "((a & b) | c) & (d | e)"; assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "b", "d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "b", "e"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("c", "d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("c", "e"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "c", "d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("b", "c", "e"))); assertTrue( VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "b", "c", "d", "e"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("b"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("c"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("d"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("e"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "b"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "d"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "e"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet("a", "b", "c"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION2, Sets.newHashSet())); final String EXPRESSION3 = "(a&b&c)|d|e"; assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "b", "c"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "b", "e"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("c", "d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("c", "e"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "c", "d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("d"))); assertTrue(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("e"))); assertTrue( VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "b", "c", "d", "e"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("b"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("c"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "b"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet("a", "c"))); assertFalse(VisibilityExpression.evaluate(EXPRESSION3, Sets.newHashSet())); final String EMPTY_EXPRESSION = ""; assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("a", "b"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("a", "b", "c"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("c"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("a"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("b"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet("d"))); assertTrue(VisibilityExpression.evaluate(EMPTY_EXPRESSION, Sets.newHashSet())); }
public static boolean evaluate(final String expression, final Set<String> auths) { final String trimmed = expression.replaceAll("\\s+", ""); try { return expressionCache.get(trimmed).evaluate(auths); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); } }
VisibilityExpression { public static boolean evaluate(final String expression, final Set<String> auths) { final String trimmed = expression.replaceAll("\\s+", ""); try { return expressionCache.get(trimmed).evaluate(auths); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); } } }
VisibilityExpression { public static boolean evaluate(final String expression, final Set<String> auths) { final String trimmed = expression.replaceAll("\\s+", ""); try { return expressionCache.get(trimmed).evaluate(auths); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); } }  }
VisibilityExpression { public static boolean evaluate(final String expression, final Set<String> auths) { final String trimmed = expression.replaceAll("\\s+", ""); try { return expressionCache.get(trimmed).evaluate(auths); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); } }  static boolean evaluate(final String expression, final Set<String> auths); }
VisibilityExpression { public static boolean evaluate(final String expression, final Set<String> auths) { final String trimmed = expression.replaceAll("\\s+", ""); try { return expressionCache.get(trimmed).evaluate(auths); } catch (final ExecutionException e) { throw new RuntimeException(e.getCause()); } }  static boolean evaluate(final String expression, final Set<String> auths);  }