private List<T> convert(Number... numbers) { List<T> list = new ArrayList<T>(numbers.length); for (int i = 0; i < numbers.length; i++) { list.add(MathUtils.cast(numbers[i], getType())); } return list; }
/** * Get the result of the operation this * right * * @param right * @return this * right */ public <N extends Number & Comparable<?>> NumberExpression<T> multiply(Expression<N> right) { return NumberOperation.create(getType(), Ops.MULT, mixin, right); }
/** * Get the difference of this and right * * @param right * @return this - right */ public <N extends Number & Comparable<?>> NumberExpression<T> subtract(Expression<N> right) { return NumberOperation.create(getType(), Ops.SUB, mixin, right); }
/** * Get the sum of this expression (aggregation) * * @return sum(this) */ public NumberExpression<T> sum() { if (sum == null) { sum = NumberOperation.create(getType(), Ops.AggOps.SUM_AGG, mixin); } return sum; }
/** * Get the absolute value of this expression * * @return abs(this) */ public NumberExpression<T> abs() { if (abs == null) { abs = NumberOperation.create(getType(), MathOps.ABS, mixin); } return abs; }
/** * Get the sum of this and right * * @param right * @return this + right */ public <N extends Number & Comparable<?>> NumberExpression<T> add(Expression<N> right) { return NumberOperation.create(getType(), Ops.ADD, mixin, right); }
/** * Get the minimum value of this expression (aggregation) * * @return min(this) */ @SuppressWarnings("unchecked") public NumberExpression<T> min() { if (min == null) { min = NumberOperation.create(getType(), Ops.AggOps.MIN_AGG, mixin); } return min; }
/** * @param num * @return */ public NumberExpression<T> mod(Expression<T> num) { return NumberOperation.create(getType(), Ops.MOD, mixin, num); }
/** * Get the negation of this expression * * @return this * -1 */ public NumberExpression<T> negate() { if (negation == null) { negation = NumberOperation.create(getType(), Ops.NEGATE, mixin); } return negation; }
@Override public NumberExpression<T> as(Path<T> alias) { return NumberOperation.create(getType(),Ops.ALIAS, mixin, alias); }
@SuppressWarnings("unchecked") @Override public <RT extends Number & Comparable<?>> NumberSubQuery<RT> unique(NumberExpression<RT> projection) { return new NumberSubQuery<RT>((Class)projection.getType(), uniqueProjection(projection)); }
/** * Get the sum of this and right * * @param right * @return this + right */ public <N extends Number & Comparable<N>> NumberExpression<T> add(N right) { return NumberOperation.create(getType(), Ops.ADD, mixin, ConstantImpl.create(right)); }
/** * @param num * @return */ public NumberExpression<T> mod(T num) { return NumberOperation.create(getType(), Ops.MOD, mixin, ConstantImpl.create(num)); }
/** * Get the result of the operation this / right * * @param right * @return this / right */ public <N extends Number & Comparable<?>> NumberExpression<T> divide(N right) { Class<?> type = getDivisionType(getType(), right.getClass()); return NumberOperation.create((Class<T>)type, Ops.DIV, mixin, ConstantImpl.create(right)); }
/** * Get the result of the operation this / right * * @param right * @return this / right */ public <N extends Number & Comparable<?>> NumberExpression<T> divide(Expression<N> right) { Class<?> type = getDivisionType(getType(), right.getType()); return NumberOperation.create((Class<T>)type, Ops.DIV, mixin, right); }
@Test public void Byte() { assertEquals(Byte.class, expr.byteValue().getType()); }
@Test public void Double() { assertEquals(Double.class, expr.doubleValue().getType()); }
@Test public void Integer() { assertEquals(Integer.class, expr.intValue().getType()); }
@Test public void Long() { assertEquals(Long.class, expr.longValue().getType()); }