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:org.goko.core.common.measure.quantity.AbstractQuantity.java
/** (inheritDoc) * @see org.goko.core.common.measure.quantity.Quantity#divide(org.goko.core.common.measure.quantity.Quantity) *//*from ww w . j a v a 2s . c o m*/ @Override public BigDecimal divide(Q q) { return value.divide(q.value(unit), MathContext.DECIMAL64); }
From source file:org.magicdgs.popgenlib.utils.FrequencyUtils.java
/** * Gets total counts and frequencies from a list of counts. * * <p>Note: Original counts could be recovered by multiplying each of the frequencies by the * total number of counts./*from w w w .j av a2s .com*/ * * @param counts list of counts for each category. * * @return total counts and frequencies. */ public static Pair<Integer, List<Double>> countsToFrequencies(final List<Integer> counts) { try { // verification and counting the total Verify.nonEmpty(counts, () -> "allele counts"); final int total = counts.stream().mapToInt(i -> { Verify.validate(i >= 0, () -> "counts should be larger than 0: " + i); return i; }).sum(); Verify.validate(total > 0, () -> "all counts are zero"); // compute the frequencies using BigDecimal operations final BigDecimal totalBig = new BigDecimal(total); final List<Double> freqs = new ArrayList<>(counts.size()); for (final double c : counts) { if (c == 0) { freqs.add(FREQUENCY_ZERO); } else { freqs.add(new BigDecimal(c).divide(totalBig, MathContext.DECIMAL64).doubleValue()); } } // return a pair return Pair.create(total, freqs); } catch (IllegalArgumentException e) { throw new IllegalFrequencyException(e); } }
From source file:org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from w w w .j a v a2s.c o m*/ 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); account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); 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(); }
From source file:org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override//from www . j a va2 s .c o m public CommandProcessingResult activateRDAccount(final Long savingsId, final JsonCommand command) { boolean isRegularTransaction = false; final AppUser user = this.context.authenticatedUser(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); this.depositAccountTransactionDataValidator.validateActivation(command); final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler .assembleFrom(savingsId, DepositAccountType.RECURRING_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) { this.depositAccountDomainService.handleRDDeposit(account, fmt, account.getActivationLocalDate(), amountForDeposit.getAmount(), null, isRegularTransaction); } else { final boolean isExceptionForBalanceCheck = false; final SavingsAccount fromSavingsAccount = null; 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); } updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); } final MathContext mc = MathContext.DECIMAL64; // submitted and activation date are different then recalculate // maturity date and schedule if (!account.accountSubmittedAndActivationOnSameDate()) { final boolean isPreMatureClosure = false; final CalendarInstance calendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(savingsId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); final Calendar calendar = calendarInstance.getCalendar(); final PeriodFrequencyType frequencyType = CalendarFrequencyType .from(CalendarUtils.getFrequency(calendar.getRecurrence())); Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency, calendar); account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } final LocalDate overdueUptoDate = DateUtils.getLocalDateOfTenant(); account.updateOverduePayments(overdueUptoDate); 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); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); 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(); }
From source file:org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult undoRDTransaction(final Long savingsId, final Long transactionId, final boolean allowAccountTransferModification) { final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler .assembleFrom(savingsId, DepositAccountType.RECURRING_DEPOSIT); final Set<Long> existingTransactionIds = new HashSet<>(); final Set<Long> existingReversedTransactionIds = new HashSet<>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository .findOneByIdAndSavingsAccountId(transactionId, savingsId); if (savingsAccountTransaction == null) { throw new SavingsAccountTransactionNotFoundException(savingsId, transactionId); }//w ww .j a v a 2s.co m if (!allowAccountTransferModification && this.accountTransfersReadPlatformService .isAccountTransfer(transactionId, PortfolioAccountType.SAVINGS)) { throw new PlatformServiceUnavailableException( "error.msg.recurring.deposit.account.transfer.transaction.update.not.allowed", "Recurring deposit account transaction:" + transactionId + " update not allowed as it involves in account transfer", transactionId); } final LocalDate today = DateUtils.getLocalDateOfTenant(); final MathContext mc = MathContext.DECIMAL64; if (account.isNotActive()) { throwValidationForActiveStatus(SavingsApiConstants.undoTransactionAction); } account.undoTransaction(transactionId); boolean isInterestTransfer = false; checkClientOrGroupActive(account); if (savingsAccountTransaction.isPostInterestCalculationRequired() && account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) { account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } else { account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.undoTransactionAction); // account.activateAccountBasedOnBalance(); final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); final LocalDate overdueUptoDate = DateUtils.getLocalDateOfTenant(); if (savingsAccountTransaction.isDeposit()) { account.updateScheduleInstallments(); } account.updateOverduePayments(overdueUptoDate); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); }
From source file:org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from w ww. j a v a 2s . c om*/ 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; final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(savingsAccountCharge.getDueLocalDate())) { 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); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.waiveChargeTransactionAction); this.savingAccountRepository.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:org.mifosplatform.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; final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(transactionDate)) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } else {/* w w w .j a v a 2s . c om*/ final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); } account.validateAccountBalanceDoesNotBecomeNegative( "." + SavingsAccountTransactionType.PAY_CHARGE.getCode()); this.savingAccountRepository.save(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); }
From source file:org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/* w w w . j a v a2s .c o m*/ public CommandProcessingResult activate(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); this.savingsAccountTransactionDataValidator.validateActivation(command); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); checkClientOrGroupActive(account); final Set<Long> existingTransactionIds = new HashSet<Long>(); final Set<Long> existingReversedTransactionIds = new HashSet<Long>(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final Map<String, Object> changes = account.activate(user, command, DateUtils.getLocalDateOfTenant()); if (!changes.isEmpty()) { final MathContext mc = MathContext.DECIMAL64; if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.postInterest(mc, today); } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); 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(); }
From source file:org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
@Override public SavingsAccountTransaction initiateSavingsTransfer(final Long accountId, final LocalDate transferDate) { final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId); final Set<Long> existingTransactionIds = new HashSet<Long>(); final Set<Long> existingReversedTransactionIds = new HashSet<Long>(); updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransaction newTransferTransaction = SavingsAccountTransaction .initiateTransfer(savingsAccount, savingsAccount.office(), transferDate); savingsAccount.getTransactions().add(newTransferTransaction); savingsAccount.setStatus(SavingsAccountStatusType.TRANSFER_IN_PROGRESS.getValue()); final MathContext mc = MathContext.DECIMAL64; savingsAccount.calculateInterestUsing(mc, transferDate); this.savingsAccountTransactionRepository.save(newTransferTransaction); this.savingAccountRepository.save(savingsAccount); postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds); return newTransferTransaction; }
From source file:org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
@Override public SavingsAccountTransaction withdrawSavingsTransfer(final Long accountId, final LocalDate transferDate) { final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(accountId); final Set<Long> existingTransactionIds = new HashSet<Long>(); final Set<Long> existingReversedTransactionIds = new HashSet<Long>(); updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds); final SavingsAccountTransaction withdrawtransferTransaction = SavingsAccountTransaction .withdrawTransfer(savingsAccount, savingsAccount.office(), transferDate); savingsAccount.getTransactions().add(withdrawtransferTransaction); savingsAccount.setStatus(SavingsAccountStatusType.ACTIVE.getValue()); final MathContext mc = MathContext.DECIMAL64; savingsAccount.calculateInterestUsing(mc, transferDate); this.savingsAccountTransactionRepository.save(withdrawtransferTransaction); this.savingAccountRepository.save(savingsAccount); postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds); return withdrawtransferTransaction; }