Java Code Examples for java.math.BigDecimal#max()

The following examples show how to use java.math.BigDecimal#max() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static PercentType increaseDecreasePercentType(IncreaseDecreaseType increaseDecreaseType, PercentType old) {
    BigDecimal delta = ZERO;
    if (increaseDecreaseType == IncreaseDecreaseType.INCREASE) {
        delta = INCREASE_DECREASE_STEP;
    } else if (increaseDecreaseType == IncreaseDecreaseType.DECREASE) {
        delta = INCREASE_DECREASE_STEP.negate();
    }

    if (!ZERO.equals(delta)) {
        BigDecimal newValue = old.toBigDecimal().add(delta);
        newValue = newValue.setScale(0, RoundingMode.HALF_UP);
        newValue = newValue.min(HUNDRED);
        newValue = newValue.max(ZERO);
        return new PercentType(newValue);
    } else {
        return old;
    }
}
 
Example 2
Source Project: litemall   File: BigDecimalTest.java    License: MIT License 5 votes vote down vote up
@Test
public void test() {
    BigDecimal a = new BigDecimal(0);
    BigDecimal b = new BigDecimal(1);
    BigDecimal c = a.subtract(b);
    BigDecimal d = c.max(new BigDecimal(0));

    System.out.println(c);
    System.out.println(d);
}
 
Example 3
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 4
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 5
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 6
Source Project: geowave   File: VectorMaxAggregation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected BigDecimal agg(BigDecimal a, BigDecimal b) {
  if (a == null) {
    return b;
  } else if (b == null) {
    return a;
  }
  return a.max(b);
}
 
Example 7
@Test
public void bigDecimalMaxValue() {
    BigDecimal data1 = new BigDecimal("1.2");
    BigDecimal data2 = new BigDecimal("1.5");
    BigDecimal max = data1.max(data2);
    System.out.println(max);
    assertThat(max).isEqualTo(data2);
    max = data2.max(data1);
    System.out.println(max);
    assertThat(max).isEqualTo(data2);
}
 
Example 8
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 9
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 10
private static BigDecimal doWork(BigDecimal arg1, BigDecimal arg2, KNOWN_OP op) {
    if (arg1 == null) {
        return arg2;
    } else if (arg2 == null) {
        return arg1;
    } else {
        BigDecimal retVal = null;
        switch (op) {
        case SUM:
            retVal = arg1.add(arg2);
            break;
        case MAX:
            if (BigDecimalWrapper.class.isInstance(arg1) && (((BigDecimalWrapper)arg1).isNegativeInfinity())) {
                retVal = arg2;
            } else if (BigDecimalWrapper.class.isInstance(arg2) && (((BigDecimalWrapper)arg2).isNegativeInfinity())) {
                retVal = arg1;
            } else {
                retVal = arg1.max(arg2);
            }
            break;
        case MIN:
            if (BigDecimalWrapper.class.isInstance(arg1) && (((BigDecimalWrapper)arg1).isPositiveInfinity())) {
                retVal = arg2;
            } else if (BigDecimalWrapper.class.isInstance(arg2) && (((BigDecimalWrapper)arg2).isPositiveInfinity())) {
                retVal = arg1;
            } else {
                retVal = arg1.min(arg2);
            }
            break;
        default:
            retVal = null;
            break;
        }
        return retVal;
    }
}
 
Example 11
@TLFunctionAnnotation("Returns max value of the arguments.")
public static final BigDecimal max(TLFunctionCallContext context, BigDecimal a, BigDecimal b) {
	if (a==null){
		return b;
	}else{
		if (b==null){
			return a;
		}
		else{
			return a.max(b);
		}
	}
}
 
Example 12
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 13
Source Project: coming   File: Math_98_BigMatrixImpl_s.java    License: MIT License 5 votes vote down vote up
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 14
Source Project: coming   File: Math_98_BigMatrixImpl_t.java    License: MIT License 5 votes vote down vote up
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 15
/**
 * Returns the <a href="http://mathworld.wolfram.com/MaximumAbsoluteRowSumNorm.html">
 * maximum absolute row sum norm</a> of the matrix.
 *
 * @return norm
 */
public BigDecimal getNorm() {
    BigDecimal maxColSum = ZERO;
    for (int col = 0; col < this.getColumnDimension(); col++) {
        BigDecimal sum = ZERO;
        for (int row = 0; row < this.getRowDimension(); row++) {
            sum = sum.add(data[row][col].abs());
        }
        maxColSum = maxColSum.max(sum);
    }
    return maxColSum;
}
 
