/* Generated By:JJTree: Do not edit this line. OContainsTextCondition.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.sql.executor.OResult;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class OContainsTextCondition extends OBooleanExpression {

  protected OExpression left;
  protected OExpression right;

  public OContainsTextCondition(int id) {
    super(id);
  }

  public OContainsTextCondition(OrientSql p, int id) {
    super(p, id);
  }

  /**
   * Accept the visitor.
   **/
  public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
    return visitor.visit(this, data);
  }

  @Override public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) {
    throw new UnsupportedOperationException("TODO Implement ContainsText!!!");//TODO
  }

  @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) {
    throw new UnsupportedOperationException("TODO Implement ContainsText!!!");//TODO
  }

  public void toString(Map<Object, Object> params, StringBuilder builder) {
    left.toString(params, builder);
    builder.append(" CONTAINSTEXT ");
    right.toString(params, builder);
  }

  @Override public boolean supportsBasicCalculation() {
    return true;
  }

  @Override protected int getNumberOfExternalCalculations() {
    int total = 0;
    if (!left.supportsBasicCalculation()) {
      total++;
    }
    if (!right.supportsBasicCalculation()) {
      total++;
    }
    return total;
  }

  @Override protected List<Object> getExternalCalculationConditions() {
    List<Object> result = new ArrayList<Object>();
    if (!left.supportsBasicCalculation()) {
      result.add(left);
    }
    if (!right.supportsBasicCalculation()) {
      result.add(right);
    }
    return result;
  }

  @Override public boolean needsAliases(Set<String> aliases) {
    if (!left.needsAliases(aliases)) {
      return true;
    }
    if (!right.needsAliases(aliases)) {
      return true;
    }
    return false;
  }

  @Override public OContainsTextCondition copy() {
    OContainsTextCondition result = new OContainsTextCondition(-1);
    result.left = left.copy();
    result.right = right.copy();
    return result;
  }

  @Override public void extractSubQueries(SubQueryCollector collector) {
    left.extractSubQueries(collector);
    right.extractSubQueries(collector);
  }

  @Override public boolean refersToParent() {
    return left.refersToParent() || right.refersToParent();
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    OContainsTextCondition that = (OContainsTextCondition) o;

    if (left != null ? !left.equals(that.left) : that.left != null)
      return false;
    if (right != null ? !right.equals(that.right) : that.right != null)
      return false;

    return true;
  }

  @Override public int hashCode() {
    int result = left != null ? left.hashCode() : 0;
    result = 31 * result + (right != null ? right.hashCode() : 0);
    return result;
  }

  @Override public List<String> getMatchPatternInvolvedAliases() {
    List<String> leftX = left == null ? null : left.getMatchPatternInvolvedAliases();
    List<String> rightX = right == null ? null : right.getMatchPatternInvolvedAliases();

    List<String> result = new ArrayList<String>();
    if (leftX != null) {
      result.addAll(leftX);
    }
    if (rightX != null) {
      result.addAll(rightX);
    }

    return result.size() == 0 ? null : result;
  }
}
/* JavaCC - OriginalChecksum=b588492ba2cbd0f932055f1f64bbbecd (do not edit this line) */

@@ -1106,260 +1106,798 @@
     
-throw new UnsupportedOperationException(%22TODO Implement ContainsText!!!%22);//TODO%0A  %7D%0A%0A  @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) %7B%0A    throw new UnsupportedOperationException(%22TODO Implement ContainsText!!!%22);//TODO
+Object leftValue = left.execute(currentRecord, ctx);%0A    if(leftValue==null %7C%7C !(leftValue instanceof String))%7B%0A      return false;%0A    %7D%0A    Object rightValue = right.execute(currentRecord, ctx);%0A    if(rightValue==null %7C%7C !(rightValue instanceof String))%7B%0A      return false;%0A    %7D%0A%0A    return ((String)leftValue).indexOf((String)rightValue) %3E -1;%0A  %7D%0A%0A  @Override public boolean evaluate(OResult currentRecord, OCommandContext ctx) %7B%0A    Object leftValue = left.execute(currentRecord, ctx);%0A    if(leftValue==null %7C%7C !(leftValue instanceof String))%7B%0A      return false;%0A    %7D%0A    Object rightValue = right.execute(currentRecord, ctx);%0A    if(rightValue==null %7C%7C !(rightValue instanceof String))%7B%0A      return false;%0A    %7D%0A%0A    return ((String)leftValue).indexOf((String)rightValue) %3E -1;
 %0A  %7D

Implement CONTAINSTEXT operator in new sql executor