Back to project page NexusData.
The source code is released under:
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project NexusData listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.dkharrat.nexusdata.predicate.parser; //from w ww. j a va2 s .co m import com.github.dkharrat.nexusdata.predicate.CompoundPredicate; import com.github.dkharrat.nexusdata.predicate.Expression; import com.github.dkharrat.nexusdata.predicate.Predicate; import static com.github.dkharrat.nexusdata.predicate.CompoundPredicate.Operator; import static com.github.dkharrat.nexusdata.predicate.parser.PredicateParser.TokenType; public class LogicalParselet implements InfixParselet<TokenType,Expression<?>> { private final Operator operator; private final int precedence; LogicalParselet(Operator operator, int precedence) { this.operator = operator; this.precedence = precedence; } public Expression<?> parse(Parser<TokenType,Expression<?>> parser, Expression<?> left, Token<TokenType> token) { if (!(left instanceof Predicate)) { throw new ParseException("Expected a predicate for left-hand side, but got an expression"); } Expression<?> right = parser.parse(getPrecedence() - 1); if (!(right instanceof Predicate)) { throw new ParseException("Expected a predicate for right-hand side, but got an expression"); } return new CompoundPredicate((Predicate)left, operator, (Predicate)right); } public int getPrecedence() { return precedence; } }