Example 16
Source Project: calcite   File: AggregateNode.java    License: Apache License 2.0 4 votes vote down vote up
public static BigDecimal max(BigDecimal a, BigDecimal b) {
  return a.max(b);
}
 
Example 17
@Transactional(rollbackOn = {Exception.class})
protected boolean checkInsufficientCumulativeQty(
    MrpLine mrpLine, Product product, boolean firstPass) throws AxelorException {

  BigDecimal cumulativeQty = mrpLine.getCumulativeQty();

  MrpLineType mrpLineType = mrpLine.getMrpLineType();

  boolean isProposalElement = this.isProposalElement(mrpLineType);

  BigDecimal minQty = mrpLine.getMinQty();

  if ((((mrpLine.getMrpLineType().getElementSelect()
                  != MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK)
              && (!isProposalElement
                  || mrpLineType.getTypeSelect() == MrpLineTypeRepository.TYPE_OUT))
          || (mrpLine.getMrpLineType().getElementSelect()
                  == MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK
              && firstPass))
      && cumulativeQty.compareTo(mrpLine.getMinQty()) < 0) {

    log.debug(
        "Cumulative qty ({} < {}) is insufficient for product ({}) at the maturity date ({})",
        cumulativeQty,
        minQty,
        product.getFullName(),
        mrpLine.getMaturityDate());

    BigDecimal reorderQty = minQty.subtract(cumulativeQty);

    StockRules stockRules =
        stockRulesService.getStockRules(
            product,
            mrpLine.getStockLocation(),
            StockRulesRepository.TYPE_FUTURE,
            StockRulesRepository.USE_CASE_USED_FOR_MRP);

    if (stockRules != null) {
      reorderQty = reorderQty.max(stockRules.getReOrderQty());
    }

    MrpLineType mrpLineTypeProposal = this.getMrpLineTypeForProposal(stockRules, product);

    long duplicateCount =
        mrpLineRepository
            .all()
            .filter(
                "self.mrp.id = ?1  AND self.isEditedByUser = ?2 AND self.product = ?3 AND self.relatedToSelectName = ?4",
                mrp.getId(),
                true,
                product,
                mrpLine.getRelatedToSelectName())
            .count();

    if (duplicateCount != 0) {
      return false;
    }

    this.createProposalMrpLine(
        mrpLine.getMrp(),
        product,
        mrpLineTypeProposal,
        reorderQty,
        mrpLine.getStockLocation(),
        mrpLine.getMaturityDate(),
        mrpLine.getMrpLineOriginList(),
        mrpLine.getRelatedToSelectName());

    return true;
  }

  return false;
}
 
Example 18
@VisibleForTesting
BigDecimal calculateDualSfdRate(Context context, Request request, boolean buy) {

    BigDecimal rate = trimToZero(calculateSfdRate(context, request, buy));

    BigDecimal inversePct = getDecimalProperty(KEY_SFD_INV, ZERO);

    BigDecimal inverseRate = trimToZero(calculateSfdRate(context, request, !buy));

    return rate.max(inverseRate.multiply(inversePct));

}
 
Example 19
@Override
protected BigDecimal adjustSellBoundaryPrice(Context context, Request request, BigDecimal price) {

    if (price == null) {
        return null;
    }

    Key key = getUnderlyingKey(request);

    if (key == null) {
        return price;
    }

    BigDecimal ask = context.getBestAskPrice(key);

    BigDecimal comm = context.getCommissionRate(key);

    BigDecimal spread = request.getTradingSpread();

    BigDecimal dailyRate = getDecimalProperty(KEY_SWAP_S, SWAP_RATE);

    BigDecimal swap = calculateSwapRate(context, request, dailyRate);

    if (ask == null || comm == null || swap == null) {
        return null;
    }

    BigDecimal theoretical = ask.multiply(ONE.add(comm).add(spread).add(swap));

    return price.max(theoretical);

}
 
Example 20
@VisibleForTesting
BigDecimal getDecimal(String site, String instrument,
                      PropertyType type, BigDecimal min, BigDecimal max, BigDecimal defaultValue) {

    try {

        BigDecimal value = get(type, site, instrument, Configuration::getBigDecimal);

        BigDecimal adjusted = value;

        if (min != null) {
            adjusted = adjusted.max(min);
        }

        if (max != null) {
            adjusted = adjusted.min(max);
        }

        log.trace("Fetched {} ({}.{}) : {} -> {}", type, site, instrument, value, adjusted);

        return adjusted;

    } catch (RuntimeException e) {

        log.warn(format("Invalid %s (%s.%s)", type, site, instrument), e);

        return defaultValue;

    }

}