private static AttributeMatcher optimizeKeyMatcher(AttributeMatcher attributeMatcher, Stack<Rule> ruleStack) { for (int i = 0, n = ruleStack.size(); i < n; ++i) { if (ruleStack.get(i) instanceof PositiveRule) { PositiveRule positiveRule = (PositiveRule) ruleStack.get(i); if (positiveRule.keyMatcher.isCoveredBy(attributeMatcher)) { return AnyMatcher.INSTANCE; } } } return attributeMatcher; }
private static AttributeMatcher optimizeValueMatcher(AttributeMatcher attributeMatcher, Stack<Rule> ruleStack) { for (int i = 0, n = ruleStack.size(); i < n; ++i) { if (ruleStack.get(i) instanceof PositiveRule) { PositiveRule positiveRule = (PositiveRule) ruleStack.get(i); if (positiveRule.valueMatcher.isCoveredBy(attributeMatcher)) { return AnyMatcher.INSTANCE; } } } return attributeMatcher; }
@Test public void isCoveredByTest() { AttributeMatcher attributeMatcher1 = new KeyMatcher(Arrays.asList(KEY1)); AttributeMatcher attributeMatcher2 = new KeyMatcher(Arrays.asList(KEY1)); Assert.assertTrue(attributeMatcher1.isCoveredBy(attributeMatcher1)); Assert.assertTrue(attributeMatcher1.isCoveredBy(attributeMatcher2)); Assert.assertTrue(attributeMatcher1.isCoveredBy(AnyMatcher.INSTANCE)); Assert.assertFalse(AnyMatcher.INSTANCE.isCoveredBy(attributeMatcher1)); }
@Test public void isCoveredByTest() { AttributeMatcher attributeMatcher1 = new ValueMatcher(Arrays.asList(VALUE1)); AttributeMatcher attributeMatcher2 = new ValueMatcher(Arrays.asList(VALUE1)); Assert.assertTrue(attributeMatcher1.isCoveredBy(attributeMatcher1)); Assert.assertTrue(attributeMatcher1.isCoveredBy(attributeMatcher2)); Assert.assertTrue(attributeMatcher1.isCoveredBy(AnyMatcher.INSTANCE)); Assert.assertFalse(AnyMatcher.INSTANCE.isCoveredBy(attributeMatcher1)); }
private static AttributeMatcher optimizeKeyMatcher(AttributeMatcher attributeMatcher, Stack<Rule> ruleStack) { for (int i = 0, n = ruleStack.size(); i < n; ++i) { if (ruleStack.get(i) instanceof PositiveRule) { PositiveRule positiveRule = (PositiveRule) ruleStack.get(i); if (positiveRule.keyMatcher.isCoveredBy(attributeMatcher)) { return AnyMatcher.INSTANCE; } } } return attributeMatcher; }
private static AttributeMatcher optimizeValueMatcher(AttributeMatcher attributeMatcher, Stack<Rule> ruleStack) { for (int i = 0, n = ruleStack.size(); i < n; ++i) { if (ruleStack.get(i) instanceof PositiveRule) { PositiveRule positiveRule = (PositiveRule) ruleStack.get(i); if (positiveRule.valueMatcher.isCoveredBy(attributeMatcher)) { return AnyMatcher.INSTANCE; } } } return attributeMatcher; }