Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.querydsl.core.types.*;
import com.querydsl.core.types.Ops.MathOps;
import com.querydsl.core.util.MathUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -747,18 +749,44 @@ public <N extends Number & Comparable<?>> NumberExpression<T> subtract(N right)
return Expressions.numberOperation(getType(), Ops.SUB, mixin, ConstantImpl.create(right));
}

@SuppressWarnings("unchecked")
private <P extends Number & Comparable<?>> NumberExpression<P> sum(Class<P> clazz) {
if (sum == null) {
sum = (NumberExpression<T>) Expressions.numberOperation(clazz, Ops.AggOps.SUM_AGG, mixin);
}
return (NumberExpression<P>) sum;
}

/**
* Create a {@code sum(this)} expression
*
* <p>Get the sum of this expression (aggregation)
*
* @return sum(this)
*/
@SuppressWarnings("unchecked")
public NumberExpression<T> sum() {
if (sum == null) {
sum = Expressions.numberOperation(getType(), Ops.AggOps.SUM_AGG, mixin);
}
return sum;
return sum((Class<T>) getType());
}

/** {@link Float} {@link Double} are mapped to sumDouble. */
public NumberExpression<Double> sumDouble() {
return sum(Double.class);
}

/** {@link Byte} {@link Short} {@link Integer} {@link Long} are mapped to sumLong. */
public NumberExpression<Long> sumLong() {
return sum(Long.class);
}

/** {@link java.math.BigDecimal} are mapped to sumBigDecimal. */
public NumberExpression<BigDecimal> sumBigDecimal() {
return sum(BigDecimal.class);
}

/** {@link java.math.BigInteger} are mapped to sumBigInteger. */
public NumberExpression<BigInteger> sumBigInteger() {
return sum(BigInteger.class);
}

@Override
Expand Down