Example usage for java.math MathContext DECIMAL64

List of usage examples for java.math MathContext DECIMAL64

Introduction

In this page you can find the example usage for java.math MathContext DECIMAL64.

Prototype

MathContext DECIMAL64

To view the source code for java.math MathContext DECIMAL64.

Click Source Link

Document

A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of RoundingMode#HALF_EVEN HALF_EVEN , the IEEE 754R default.

Usage

From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from w  w w  .  j ava  2s  . co m*/
public CommandProcessingResult modifyRDApplication(final Long accountId, final JsonCommand command) {
    try {
        this.depositAccountDataValidator.validateRecurringDepositForUpdate(command.json());

        final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                .isSavingsInterestPostingAtCurrentPeriodEnd();
        final Integer financialYearBeginningMonth = this.configurationDomainService
                .retrieveFinancialYearBeginningMonth();

        final Map<String, Object> changes = new LinkedHashMap<>(20);

        final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
                .assembleFrom(accountId, DepositAccountType.RECURRING_DEPOSIT);
        checkClientOrGroupActive(account);
        account.modifyApplication(command, changes);
        account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(),
                DepositAccountType.RECURRING_DEPOSIT.resourceName());

        if (!changes.isEmpty()) {
            updateFDAndRDCommonChanges(changes, command, account);
            final MathContext mc = MathContext.DECIMAL64;
            final CalendarInstance calendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId,
                            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);
            final boolean isPreMatureClosure = false;
            account.updateMaturityDateAndAmount(mc, isPreMatureClosure,
                    isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
            account.validateApplicableInterestRate();
            this.savingAccountRepository.save(account);

        }

        // update calendar details
        if (!account.isCalendarInherited()) {
            final LocalDate calendarStartDate = account.depositStartDate();
            final Integer frequencyType = command
                    .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName);
            final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType);
            final Integer frequency = command
                    .integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName);
            final Integer repeatsOnDay = calendarStartDate.getDayOfWeek();

            CalendarInstance calendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId,
                            CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());
            Calendar calendar = calendarInstance.getCalendar();
            calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType),
                    frequency, repeatsOnDay, null);
            this.calendarInstanceRepository.save(calendarInstance);
        }

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(accountId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(accountId) //
                .with(changes) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return new CommandProcessingResult(Long.valueOf(-1));
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return new CommandProcessingResult(Long.valueOf(-1));
    }
}

From source file:com.gst.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);
    }/*from w  w  w  . ja v a  2  s .com*/

    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;
    LocalDate postInterestOnDate = null;
    checkClientOrGroupActive(account);
    if (savingsAccountTransaction.isPostInterestCalculationRequired()
            && account.isBeforeLastPostingPeriod(savingsAccountTransaction.transactionLocalDate())) {
        account.postInterest(mc, today, isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth, postInterestOnDate);
    } else {
        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.undoTransactionAction,
            depositAccountOnHoldTransactions);
    // 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);

    this.savingAccountRepositoryWrapper.saveAndFlush(account);
    postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds);

    return new CommandProcessingResultBuilder() //
            .withEntityId(savingsId) //
            .withOfficeId(account.officeId()) //
            .withClientId(account.clientId()) //
            .withGroupId(account.groupId()) //
            .withSavingsId(savingsId) //
            .build();
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public SavingsAccountTransaction initiateSavingsTransfer(final SavingsAccount savingsAccount,
        final LocalDate transferDate) {

    AppUser user = getAppUserIfPresent();

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();
    this.savingAccountAssembler.setHelpers(savingsAccount);
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction newTransferTransaction = SavingsAccountTransaction
            .initiateTransfer(savingsAccount, savingsAccount.office(), transferDate, user);
    savingsAccount.addTransaction(newTransferTransaction);
    savingsAccount.setStatus(SavingsAccountStatusType.TRANSFER_IN_PROGRESS.getValue());
    final MathContext mc = MathContext.DECIMAL64;
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    savingsAccount.calculateInterestUsing(mc, transferDate, isInterestTransfer,
            isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);

    this.savingsAccountTransactionRepository.save(newTransferTransaction);
    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);

    postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    return newTransferTransaction;
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public SavingsAccountTransaction withdrawSavingsTransfer(final SavingsAccount savingsAccount,
        final LocalDate transferDate) {

    AppUser user = getAppUserIfPresent();

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();
    this.savingAccountAssembler.setHelpers(savingsAccount);
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction withdrawtransferTransaction = SavingsAccountTransaction
            .withdrawTransfer(savingsAccount, savingsAccount.office(), transferDate, user);
    savingsAccount.addTransaction(withdrawtransferTransaction);
    savingsAccount.setStatus(SavingsAccountStatusType.ACTIVE.getValue());
    final MathContext mc = MathContext.DECIMAL64;
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    savingsAccount.calculateInterestUsing(mc, transferDate, isInterestTransfer,
            isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);

    this.savingsAccountTransactionRepository.save(withdrawtransferTransaction);
    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);

    postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    return withdrawtransferTransaction;
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public SavingsAccountTransaction acceptSavingsTransfer(final SavingsAccount savingsAccount,
        final LocalDate transferDate, final Office acceptedInOffice, final Staff fieldOfficer) {

    AppUser user = getAppUserIfPresent();

    final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
            .isSavingsInterestPostingAtCurrentPeriodEnd();
    final Integer financialYearBeginningMonth = this.configurationDomainService
            .retrieveFinancialYearBeginningMonth();
    this.savingAccountAssembler.setHelpers(savingsAccount);
    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);
    }/*from www  .  ja  v  a 2 s  .  co m*/
    boolean isInterestTransfer = false;
    final MathContext mc = MathContext.DECIMAL64;
    LocalDate postInterestOnDate = null;
    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.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public SavingsAccountTransaction initiateSavingsTransfer(final Long accountId, final LocalDate transferDate,
        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);//from   w w  w  .j a  va2  s.com
    final LocalDate postInterestOnDate = null;
    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction newTransferTransaction = SavingsAccountTransaction
            .initiateTransfer(savingsAccount, savingsAccount.office(), transferDate, user);
    savingsAccount.addTransaction(newTransferTransaction);
    savingsAccount.setStatus(SavingsAccountStatusType.TRANSFER_IN_PROGRESS.getValue());
    final MathContext mc = MathContext.DECIMAL64;
    boolean isInterestTransfer = false;
    savingsAccount.calculateInterestUsing(mc, transferDate, isInterestTransfer,
            isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);

    this.savingsAccountTransactionRepository.save(newTransferTransaction);
    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);

    postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    return newTransferTransaction;
}

