Java Code Examples for java.math.BigDecimal#max()
The following examples show how to use
java.math.BigDecimal#max() .
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
Source File: LifxMessageUtil.java From smarthome with Eclipse Public License 2.0 | 6 votes |
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 File: BigDecimalTest.java From litemall with MIT License | 5 votes |
@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
Source File: BigMatrixImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: BigMatrixImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: Math_98_BigMatrixImpl_t.java From coming with MIT License | 5 votes |
/** * 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 File: Math_98_BigMatrixImpl_s.java From coming with MIT License | 5 votes |
/** * 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 7
Source File: 1_BigMatrixImpl.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * 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 8
Source File: 1_BigMatrixImpl.java From SimFix with GNU General Public License v2.0 | 5 votes |
/** * 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
Source File: VectorMaxAggregation.java From geowave with Apache License 2.0 | 5 votes |
@Override protected BigDecimal agg(BigDecimal a, BigDecimal b) { if (a == null) { return b; } else if (b == null) { return a; } return a.max(b); }
Example 10
Source File: TwoValidDigitsTest.java From spring-boot-cookbook with Apache License 2.0 | 5 votes |
@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 11
Source File: BigMatrixImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 12
Source File: BigMatrixImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 File: AlgebraicBigDecimalMathBase.java From spork with Apache License 2.0 | 5 votes |
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 14
Source File: MathLib.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@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 15
Source File: BigMatrixImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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 File: MrpServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
@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 17
Source File: AggregateNode.java From calcite with Apache License 2.0 | 4 votes |
public static BigDecimal max(BigDecimal a, BigDecimal b) { return a.max(b); }
Example 18
Source File: PropertyManagerImpl.java From cryptotrader with GNU Affero General Public License v3.0 | 3 votes |
@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; } }
Example 19
Source File: BitflyerAdviser.java From cryptotrader with GNU Affero General Public License v3.0 | 3 votes |
@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
Source File: BitflyerAdviser.java From cryptotrader with GNU Affero General Public License v3.0 | 3 votes |
@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)); }