List of usage examples for java.math MathContext DECIMAL64
MathContext DECIMAL64
To view the source code for java.math MathContext DECIMAL64.
Click Source Link
From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Override public SavingsAccountTransaction acceptSavingsTransfer(final Long accountId, final LocalDate transferDate, final Office acceptedInOffice, final Staff fieldOfficer, final DepositAccountType depositAccountType) { AppUser user = getAppUserIfPresent(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(accountId, depositAccountType);/* w w w. j a v a2s . c o m*/ final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransaction acceptTransferTransaction = SavingsAccountTransaction .approveTransfer(savingsAccount, acceptedInOffice, transferDate, user); savingsAccount.addTransaction(acceptTransferTransaction); savingsAccount.setStatus(SavingsAccountStatusType.ACTIVE.getValue()); if (fieldOfficer != null) { savingsAccount.reassignSavingsOfficer(fieldOfficer, transferDate); } boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final MathContext mc = MathContext.DECIMAL64; savingsAccount.calculateInterestUsing(mc, transferDate, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); this.savingsAccountTransactionRepository.save(acceptTransferTransaction); this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount); postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds); return acceptTransferTransaction; }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional private void payCharge(final SavingsAccountCharge savingsAccountCharge, final LocalDate transactionDate, final BigDecimal amountPaid, final DateTimeFormatter formatter, final AppUser user) { final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); // Get Savings account from savings charge final SavingsAccount account = savingsAccountCharge.savingsAccount(); this.savingAccountAssembler.assignSavingAccountHelpers(account); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); account.payCharge(savingsAccountCharge, amountPaid, transactionDate, formatter, user); boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(transactionDate)) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } else {/*from w ww .jav a 2 s . com*/ final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null; if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) { depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account); } account.validateAccountBalanceDoesNotBecomeNegative( "." + SavingsAccountTransactionType.PAY_CHARGE.getCode(), depositAccountOnHoldTransactions); this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); }
From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override// w w w . j a va2s . c o m public CommandProcessingResult waiveCharge(final Long savingsAccountId, final Long savingsAccountChargeId, @SuppressWarnings("unused") final DepositAccountType depositAccountType) { AppUser user = getAppUserIfPresent(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId); // Get Savings account from savings charge final SavingsAccount account = savingsAccountCharge.savingsAccount(); this.depositAccountAssembler.assignSavingAccountHelpers(account); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); account.waiveCharge(savingsAccountChargeId, user); boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(savingsAccountCharge.getDueLocalDate())) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null; if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) { depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.waiveChargeTransactionAction, depositAccountOnHoldTransactions); this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountChargeId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsAccountId) // .build(); }
From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional private void payCharge(final SavingsAccountCharge savingsAccountCharge, final LocalDate transactionDate, final BigDecimal amountPaid, final DateTimeFormatter formatter) { AppUser user = getAppUserIfPresent(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); // Get Savings account from savings charge final SavingsAccount account = savingsAccountCharge.savingsAccount(); this.depositAccountAssembler.assignSavingAccountHelpers(account); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); account.payCharge(savingsAccountCharge, amountPaid, transactionDate, formatter, user); boolean isInterestTransfer = false; LocalDate postInterestOnDate = null; final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(transactionDate)) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } else {// w w w . j a v a2s .co m final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate); } List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null; if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) { depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account); } account.validateAccountBalanceDoesNotBecomeNegative( "." + SavingsAccountTransactionType.PAY_CHARGE.getCode(), depositAccountOnHoldTransactions); this.savingAccountRepositoryWrapper.saveAndFlush(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
private void payActivationCharges(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth, final AppUser user) { boolean isSavingsChargeApplied = false; for (SavingsAccountCharge savingsAccountCharge : this.charges()) { if (savingsAccountCharge.isSavingsActivation()) { isSavingsChargeApplied = true; payCharge(savingsAccountCharge, savingsAccountCharge.getAmountOutstanding(getCurrency()), getActivationLocalDate(), user); }/* w ww . j a va2 s . c o m*/ } if (isSavingsChargeApplied) { final MathContext mc = MathContext.DECIMAL64; boolean isInterestTransfer = false; LocalDate postInterestAsOnDate = null; if (this.isBeforeLastPostingPeriod(getActivationLocalDate())) { final LocalDate today = DateUtils.getLocalDateOfTenant(); this.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestAsOnDate); } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); this.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestAsOnDate); } } }
From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java
/** * Computes real roots for quadratic equation of the form * {@code ax^2 + bx + c = 0}, given real coefficients {@code a}, {@code b}, * and {@code c}. If there are two distinct roots, they are returned in a * two-element array. If there is a single root or two identical roots, the * result is returned in a single-element array. If there are no real-valued * roots, the function returns a zero-length array. Note that the * discriminant {@code b*b-4*a*c} contains the potential for catastrophic * cancellation if its two terms are nearly equal, so in this case the * algorithm uses {@code BigDecimal}s and methods described by W. Kahan in * "On the Cost of Floating-Point Computation Without Extra-Precise * Arithmetic"/*from www . j a v a2 s. com*/ * (<a href="http://www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf">www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf/</a>), * which references TJ Dekker (A Floating-Point Technique for Extending the * Available Precision,? pp 234-242 in Numerische Mathematik 18, 1971). * * @param a quadratic coefficient * @param b linear coefficient * @param c constant term * @return array of distinct roots in order from least to greatest, or * zero-length array if there are no real-valued roots */ public static final double[] quadraticRoots(double a, double b, double c) { if (a == 0.0) { if (b == 0.0) { return new double[0]; } else { return new double[] { -c / b }; } } else if (b == 0.0) { if (c == 0.0) { return new double[] { 0.0 }; } else { double q = Math.sqrt(-c / a); return new double[] { -q, q }; } } else if (c == 0.0) { if (a == 0.0) { return new double[] { 0.0 }; } else { double r = -b / a; if (r < 0.0) { return new double[] { r, 0.0 }; } else { return new double[] { 0.0, r }; } } } else { double p = b * b; double q = 4.0 * a * c; double d = p - q; double sqrtD = Math.sqrt(d); double pie = 3; // see reference cited in javadoc for the origin of this number if (pie * Math.abs(d) < p + q) { BigDecimal aBD = new BigDecimal(a, MathContext.DECIMAL64); BigDecimal bBD = new BigDecimal(b, MathContext.DECIMAL64); BigDecimal cBD = new BigDecimal(c, MathContext.DECIMAL64); BigDecimal pBD = bBD.multiply(bBD); BigDecimal qBD = aBD.multiply(cBD).multiply(new BigDecimal(4, MathContext.DECIMAL64)); BigDecimal dBD = pBD.subtract(qBD); if (dBD.doubleValue() < 0) { // discriminant < 0.0 return new double[0]; } else if (dBD.doubleValue() == 0) { // discriminant is truly zero to double precision return new double[] { -b / (2.0 * a) }; } sqrtD = sqrt(dBD, MathContext.DECIMAL64).doubleValue(); } double s = -0.5 * (b + Math.signum(b) * sqrtD); double r1 = s / a; double r2 = c / s; if (r1 < r2) { return new double[] { r1, r2 }; } else if (r1 > r2) { return new double[] { r2, r1 }; } else { return new double[] { r1 }; } } }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** SQL <code>/</code> operator applied to BigDecimal values. */ public static BigDecimal divide(BigDecimal b0, BigDecimal b1) { return (b0 == null || b1 == null) ? null : b0.divide(b1, MathContext.DECIMAL64); }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** CAST(DOUBLE AS VARCHAR). */ public static String toString(double x) { if (x == 0) { return "0E0"; }/*from w ww. ja v a 2 s. co m*/ BigDecimal bigDecimal = new BigDecimal(x, MathContext.DECIMAL64).stripTrailingZeros(); final String s = bigDecimal.toString(); return s.replaceAll("0*E", "E").replace("E+", "E"); }
From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccount.java
private void payActivationCharges(final boolean isSavingsInterestPostingAtCurrentPeriodEnd, final Integer financialYearBeginningMonth, final AppUser user) { boolean isSavingsChargeApplied = false; for (SavingsAccountCharge savingsAccountCharge : this.charges()) { if (savingsAccountCharge.isSavingsActivation()) { isSavingsChargeApplied = true; payCharge(savingsAccountCharge, savingsAccountCharge.getAmountOutstanding(getCurrency()), getActivationLocalDate(), user); }//from w w w. jav a 2s . c o m } if (isSavingsChargeApplied) { final MathContext mc = MathContext.DECIMAL64; boolean isInterestTransfer = false; if (this.isBeforeLastPostingPeriod(getActivationLocalDate())) { final LocalDate today = DateUtils.getLocalDateOfTenant(); this.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); this.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } } }
From source file:org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from w w w . jav a2 s .c om*/ public CommandProcessingResult activateFDAccount(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); this.depositAccountTransactionDataValidator.validateActivation(command); final MathContext mc = MathContext.DECIMAL64; final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler .assembleFrom(savingsId, DepositAccountType.FIXED_DEPOSIT); checkClientOrGroupActive(account); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final Map<String, Object> changes = account.activate(user, command, DateUtils.getLocalDateOfTenant()); if (!changes.isEmpty()) { final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); Money amountForDeposit = account.activateWithBalance(); if (amountForDeposit.isGreaterThanZero()) { final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService .retriveSavingsLinkedAssociation(savingsId); if (portfolioAccountData == null) { final PaymentDetail paymentDetail = null; this.depositAccountDomainService.handleFDDeposit(account, fmt, account.getActivationLocalDate(), amountForDeposit.getAmount(), paymentDetail); } else { final SavingsAccount fromSavingsAccount = null; boolean isRegularTransaction = false; final boolean isExceptionForBalanceCheck = false; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO( account.getActivationLocalDate(), amountForDeposit.getAmount(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, portfolioAccountData.accountId(), account.getId(), "Account Transfer", locale, fmt, null, null, null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, account, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); } final boolean isInterestTransfer = false; if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); } final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions = null; if (account.getOnHoldFunds().compareTo(BigDecimal.ZERO) == 1) { depositAccountOnHoldTransactions = this.depositAccountOnHoldTransactionRepository .findBySavingsAccountAndReversedFalseOrderByCreatedDateAsc(account); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name(), depositAccountOnHoldTransactions); this.savingAccountRepository.save(account); } postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .with(changes) // .build(); }