From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from   w w w .j  av  a2s . c o  m*/
public CommandProcessingResult waiveCharge(final Long savingsAccountId, final Long savingsAccountChargeId) {

    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.savingAccountAssembler.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:net.pms.util.Rational.java

/**
 * Converts this {@link Rational} to a {@code double}. This conversion is
 * similar to the <i>narrowing primitive conversion</i> from {@code double}
 * to {@code float} as defined in section 5.1.3 of <cite>The Java&trade;
 * Language Specification</cite>: if this {@link Rational} has too great a
 * magnitude to represent as a {@code double}, it will be converted to
 * {@link Double#NEGATIVE_INFINITY} or {@link Double#POSITIVE_INFINITY} as
 * appropriate./*from   www.j a  v  a  2s  .  c o  m*/
 * <p>
 * Note that even when the return value is finite, this conversion can lose
 * information about the precision of the {@link Rational} value.
 *
 * @return This {@link Rational} converted to a {@code double}.
 */
@Override
public double doubleValue() {
    if (isNaN()) {
        return Double.NaN;
    }
    if (isInfinitePositive()) {
        return Double.POSITIVE_INFINITY;
    }
    if (isInfiniteNegative()) {
        return Double.NEGATIVE_INFINITY;
    }
    return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), MathContext.DECIMAL64)
            .doubleValue();
}

From source file:com.gst.portfolio.savings.service.DepositAccountWritePlatformServiceJpaRepositoryImpl.java

@Override
public SavingsAccountTransaction withdrawSavingsTransfer(final Long accountId, final LocalDate transferDate,
        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);//from ww  w .  j  a v  a  2  s .co m

    final Set<Long> existingTransactionIds = new HashSet<>();
    final Set<Long> existingReversedTransactionIds = new HashSet<>();
    updateExistingTransactionsDetails(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    final SavingsAccountTransaction withdrawtransferTransaction = SavingsAccountTransaction
            .withdrawTransfer(savingsAccount, savingsAccount.office(), transferDate, user);
    savingsAccount.addTransaction(withdrawtransferTransaction);
    savingsAccount.setStatus(SavingsAccountStatusType.ACTIVE.getValue());
    final MathContext mc = MathContext.DECIMAL64;
    boolean isInterestTransfer = false;
    LocalDate postInterestOnDate = null;
    savingsAccount.calculateInterestUsing(mc, transferDate, isInterestTransfer,
            isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth, postInterestOnDate);

    this.savingsAccountTransactionRepository.save(withdrawtransferTransaction);
    this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount);

    postJournalEntries(savingsAccount, existingTransactionIds, existingReversedTransactionIds);

    return withdrawtransferTransaction;
}

From source file:ca.uhn.fhir.jpa.dao.SearchBuilder.java

private Predicate createPredicateNumeric(CriteriaBuilder builder, IQueryParameterType params,
        ParamPrefixEnum cmpValue, BigDecimal valueValue, final Expression<BigDecimal> path,
        String invalidMessageName, String theValueString) {
    Predicate num;//  w w  w . j a  v  a2 s  .com
    switch (cmpValue) {
    case GREATERTHAN:
        num = builder.gt(path, valueValue);
        break;
    case GREATERTHAN_OR_EQUALS:
        num = builder.ge(path, valueValue);
        break;
    case LESSTHAN:
        num = builder.lt(path, valueValue);
        break;
    case LESSTHAN_OR_EQUALS:
        num = builder.le(path, valueValue);
        break;
    case APPROXIMATE:
    case EQUAL:
    case NOT_EQUAL:
        BigDecimal mul = calculateFuzzAmount(cmpValue, valueValue);
        BigDecimal low = valueValue.subtract(mul, MathContext.DECIMAL64);
        BigDecimal high = valueValue.add(mul, MathContext.DECIMAL64);
        Predicate lowPred;
        Predicate highPred;
        if (cmpValue != ParamPrefixEnum.NOT_EQUAL) {
            lowPred = builder.ge(path.as(BigDecimal.class), low);
            highPred = builder.le(path.as(BigDecimal.class), high);
            num = builder.and(lowPred, highPred);
            ourLog.trace("Searching for {} <= val <= {}", low, high);
        } else {
            // Prefix was "ne", so reverse it!
            lowPred = builder.lt(path.as(BigDecimal.class), low);
            highPred = builder.gt(path.as(BigDecimal.class), high);
            num = builder.or(lowPred, highPred);
        }
        break;
    default:
        String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, invalidMessageName,
                cmpValue.getValue(), params.getValueAsQueryToken(myContext));
        throw new InvalidRequestException(msg);
    }
    return num;
}