com.blazebit.persistence.parser.expression.TreatExpression Maven / Gradle / Ivy
/*
* Copyright 2014 - 2020 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.blazebit.persistence.parser.expression;
/**
*
* @author Christian Beikov
* @since 1.2.0
*/
public class TreatExpression extends AbstractExpression implements PathElementExpression {
// Can be either a PathExpression or a KEY/VALUE expression
private Expression expression;
private final String type;
public TreatExpression(Expression expression, String type) {
this.expression = expression;
this.type = type;
}
@Override
public TreatExpression copy(ExpressionCopyContext copyContext) {
return new TreatExpression(expression.copy(copyContext), type);
}
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
@Override
public T accept(ResultVisitor visitor) {
return visitor.visit(this);
}
public Expression getExpression() {
return expression;
}
public void setExpression(Expression expression) {
this.expression = expression;
}
public String getType() {
return type;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TreatExpression)) {
return false;
}
TreatExpression that = (TreatExpression) o;
if (expression != null ? !expression.equals(that.expression) : that.expression != null) {
return false;
}
return type != null ? type.equals(that.type) : that.type == null;
}
@Override
public int hashCode() {
int result = expression != null ? expression.hashCode() : 0;
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
}