org.unlaxer.tinyexpression.parser.StringMultipleParameterPredicator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tinyExpression Show documentation
Show all versions of tinyExpression Show documentation
TinyExpression implemented with Unlaxer
package org.unlaxer.tinyexpression.parser;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.unlaxer.Token;
import org.unlaxer.parser.Parser;
import org.unlaxer.tinyexpression.evaluator.javacode.ExpressionOrLiteral;
import org.unlaxer.tinyexpression.evaluator.javacode.SimpleJavaCodeBuilder;
import org.unlaxer.tinyexpression.evaluator.javacode.StringClauseBuilder;
import org.unlaxer.tinyexpression.evaluator.javacode.TinyExpressionTokens;
import org.unlaxer.tinyexpression.evaluator.javacode.TokenCodeBuilder;
import org.unlaxer.util.annotation.TokenExtractor;
public interface StringMultipleParameterPredicator extends TokenCodeBuilder{
@TokenExtractor
public default Token getLeftExpression(Token thisParserParsed) {
return thisParserParsed.getChildWithParser(StringExpressionParser.class);
}
@TokenExtractor
public default List getParameters(Token thisParserParsed){
Token parameterParser = thisParserParsed.getChildWithParser(parameterParserClass());
return getStringExpressions(parameterParser);
}
public Class extends Parser> parameterParserClass();
static List getStringExpressions(Token parameterParser){
Token stringExpressions = InMethodParser.getStringExpressions(parameterParser);
List expressions = stringExpressions.filteredChildren.stream()
.filter(token->token.parser instanceof StringExpressionParser)
.collect(Collectors.toList());
return expressions;
}
public String predicateMethodString();
@Override
public default void build(SimpleJavaCodeBuilder builder, Token token ,
TinyExpressionTokens tinyExpressionTokens) {
builder.append(predicateMethodString());
List filteredChildren = token.filteredChildren;
Iterator iterator = filteredChildren.stream()
.map(_token-> StringClauseBuilder.SINGLETON.build(_token, tinyExpressionTokens))
.iterator();
while (iterator.hasNext()) {
ExpressionOrLiteral expressionOrLiteral = iterator.next();
builder.append(expressionOrLiteral.toString());
if(iterator.hasNext()) {
builder.append(",");
}
}
builder.append(")");
}
}