/**
* Alipay.com Inc.
* Copyright (c) 2004-2012 All Rights Reserved.
*/
package com.alipay.zdal.parser.sql.ast.expr;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.alipay.zdal.parser.sql.ast.SQLExpr;
import com.alipay.zdal.parser.sql.ast.SQLExprImpl;
import com.alipay.zdal.parser.sql.visitor.SQLASTVisitor;
/**
*
* @author xiaoqing.zhouxq
* @version $Id: SQLAggregateExpr.java, v 0.1 2012-11-17 ����3:14:24 xiaoqing.zhouxq Exp $
*/
public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
private static final long serialVersionUID = 1L;
protected String methodName;
protected Option option;
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
public SQLAggregateExpr(String methodName) {
this.methodName = methodName;
}
public SQLAggregateExpr(String methodName, Option option) {
this.methodName = methodName;
this.option = option;
}
public String getMethodName() {
return this.methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public Option getOption() {
return this.option;
}
public void setOption(Option option) {
this.option = option;
}
public List<SQLExpr> getArguments() {
return this.arguments;
}
public void output(StringBuffer buf) {
buf.append(this.methodName);
buf.append("(");
int i = 0;
for (int size = this.arguments.size(); i < size; ++i) {
((SQLExpr) this.arguments.get(i)).output(buf);
}
buf.append(")");
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.arguments);
}
visitor.endVisit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
result = prime * result + ((option == null) ? 0 : option.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SQLAggregateExpr other = (SQLAggregateExpr) obj;
if (arguments == null) {
if (other.arguments != null) {
return false;
}
} else if (!arguments.equals(other.arguments)) {
return false;
}
if (methodName == null) {
if (other.methodName != null) {
return false;
}
} else if (!methodName.equals(other.methodName)) {
return false;
}
if (option != other.option) {
return false;
}
return true;
}
public static enum Option {
DISTINCT, ALL, UNIQUE
}
}