com.querydsl.core.group.AbstractGroupExpression Maven / Gradle / Ivy
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
*
* 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.querydsl.core.group;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Ops;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Visitor;
import com.querydsl.core.types.dsl.DslExpression;
import com.querydsl.core.types.dsl.Expressions;
/**
* A base class for GroupExpressions
*
* @author sasa
* @param
* @param
*/
public abstract class AbstractGroupExpression implements GroupExpression {
private static final long serialVersionUID = 1509709546966783160L;
private final Class extends R> type;
private final Expression expr;
@SuppressWarnings("unchecked")
public AbstractGroupExpression(Class super R> type, Expression expr) {
this.type = (Class) type;
this.expr = expr;
}
/**
* Create an alias for the expression
*
* @return alias expression
*/
public DslExpression as(Path alias) {
return Expressions.dslOperation(getType(), Ops.ALIAS, this, alias);
}
/**
* Create an alias for the expression
*
* @return alias expression
*/
public DslExpression as(String alias) {
return as(ExpressionUtils.path(getType(), alias));
}
@Override
public Expression getExpression() {
return expr;
}
@Override
public R accept(Visitor v, C context) {
return expr.accept(v, context);
}
@Override
public boolean equals(Object o) {
if (o != null && getClass().equals(o.getClass())) {
return ((GroupExpression, ?>) o).getExpression().equals(expr);
} else {
return false;
}
}
@Override
public Class extends R> getType() {
return type;
}
@Override
public int hashCode() {
return expr.hashCode();
}
@Override
public String toString() {
return expr.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy