List of usage examples for java.math BigDecimal ONE
BigDecimal ONE
To view the source code for java.math BigDecimal ONE.
Click Source Link
From source file:org.finra.dm.service.helper.DmHelperTest.java
/** * Tests case where validation is run against the definition generated by createValidEmrClusterDefinition() The master instance max search price and * on-demand threshold is specified The definition should be valid because on-demand threshold can be used with max search price. *//* www. j a v a 2s.c o m*/ @Test public void testValidateEmrClusterDefinitionConfigurationMasterMaxSearchPriceAndOnDemandThresholdSpecified() { EmrClusterDefinition emrClusterDefinition = createValidEmrClusterDefinition(); emrClusterDefinition.getInstanceDefinitions().getMasterInstances() .setInstanceMaxSearchPrice(BigDecimal.ONE); emrClusterDefinition.getInstanceDefinitions().getMasterInstances() .setInstanceOnDemandThreshold(BigDecimal.ONE); try { dmHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); } catch (Exception e) { fail("expected no exception, but " + e.getClass() + " was thrown. " + e); } }
From source file:org.kuali.kfs.module.ar.document.service.impl.ContractsGrantsInvoiceDocumentServiceImpl.java
/** * @param docNum/*from ww w .jav a 2 s. c o m*/ * @param coaCode * @param acctNum * @param obCode * @param totalAmount * @param seqNum * @return */ protected CustomerInvoiceDetail createSourceAccountingLine(String docNum, String coaCode, String acctNum, String obCode, KualiDecimal totalAmount, Integer seqNum) { CustomerInvoiceDetail cid = new CustomerInvoiceDetail(); cid.setDocumentNumber(docNum); cid.setAccountNumber(acctNum); cid.setChartOfAccountsCode(coaCode); cid.setFinancialObjectCode(obCode); cid.setSequenceNumber(seqNum); cid.setInvoiceItemQuantity(BigDecimal.ONE); cid.setInvoiceItemUnitOfMeasureCode(ArConstants.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT); cid.setInvoiceItemUnitPrice(totalAmount); cid.setAmount(totalAmount); if (totalAmount.isNegative()) { cid.setInvoiceItemDiscountLineNumber(seqNum); } // To get AR Object codes for the GLPEs .... as it is not being called implicitly.. cid.setAccountsReceivableObjectCode( getAccountsReceivablePendingEntryService().getAccountsReceivableObjectCode(cid)); return cid; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java
private BigDecimal getNotTaughtSummaries(Professorship professorship, Shift shift, BigDecimal notTaughtSummaries, LocalDate oneWeekBeforeToday) { for (Summary summary : shift.getAssociatedSummariesSet()) { if (summary.getProfessorship() != null && summary.getProfessorship() == professorship && !summary.getIsExtraLesson() && !summary.getLessonInstance().getBeginDateTime().toLocalDate().isAfter(oneWeekBeforeToday)) { if (summary.getTaught() != null && summary.getTaught() == false) { notTaughtSummaries = notTaughtSummaries.add(BigDecimal.ONE); }/*w w w . jav a2s . com*/ } } return notTaughtSummaries; }
From source file:org.apache.torque.oid.IDBroker.java
/** * Grabs more ids from the id_table and stores it in the ids * Hashtable. If adjustQuantity is set to true the amount of id's * retrieved for each call to storeIDs will be adjusted. * * @param tableName The name of the table for which we want an id. * @param adjustQuantity True if amount should be adjusted. * @param connection a Connection/*from ww w. ja v a 2 s.c om*/ * @exception on a database error. */ private synchronized void storeIDs(String tableName, boolean adjustQuantity, Connection connection) throws TorqueException { log.debug("storeIDs(): Start retrieving ids from database."); BigDecimal nextId = null; BigDecimal quantity = null; // Block on the table. Multiple tables are allowed to ask for // ids simultaneously. // TableMap tMap = dbMap.getTable(tableName); // synchronized(tMap) see comment in the getNextIds method // { if (adjustQuantity) { checkTiming(tableName); } boolean useNewConnection = (connection == null) || (configuration.getBoolean(DB_IDBROKER_USENEWCONNECTION, true)); try { if (useNewConnection) { connection = Transaction.begin(databaseName); if (log.isTraceEnabled()) { log.trace("storeIDs(): fetched connection, " + "started transaction."); } } // Write the current value of quantity of keys to grab // to the database, primarily to obtain a write lock // on the table/row, but this value will also be used // as the starting value when an IDBroker is // instantiated. quantity = getQuantity(tableName, connection); updateQuantity(connection, tableName, quantity); // Read the next starting ID from the ID_TABLE. BigDecimal[] results = selectRow(connection, tableName); nextId = results[0]; // NEXT_ID column // Update the row based on the quantity in the // ID_TABLE. BigDecimal newNextId = nextId.add(quantity); updateNextId(connection, tableName, newNextId.toString()); if (useNewConnection) { Transaction.commit(connection); if (log.isTraceEnabled()) { log.trace("storeIDs(): Transaction committed, " + "connection returned"); } } } catch (TorqueException e) { if (useNewConnection) { Transaction.safeRollback(connection); } throw e; } List<BigDecimal> availableIds = ids.get(tableName); if (availableIds == null) { availableIds = new ArrayList<BigDecimal>(); ids.put(tableName, availableIds); } // Create the ids and store them in the list of available ids. int numId = quantity.intValue(); for (int i = 0; i < numId; i++) { availableIds.add(nextId); nextId = nextId.add(BigDecimal.ONE); } // } }
From source file:org.yes.cart.service.payment.impl.PaymentProcessorImpl.java
/** * Calculate delivery amount according to shipment sla cost and items in particular delivery. * * @param order order/*from w w w .j ava 2 s . c om*/ * @param delivery delivery * @param payment payment */ private void fillPaymentAmount(final CustomerOrder order, final CustomerOrderDelivery delivery, final Payment payment) { BigDecimal rez = BigDecimal.ZERO.setScale(Constants.DEFAULT_SCALE); for (PaymentLine paymentLine : payment.getOrderItems()) { if (paymentLine.isShipment()) { // shipping price already includes shipping level promotions rez = rez.add(paymentLine.getUnitPrice()).setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } else { // unit price already includes item level promotions rez = rez.add(paymentLine.getQuantity().multiply(paymentLine.getUnitPrice()) .setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP)); } } if (order.isPromoApplied()) { // work out the percentage of order level promotion per delivery // work out the real sub total using item promotional prices // DO NOT use the order.getListPrice() as this is the list price in catalog and we calculate // promotions against sale price BigDecimal orderTotalList = BigDecimal.ZERO; for (final CustomerOrderDet detail : order.getOrderDetail()) { orderTotalList = orderTotalList.add(detail.getQty().multiply(detail.getGrossPrice()) .setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP)); } final BigDecimal orderTotal = order.getGrossPrice(); // take the list price (sub total of items using list price) final BigDecimal discount = orderTotalList.subtract(orderTotal).divide(orderTotalList, 10, RoundingMode.HALF_UP); // scale delivery items total in accordance with order level discount percentage rez = rez.multiply(BigDecimal.ONE.subtract(discount)).setScale(Constants.DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } payment.setPaymentAmount(rez); payment.setOrderCurrency(order.getCurrency()); payment.setOrderLocale(order.getLocale()); }
From source file:org.marketcetera.marketdata.csv.BasicCSVFeedEventTranslator.java
/** * Guesses the contract multiplier of the given data line. * * @param inData a <code>CSVQuantum</code> value * @param inOption an <code>Option</code> value * @return a <code>BigDecimal</code> value or <code>null</code> * @throws CoreException if the given data cannot be interpreted as a <code>BigDecimal</code> value *///from w w w . ja va 2 s. c o m protected BigDecimal guessMultiplier(CSVQuantum inData, Option inOption) throws CoreException { return BigDecimal.ONE; }
From source file:org.openvpms.esci.adapter.map.invoice.InvoiceMapperImpl.java
/** * Verifies that the invoice line item's <em>PackQuantity</em> is specified correctly, if present. * * @param line the invoice line// w ww . j ava2 s .c o m * @param unitCode the expected unit code */ private void checkPackQuantity(UBLInvoiceLine line, String unitCode) { BigDecimal quantity = line.getPackQuantity(); if (quantity != null) { if (quantity.compareTo(BigDecimal.ONE) != 0) { ErrorContext context = new ErrorContext(line, "PackQuantity"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), "1", quantity.toString())); } String packageUnits = line.getPackQuantityUnitCode(); if (packageUnits != null && !ObjectUtils.equals(unitCode, packageUnits)) { ErrorContext context = new ErrorContext(line, "PackQuantity@unitCode"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), unitCode, packageUnits)); } } }
From source file:org.efaps.esjp.accounting.transaction.Recalculate_Base.java
/** * @param _parameter Parameter as passed by the eFasp API * @return new Return/*from www . j a v a 2s. c o m*/ * @throws EFapsException on error */ public Return createGainLoss4SimpleAccount(final Parameter _parameter) throws EFapsException { final PrintQuery printPer = new PrintQuery(_parameter.getInstance()); final SelectBuilder selCurrInst = SelectBuilder.get().linkto(CIAccounting.Period.CurrencyLink).instance(); printPer.addSelect(selCurrInst); printPer.addAttribute(CIAccounting.Period.FromDate, CIAccounting.Period.CurrencyLink); printPer.execute(); final DateTime dateFrom = printPer.<DateTime>getAttribute(CIAccounting.Period.FromDate); final Instance currencyInst = printPer.<Instance>getSelect(selCurrInst); final String[] relOIDs = (String[]) Context.getThreadContext() .getSessionAttribute(CIFormAccounting.Accounting_GainLoss4SimpleAccountForm.config2period.name); final DateTime dateTo = new DateTime(_parameter .getParameterValue(CIFormAccounting.Accounting_GainLoss4SimpleAccountForm.transactionDate.name)); final DateTime dateEx = new DateTime(_parameter .getParameterValue(CIFormAccounting.Accounting_GainLoss4SimpleAccountForm.exchangeDate.name)); Insert insert = null; BigDecimal totalSum = BigDecimal.ZERO; for (final String oid : relOIDs) { Instance tarCurInst = null; final Instance relInst = Instance.get(oid); final PrintQuery print = new PrintQuery(relInst); final SelectBuilder selAccount = new SelectBuilder() .linkto(CIAccounting.AccountConfigSimple2Period.FromLink).oid(); print.addSelect(selAccount); print.addAttribute(CIAccounting.AccountConfigSimple2Period.IsSale); if (print.execute()) { final Instance instAcc = Instance.get(print.<String>getSelect(selAccount)); final boolean isSale = print.<Boolean>getAttribute(CIAccounting.AccountConfigSimple2Period.IsSale); final QueryBuilder attrQuerBldr = new QueryBuilder(CIAccounting.Transaction); attrQuerBldr.addWhereAttrEqValue(CIAccounting.Transaction.PeriodLink, _parameter.getInstance()); attrQuerBldr.addWhereAttrGreaterValue(CIAccounting.Transaction.Date, dateFrom.minusMinutes(1)); attrQuerBldr.addWhereAttrLessValue(CIAccounting.Transaction.Date, dateTo.plusDays(1)); final AttributeQuery attrQuery = attrQuerBldr.getAttributeQuery(CIAccounting.Transaction.ID); final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.TransactionPositionAbstract); queryBldr.addWhereAttrEqValue(CIAccounting.TransactionPositionAbstract.AccountLink, instAcc); queryBldr.addWhereAttrInQuery(CIAccounting.TransactionPositionAbstract.TransactionLink, attrQuery); final MultiPrintQuery multi = queryBldr.getPrint(); final SelectBuilder selTRInst = SelectBuilder.get() .linkto(CIAccounting.TransactionPositionAbstract.RateCurrencyLink).instance(); multi.addSelect(selTRInst); multi.addAttribute(CIAccounting.TransactionPositionAbstract.Amount, CIAccounting.TransactionPositionAbstract.RateAmount); BigDecimal gainlossSum = BigDecimal.ZERO; multi.execute(); while (multi.next()) { final BigDecimal oldRateAmount = multi .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.RateAmount); final BigDecimal oldAmount = multi .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.Amount); final Instance targetCurrInst = multi.<Instance>getSelect(selTRInst); final BigDecimal rate = evaluateRate(_parameter, dateEx, currencyInst, targetCurrInst, isSale); final BigDecimal newAmount = oldRateAmount.divide(rate, BigDecimal.ROUND_HALF_UP); BigDecimal gainloss = BigDecimal.ZERO; if (!currencyInst.equals(targetCurrInst)) { gainloss = newAmount.subtract(oldAmount); tarCurInst = targetCurrInst; } else { gainloss = newAmount; } gainlossSum = gainlossSum.add(gainloss); } totalSum = totalSum.add(gainlossSum); final Map<String, String[]> map = validateInfo(_parameter, gainlossSum); final String[] accs = map.get("accs"); final String[] check = map.get("check"); if (checkAccounts(accs, 0, check).length() > 0) { if (gainlossSum.compareTo(BigDecimal.ZERO) != 0) { final String[] accOids = map.get("accountOids"); if (insert == null) { final String descr = DBProperties.getFormatedDBProperty( Recalculate.class.getName() + ".gainLoss4SimpleAccountTransDesc", dateTo.toDate()); insert = new Insert(CIAccounting.Transaction); insert.add(CIAccounting.Transaction.Description, descr); insert.add(CIAccounting.Transaction.Date, dateTo); insert.add(CIAccounting.Transaction.PeriodLink, _parameter.getInstance()); insert.add(CIAccounting.Transaction.Status, Status.find(CIAccounting.TransactionStatus.Open)); insert.execute(); } Insert insertPos = new Insert(CIAccounting.TransactionPositionDebit); insertPos.add(CIAccounting.TransactionPositionDebit.TransactionLink, insert.getInstance()); if (gainlossSum.signum() > 0) { insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink, Instance.get(accOids[0])); } else { insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink, instAcc); } insertPos.add(CIAccounting.TransactionPositionDebit.Amount, gainlossSum.abs().negate()); insertPos.add(CIAccounting.TransactionPositionDebit.RateAmount, BigDecimal.ZERO); insertPos.add(CIAccounting.TransactionPositionDebit.CurrencyLink, currencyInst); insertPos.add(CIAccounting.TransactionPositionDebit.RateCurrencyLink, tarCurInst); insertPos.add(CIAccounting.TransactionPositionDebit.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); insertPos.execute(); insertPos = new Insert(CIAccounting.TransactionPositionCredit); insertPos.add(CIAccounting.TransactionPositionCredit.TransactionLink, insert.getInstance()); if (gainlossSum.signum() > 0) { insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink, instAcc); } else { insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink, Instance.get(accOids[0])); } insertPos.add(CIAccounting.TransactionPositionCredit.Amount, gainlossSum.abs()); insertPos.add(CIAccounting.TransactionPositionCredit.RateAmount, BigDecimal.ZERO); insertPos.add(CIAccounting.TransactionPositionCredit.CurrencyLink, currencyInst); insertPos.add(CIAccounting.TransactionPositionCredit.RateCurrencyLink, tarCurInst); insertPos.add(CIAccounting.TransactionPositionCredit.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); insertPos.execute(); } } } } if (insert != null) { final Instance instance = insert.getInstance(); // create classifications final Classification classification1 = (Classification) CIAccounting.TransactionClass.getType(); final Insert relInsert1 = new Insert(classification1.getClassifyRelationType()); relInsert1.add(classification1.getRelLinkAttributeName(), instance); relInsert1.add(classification1.getRelTypeAttributeName(), classification1.getId()); relInsert1.execute(); final Insert classInsert1 = new Insert(classification1); classInsert1.add(classification1.getLinkAttributeName(), instance); classInsert1.execute(); final Classification classification = (Classification) CIAccounting.TransactionClassGainLoss.getType(); final Insert relInsert = new Insert(classification.getClassifyRelationType()); relInsert.add(classification.getRelLinkAttributeName(), instance); relInsert.add(classification.getRelTypeAttributeName(), classification.getId()); relInsert.execute(); final Insert classInsert = new Insert(classification); classInsert.add(classification.getLinkAttributeName(), instance); classInsert.add(CIAccounting.TransactionClassGainLoss.Amount, totalSum); classInsert.add(CIAccounting.TransactionClassGainLoss.RateAmount, totalSum); classInsert.add(CIAccounting.TransactionClassGainLoss.CurrencyLink, currencyInst); classInsert.add(CIAccounting.TransactionClassGainLoss.RateCurrencyLink, currencyInst); classInsert.add(CIAccounting.TransactionClassGainLoss.Rate, new Object[] { BigDecimal.ONE, BigDecimal.ONE }); classInsert.execute(); } // clean up Context.getThreadContext() .removeSessionAttribute(CIFormAccounting.Accounting_GainLoss4SimpleAccountForm.config2period.name); return new Return(); }
From source file:org.apache.calcite.test.MaterializationTest.java
@Test public void testSplitFilter() { final RexLiteral i1 = rexBuilder.makeExactLiteral(BigDecimal.ONE); final RexLiteral i2 = rexBuilder.makeExactLiteral(BigDecimal.valueOf(2)); final RexLiteral i3 = rexBuilder.makeExactLiteral(BigDecimal.valueOf(3)); final RelDataType intType = typeFactory.createType(int.class); final RexInputRef x = rexBuilder.makeInputRef(intType, 0); // $0 final RexInputRef y = rexBuilder.makeInputRef(intType, 1); // $1 final RexInputRef z = rexBuilder.makeInputRef(intType, 2); // $2 final RexNode x_eq_1 = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, x, i1); // $0 = 1 final RexNode x_eq_1_b = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, x, i1); // $0 = 1 again final RexNode y_eq_2 = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, y, i2); // $1 = 2 final RexNode z_eq_3 = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, z, i3); // $2 = 3 RexNode newFilter;/* ww w . jav a 2 s. co m*/ // Example 1. // TODO: // Example 2. // condition: x = 1, // target: x = 1 or z = 3 // yields // residue: not (z = 3) newFilter = SubstitutionVisitor.splitFilter(rexBuilder, x_eq_1, rexBuilder.makeCall(SqlStdOperatorTable.OR, x_eq_1, z_eq_3)); assertThat(newFilter.toString(), equalTo("NOT(=($2, 3))")); // 2b. // condition: x = 1 or y = 2 // target: x = 1 or y = 2 or z = 3 // yields // residue: not (z = 3) newFilter = SubstitutionVisitor.splitFilter(rexBuilder, rexBuilder.makeCall(SqlStdOperatorTable.OR, x_eq_1, y_eq_2), rexBuilder.makeCall(SqlStdOperatorTable.OR, x_eq_1, y_eq_2, z_eq_3)); assertThat(newFilter.toString(), equalTo("NOT(=($2, 3))")); // 2c. // condition: x = 1 // target: x = 1 or y = 2 or z = 3 // yields // residue: not (y = 2) and not (z = 3) newFilter = SubstitutionVisitor.splitFilter(rexBuilder, x_eq_1, rexBuilder.makeCall(SqlStdOperatorTable.OR, x_eq_1, y_eq_2, z_eq_3)); assertThat(newFilter.toString(), equalTo("AND(NOT(=($1, 2)), NOT(=($2, 3)))")); // 2d. // condition: x = 1 or y = 2 // target: y = 2 or x = 1 // yields // residue: true newFilter = SubstitutionVisitor.splitFilter(rexBuilder, rexBuilder.makeCall(SqlStdOperatorTable.OR, x_eq_1, y_eq_2), rexBuilder.makeCall(SqlStdOperatorTable.OR, y_eq_2, x_eq_1)); assertThat(newFilter.isAlwaysTrue(), equalTo(true)); // 2e. // condition: x = 1 // target: x = 1 (different object) // yields // residue: true newFilter = SubstitutionVisitor.splitFilter(rexBuilder, x_eq_1, x_eq_1_b); assertThat(newFilter.isAlwaysTrue(), equalTo(true)); // 2f. // condition: x = 1 or y = 2 // target: x = 1 // yields // residue: null // TODO: // Example 3. // Condition [x = 1 and y = 2], // target [y = 2 and x = 1] yields // residue [true]. // TODO: // Example 4. // TODO: }
From source file:com.ng.mats.psa.mt.paga.data.JSONObject.java
/** * Increment a property of a JSONObject. If there is no such property, * create one with a value of 1. If there is such a property, and if it is * an Integer, Long, Double, or Float, then add one to it. * /*from w ww .j a v a 2s . co m*/ * @param key * A key string. * @return this. * @throws JSONException * If there is already a property with this name that is not an * Integer, Long, Double, or Float. */ public JSONObject increment(String key) throws JSONException { Object value = this.opt(key); if (value == null) { this.put(key, 1); } else if (value instanceof BigInteger) { this.put(key, ((BigInteger) value).add(BigInteger.ONE)); } else if (value instanceof BigDecimal) { this.put(key, ((BigDecimal) value).add(BigDecimal.ONE)); } else if (value instanceof Integer) { this.put(key, (Integer) value + 1); } else if (value instanceof Long) { this.put(key, (Long) value + 1); } else if (value instanceof Double) { this.put(key, (Double) value + 1); } else if (value instanceof Float) { this.put(key, (Float) value + 1); } else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } return this; }