package com.chenyang.druid.sql.dialect.sqlserver.ast.stmt;

import com.chenyang.druid.FastsqlException;
import com.chenyang.druid.sql.ast.expr.SQLBinaryOperator;
import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem;
import com.chenyang.druid.sql.dialect.sqlserver.ast.SQLServerObject;
import com.chenyang.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;
import java.io.IOException;
import util.sqlparse.visitor.common.Objects;

public class SQLServerUpdateSetItem extends SQLUpdateSetItem implements SQLServerObject {
   private SQLBinaryOperator operator;

   public void accept0(SQLServerASTVisitor visitor) {
      if (visitor.visit(this)) {
         if (this.getColumn() != null) {
            this.getColumn().accept(visitor);
         }

         if (this.getValue() != null) {
            this.getValue().accept(visitor);
         }
      }

      visitor.endVisit(this);
   }

   protected void accept0(SQLASTVisitor visitor) {
      this.accept0((SQLServerASTVisitor)visitor);
   }

   public SQLBinaryOperator getOperator() {
      return this.operator;
   }

   public void setOperator(SQLBinaryOperator operator) {
      this.operator = operator;
   }

   public void output(Appendable buf) {
      try {
         this.getColumn().output(buf);
         buf.append(this.operator.name);
         this.getValue().output(buf);
      } catch (IOException ex) {
         throw new FastsqlException("output error", ex);
      }
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (o != null && this.getClass() == o.getClass()) {
         if (!super.equals(o)) {
            return false;
         } else {
            SQLServerUpdateSetItem that = (SQLServerUpdateSetItem)o;
            return this.operator == that.operator;
         }
      } else {
         return false;
      }
   }

   public int hashCode() {
      return Objects.hash(super.hashCode(), this.operator);
   }
}
