Skip to content

Instantly share code, notes, and snippets.

@ldez
Created October 11, 2014 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldez/5350867ef1b74585cfe1 to your computer and use it in GitHub Desktop.
Save ldez/5350867ef1b74585cfe1 to your computer and use it in GitHub Desktop.
QueryDSL Collection util for BigDecimal divide Expression
import java.math.BigDecimal;
import java.math.RoundingMode;
import com.mysema.query.support.Expressions;
import com.mysema.query.types.ConstantImpl;
import com.mysema.query.types.Expression;
import com.mysema.query.types.expr.NumberExpression;
/**
* The Class BigDecimalExpression.
*/
public final class BigDecimalExpression {
/** The Constant DIVIDE. */
public static final String DIVIDE = "{0}.divide({1}, {2}, {3})";
/**
* Instantiates a new big decimal expression.
*
* @throws InstantiationException the instantiation exception
*/
private BigDecimalExpression() throws InstantiationException {
throw new InstantiationException();
}
/**
* Divide.
*
* @param dividend the dividend
* @param divisor the divisor
* @param scale the scale
* @param roundingMode the rounding mode
* @return the number expression
*/
public static NumberExpression<BigDecimal> divide(final BigDecimal dividend, final BigDecimal divisor, final int scale, final RoundingMode roundingMode) {
return divide(ConstantImpl.create(dividend), ConstantImpl.create(divisor), scale, roundingMode);
}
/**
* Divide.
*
* @param dividend the dividend
* @param divisor the divisor
* @param scale the scale
* @param roundingMode the rounding mode
* @return the number expression
*/
public static NumberExpression<BigDecimal> divide(final NumberExpression<BigDecimal> dividend, final BigDecimal divisor, final int scale, final RoundingMode roundingMode) {
return divide(dividend, ConstantImpl.create(divisor), scale, roundingMode);
}
/**
* Divide.
*
* @param dividend the dividend
* @param divisor the divisor
* @param scale the scale
* @param roundingMode the rounding mode
* @return the number expression
*/
public static NumberExpression<BigDecimal> divide(final BigDecimal dividend, final NumberExpression<BigDecimal> divisor, final int scale, final RoundingMode roundingMode) {
return divide(ConstantImpl.create(dividend), divisor, scale, roundingMode);
}
/**
* Divide.
*
* @param dividend the dividend
* @param divisor the divisor
* @param scale the scale
* @param roundingMode the rounding mode
* @return the number expression
*/
public static NumberExpression<BigDecimal> divide(final Expression<BigDecimal> dividend, final Expression<BigDecimal> divisor, final int scale, final RoundingMode roundingMode) {
return Expressions.numberTemplate(BigDecimal.class, DIVIDE, dividend, divisor, scale, roundingMode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment