List of usage examples for java.math BigDecimal multiply
public BigDecimal multiply(BigDecimal multiplicand)
(this × multiplicand)
, and whose scale is (this.scale() + multiplicand.scale()) . From source file:module.siadap.activities.CreateObjectiveEvaluationActivityInformation.java
protected void addNewIndicator(String measurementIndicator, String superationCriteria, BigDecimal ponderationFactor) throws SiadapException { checkIndicatorsSize();/*from w w w . ja v a2s .c om*/ indicators.add(new ObjectiveIndicator(measurementIndicator, superationCriteria, new Integer(ponderationFactor.multiply(new BigDecimal(100)).intValue()))); }
From source file:co.nubetech.apache.hadoop.TextSplitter.java
/** * Return the string encoded in a BigDecimal. Repeatedly multiply the input * value by 65536; the integer portion after such a multiplication * represents a single character in base 65536. Convert that back into a * char and create a string out of these until we have no data left. *///from ww w.j a v a 2s .c o m String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }
From source file:org.apache.sqoop.mapreduce.db.TextSplitter.java
/** * Return the string encoded in a BigDecimal. * Repeatedly multiply the input value by 65536; the integer portion after * such a multiplication represents a single character in base 65536. * Convert that back into a char and create a string out of these until we * have no data left./* w ww . ja va 2 s.c o m*/ */ public String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }
From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultWorkloadSuggestionMaker.java
@Override public WorkloadConfiguration suggest(BigDecimal desiredTps, NodeTpsStatistics statistics, int maxThreads) { log.debug("Going to suggest workload configuration. desired tps {}. statistics {}", desiredTps, statistics); Table<Integer, Integer, Pair<Long, BigDecimal>> threadDelayStats = statistics.getThreadDelayStats(); if (areEqual(desiredTps, BigDecimal.ZERO)) { return WorkloadConfiguration.with(0, 0); }// w w w . jav a 2s .co m if (threadDelayStats.isEmpty()) { throw new IllegalArgumentException("Cannot suggest workload configuration"); } if (!threadDelayStats.contains(CALIBRATION_CONFIGURATION.getThreads(), CALIBRATION_CONFIGURATION.getDelay())) { log.debug("Statistics is empty. Going to return calibration info."); return CALIBRATION_CONFIGURATION; } if (threadDelayStats.size() == 2 && areEqual(threadDelayStats.get(1, 0).getSecond(), BigDecimal.ZERO)) { log.warn("No calibration info. Going to retry."); return CALIBRATION_CONFIGURATION; } Map<Integer, Pair<Long, BigDecimal>> noDelays = threadDelayStats.column(0); log.debug("Calculate next thread count"); Integer threadCount = findClosestPoint(desiredTps, noDelays); if (threadCount == 0) { threadCount = 1; } if (threadCount > maxThreads) { log.warn("{} calculated max {} allowed", threadCount, maxThreads); threadCount = maxThreads; } int currentThreads = statistics.getCurrentWorkloadConfiguration().getThreads(); int diff = threadCount - currentThreads; if (diff > maxDiff) { log.debug("Increasing to {} is required current thread count is {} max allowed diff is {}", new Object[] { threadCount, currentThreads, maxDiff }); return WorkloadConfiguration.with(currentThreads + maxDiff, 0); } diff = currentThreads - threadCount; if (diff > maxDiff) { log.debug("Decreasing to {} is required current thread count is {} max allowed diff is {}", new Object[] { threadCount, currentThreads, maxDiff }); if ((currentThreads - maxDiff) > 1) { return WorkloadConfiguration.with(currentThreads - maxDiff, 0); } else { return WorkloadConfiguration.with(1, 0); } } if (!threadDelayStats.contains(threadCount, 0)) { return WorkloadConfiguration.with(threadCount, 0); } // <delay, <timestamp,tps>> Map<Integer, Pair<Long, BigDecimal>> delays = threadDelayStats.row(threadCount); // not enough statistics to calculate if (delays.size() == 1) { int delay = 0; BigDecimal tpsFromStat = delays.get(0).getSecond(); // try to guess // tpsFromStat can be zero if no statistics was captured till this time if ((tpsFromStat.compareTo(BigDecimal.ZERO) > 0) && (desiredTps.compareTo(BigDecimal.ZERO) > 0)) { BigDecimal oneSecond = new BigDecimal(TimeUtils.secondsToMillis(1)); BigDecimal result = oneSecond.multiply(new BigDecimal(threadCount)).divide(desiredTps, 3, BigDecimal.ROUND_HALF_UP); result = result.subtract(oneSecond.multiply(new BigDecimal(threadCount)).divide(tpsFromStat, 3, BigDecimal.ROUND_HALF_UP)); delay = result.intValue(); } // to have some non zero point in statistics if (delay == 0) { delay = MIN_DELAY; } delay = checkDelayInRange(delay); return WorkloadConfiguration.with(threadCount, delay); } log.debug("Calculate next delay"); Integer delay = findClosestPoint(desiredTps, threadDelayStats.row(threadCount)); delay = checkDelayInRange(delay); return WorkloadConfiguration.with(threadCount, delay); }
From source file:org.egov.adtax.service.notice.AdvertisementNoticeService.java
private BigDecimal calculateAdditionalTaxes(BigDecimal curntInsTotalTaxableAmt, final BigDecimal entry) { return entry.multiply(curntInsTotalTaxableAmt).divide(BigDecimal.valueOf(100)).setScale(0, BigDecimal.ROUND_HALF_UP); }
From source file:org.estatio.dom.lease.invoicing.InvoiceCalculationService.java
/** * Multiplies a value with the range and annual factors * /* ww w . j a v a 2 s . c o m*/ * @param rangeFactor * @param annualFactor * @param value * @return */ private BigDecimal calculateValue(final BigDecimal rangeFactor, final BigDecimal annualFactor, final BigDecimal value) { if (value != null && annualFactor != null && rangeFactor != null) { return value.multiply(annualFactor).multiply(rangeFactor).setScale(2, RoundingMode.HALF_UP); } return new BigDecimal("0.00"); }
From source file:com.autentia.tnt.businessobject.Project.java
public BigDecimal getCostPerProject() { BigDecimal total = new BigDecimal(0); Set<ProjectRole> roles = this.getRoles(); if (roles != null) { for (ProjectRole role : roles) { Set<Activity> activities = role.getActivities(); if (activities != null) { for (Activity activity : activities) { BigDecimal converse = new BigDecimal(activity.getUser().getCostPerHour()); BigDecimal div = new BigDecimal(activity.getDuration()); BigDecimal ret = div.multiply(converse); total = total.add(ret.divide(new BigDecimal(60), 2, BigDecimal.ROUND_HALF_UP));// += activity.getDuration() * activity.getUser().getCostPerHour()/ 60 ; }/*from w w w.j a v a 2 s. c om*/ } } } return total; }
From source file:nl.tudelft.ewi.st.atlantis.tudelft.v1.services.orderprocessorservice.impl.OrderProcessManager.java
public void processAndCompleteOrder(Order order) throws DAOException { if (logger.isDebugEnabled()) { logger.debug("ProcessOrder.processAndCompleteOrder(OrderDataModel) \nOrderID :" + order.getOrderID() + "\nOrderType :" + order.getOrderType() + "\nSymbol :" + order.getSymbol() + "\nQuantity :" + order.getQuantity() + "\nOrder Status :" + order.getOrderStatus() + "\nOrder Open Date :" + order.getOpenDate() + "\nCompletionDate :" + order.getCompletionDate()); }//from w ww .j ava 2s. c om try { DAOFactory factory = DAOFactory.getFactory(); orderDAO = factory.getOrderDAO(); orderDAO.beginTransaction(); BigDecimal total = null; int holdingId = -1; //Quote quote = orderDAO.getQuoteForUpdate(order.getSymbol()); /* Tiago: making this more dynamic. query config service for a * quote service, then use quote service to get quote data */ SharedConfigurationServiceV1Consumer consumer = new SharedConfigurationServiceV1Consumer( "OrderProcessorService", "production"); GetQSLocationsResponse response = consumer.getQSLocations(new GetQSLocationsRequest()); if (response.getLocations().size() == 0) { System.out.println("Unable to locate a quote service"); return; } /* Got the QS Endpoint */ String qsEndpoint = response.getLocations().get(0).getServiceURL(); SharedQuoteServiceV1Consumer qsConsumer = new SharedQuoteServiceV1Consumer("OrderProcessorService", "production"); GetQuotesRequest request = new GetQuotesRequest(); request.getSymbols().add(order.getSymbol()); qsConsumer.getService().setServiceLocation(new URL(qsEndpoint)); GetQuotesResponse qsResponse = qsConsumer.getQuotes(request); if (qsResponse.getQuoteData().size() == 0) { System.out.println("Unable to locate a quote entry for the symbol :" + order.getSymbol()); return; } RemoteQuoteData quoteData = qsResponse.getQuoteData().get(0); BigDecimal price = BigDecimal.valueOf(quoteData.getValue()); order.setPrice(price); System.out.println("order type is:" + order.getOrderType()); if (StockTraderUtility.ORDER_TYPE_BUY.equals(order.getOrderType())) { holdingId = orderDAO.createHolding(order); BigDecimal orderQuantity = BigDecimal.valueOf(order.getQuantity()); BigDecimal orderPrice = order.getPrice(); total = orderQuantity.multiply(orderPrice); BigDecimal orderFee = order.getOrderFee(); if (orderFee != null) { total = total.add(orderFee); } } else if (StockTraderUtility.ORDER_TYPE_SELL.equals(order.getOrderType())) { holdingId = sellHolding(order); if (holdingId == -1) { return; } BigDecimal orderQuantity = BigDecimal.valueOf(-1 * order.getQuantity()); BigDecimal orderPrice = order.getPrice(); total = orderQuantity.multiply(orderPrice); BigDecimal orderFee = order.getOrderFee(); if (total != null) { total = total.add(orderFee); } } orderDAO.updateAccountBalance(order.getAccountId(), total); orderDAO.updateStockPriceVolume(order.getQuantity(), quoteData); order.setOrderStatus(StockTraderUtility.ORDER_STATUS_CLOSED); order.setCompletionDate(Calendar.getInstance()); order.setHoldingId(holdingId); orderDAO.closeOrder(order); orderDAO.commitTransaction(); } catch (Exception e) { e.printStackTrace(); try { orderDAO.rollbackTransaction(); logger.error("", e); } catch (DAOException e1) { logger.error("", e1); } } finally { if (orderDAO != null) { try { orderDAO.close(); } catch (DAOException e) { logger.error("", e); } } } }
From source file:jp.furplag.util.commons.NumberUtils.java
/** * generate cosine factor for trigonometric functions in BigDecimal. * * @param mc {@link java.math.MathContext}. * @return list of cosine factors.//w w w .j av a 2 s . c o m */ private static List<BigDecimal> initCosineFactor(MathContext mc) { int precision = (mc == null ? MathContext.DECIMAL128 : mc).getPrecision(); List<BigDecimal> factors = new ArrayList<BigDecimal>(); BigDecimal divisor = BigDecimal.valueOf(2d); BigDecimal temporary = BigDecimal.valueOf(2d); do { factors.add(BigDecimal.ONE.divide(divisor, precision + 2, RoundingMode.HALF_UP)); temporary = temporary.add(BigDecimal.ONE); divisor = divisor.multiply(temporary); temporary = temporary.add(BigDecimal.ONE); divisor = divisor.multiply(temporary); } while (factors.get(factors.size() - 1).compareTo(new BigDecimal("1E-" + (precision + 2))) > 0); return factors; }
From source file:org.kalypso.model.wspm.tuhh.schema.simulation.ResultLengthSection.java
private void fixLengthSectionStation(final TupleResult result) { final TuhhStationRange stationRange = new TuhhStationRange(m_calculation); final int exportSign = stationRange.getExportSign(); if (exportSign == 1) { /* Nothing to do, station was not inverted for calculation */ return;/*from w ww .j a v a2s . co m*/ } final BigDecimal sign = new BigDecimal(exportSign); final int stationComponent = result.indexOfComponent(IWspmTuhhConstants.LENGTH_SECTION_PROPERTY_STATION); for (final IRecord record : result) { final BigDecimal station = (BigDecimal) record.getValue(stationComponent); if (station != null) { final BigDecimal invertedStation = station.multiply(sign); record.setValue(stationComponent, invertedStation); } } }