All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.tinyexpression.parser.StringMultipleParameterPredicator Maven / Gradle / Ivy

There is a newer version: 1.4.4
Show newest version
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 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(")");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy