/** @return a new {@code Rule} instance. */ public Rule build() { if (this.valueList.remove(STRING_NEGATION)) { AttributeMatcher attributeMatcher = new NegativeMatcher(this.keyList, this.valueList); return new NegativeRule(this, attributeMatcher); } AttributeMatcher keyMatcher = getKeyMatcher(this.keyList); AttributeMatcher valueMatcher = getValueMatcher(this.valueList); keyMatcher = RuleOptimizer.optimize(keyMatcher, this.ruleStack); valueMatcher = RuleOptimizer.optimize(valueMatcher, this.ruleStack); return new PositiveRule(this, keyMatcher, valueMatcher); }
private void extractValues(String elementName, XmlPullParser pullParser) throws XmlPullParserException { for (int i = 0; i < pullParser.getAttributeCount(); ++i) { String name = pullParser.getAttributeName(i); String value = pullParser.getAttributeValue(i); if (E.equals(name)) { this.element = Element.fromString(value); } else if (K.equals(name)) { this.keys = value; } else if (V.equals(name)) { this.values = value; } else if (CAT.equals(name)) { this.cat = value; } else if (CLOSED.equals(name)) { this.closed = Closed.fromString(value); } else if (ZOOM_MIN.equals(name)) { this.zoomMin = XmlUtils.parseNonNegativeByte(name, value); } else if (ZOOM_MAX.equals(name)) { this.zoomMax = XmlUtils.parseNonNegativeByte(name, value); } else { throw XmlUtils.createXmlPullParserException(elementName, name, value, i); } } validate(elementName); this.keyList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN.split(this.keys))); this.valueList = new ArrayList<String>(Arrays.asList(SPLIT_PATTERN.split(this.values))); this.elementMatcher = getElementMatcher(this.element); this.closedMatcher = getClosedMatcher(this.closed); this.elementMatcher = RuleOptimizer.optimize(this.elementMatcher, this.ruleStack); this.closedMatcher = RuleOptimizer.optimize(this.closedMatcher, this.ruleStack); }