package com.alibaba.druid.sql.dialect.spark.ast.expr;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.dialect.spark.ast.SparkSqlExprImpl;
import com.alibaba.druid.sql.dialect.spark.visitor.SparkVisitor;
import java.util.ArrayList;
import java.util.List;
import util.sqlparse.visitor.common.Objects;

public class SparkTablePartition extends SparkSqlExprImpl {
   private List<SparkDefProperty> cols = new ArrayList();

   public void addDef(SQLExpr col, SQLExpr value) {
      this.cols.add(new SparkDefProperty(col, value));
   }

   public void addDef(SQLBinaryOpExpr e) {
      this.cols.add(new SparkDefProperty(e.getLeft(), e.getRight()));
   }

   public List<SparkDefProperty> getCols() {
      return this.cols;
   }

   public void setCols(List<SparkDefProperty> cols) {
      this.cols = cols;
   }

   public List<SQLObject> getChildren() {
      ArrayList<SQLObject> sqlExprs = new ArrayList();

      for(SparkDefProperty col : this.cols) {
         sqlExprs.add(col);
      }

      return sqlExprs;
   }

   public void accept0(SparkVisitor v) {
      if (v.visit(this)) {
         this.acceptChild(v, this.cols);
      }

      v.endVisit(this);
   }

   public SparkTablePartition clone() {
      SparkTablePartition e = new SparkTablePartition();

      for(SparkDefProperty col : this.cols) {
         e.cols.add(col.clone());
      }

      return e;
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (o != null && this.getClass() == o.getClass()) {
         SparkTablePartition that = (SparkTablePartition)o;
         return Objects.equals(this.cols, that.cols);
      } else {
         return false;
      }
   }

   public int hashCode() {
      return Objects.hash(this.cols);
   }
}
