List of usage examples for java.math BigDecimal signum
public int signum()
From source file:org.openbravo.erpCommon.ad_forms.DocCostAdjustment.java
/** * Get Document Confirmation//from ww w .jav a2s . c om * * not used */ public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { boolean isGeneratedAccounting = false; DocLine[] local_p_lines = new DocLine[0]; local_p_lines = loadLines(conn); // Lines for (int i = 0; local_p_lines != null && i < local_p_lines.length; i++) { DocLine_CostAdjustment line = (DocLine_CostAdjustment) local_p_lines[i]; BigDecimal amount = new BigDecimal(line.getAmount()); if (amount.signum() != 0) { isGeneratedAccounting = true; } } if (!isGeneratedAccounting) { setStatus(STATUS_DocumentDisabled); } return isGeneratedAccounting; }
From source file:org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement.java
private BigDecimal getAvancement(SQLRowAccessor r) { Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("ECHEANCE_CLIENT")); long totalEch = 0; for (SQLRowAccessor row : rows) { if (!row.getBoolean("REGLE") && !row.getBoolean("REG_COMPTA")) { totalEch += row.getLong("MONTANT"); }//w w w. j a va 2 s. com } SQLRowAccessor avoir = r.getForeign("ID_AVOIR_CLIENT"); BigDecimal avoirTTC = BigDecimal.ZERO; if (avoir != null && !avoir.isUndefined()) { avoirTTC = new BigDecimal(avoir.getLong("MONTANT_TTC")); } final BigDecimal totalAregler = new BigDecimal(r.getLong("T_TTC")).subtract(avoirTTC); if (totalAregler.signum() > 0 && totalEch > 0) { return totalAregler.subtract(new BigDecimal(totalEch)).divide(totalAregler, MathContext.DECIMAL128) .movePointRight(2).setScale(2, RoundingMode.HALF_UP); } else { return BigDecimal.ONE.movePointRight(2); } }
From source file:org.marketcetera.core.position.impl.PositionMetricsCalculatorImpl.java
/** * Processes a trade, closing existing positions and creating new ones as necessary. * // w w w.j a v a 2s . co m * @param quantity * the quantity of the trade, positive for a buy and negative for a sell * @param price * the price of the trade */ private void processTrade(final BigDecimal quantity, final BigDecimal price) { mPosition = mPosition.add(quantity); // only bother with PNL if the closing price is available if (mClosingPriceAvailable) { tradingCost.add(quantity, price); // determine the sides, +1 for long and -1 for short int holdingSide = mUnrealizedCost.signum(); int tradingSide = quantity.signum(); BigDecimal remaining = quantity; // if sides are different if (tradingSide * holdingSide == -1) { // close positions while (!mPositionElements.isEmpty()) { // get the oldest open position PositionElement toClose = mPositionElements.peek(); // add the remaining trade quantity BigDecimal leftover = toClose.quantity.add(remaining); int leftoverSide = leftover.signum(); // if there is leftover on the open position if (leftoverSide == holdingSide) { // the trade only partially closed this position processClose(remaining, toClose.price, price); toClose.quantity = leftover; // trade has been completely processed return; } else { // the trade completely closed this position processClose(toClose.quantity.negate(), toClose.price, price); mPositionElements.remove(); remaining = leftover; // if leftover is zero if (leftoverSide == 0) { // trade has been completely processed return; } } } } // if non-zero remaining quantity if (remaining.signum() != 0) { // create new position mPositionElements.add(new PositionElement(remaining, price)); mUnrealizedCost.add(remaining, price); } } }
From source file:com.heliumv.api.item.ItemApi.java
protected List<StockAmountEntry> getStockAmountImpl(String userId, String itemCnr, Boolean returnItemInfo) { List<StockAmountEntry> stockEntries = new ArrayList<StockAmountEntry>(); if (StringHelper.isEmpty(itemCnr)) { respondBadRequestValueMissing("itemCnr"); return stockEntries; }/*w ww. ja va 2 s.c om*/ if (connectClient(userId) == null) return stockEntries; if (returnItemInfo == null) returnItemInfo = false; try { ArtikelDto itemDto = artikelCall.artikelFindByCNrOhneExc(itemCnr); if (itemDto == null) { respondNotFound("itemCnr", itemCnr); return stockEntries; } StockEntryMapper stockMapper = new StockEntryMapper(); ItemEntryMapper itemMapper = new ItemEntryMapper(); List<AllLagerEntry> stocks = lagerCall.getAllLager(); for (AllLagerEntry allLagerEntry : stocks) { if (lagerCall.hatRolleBerechtigungAufLager(allLagerEntry.getStockId())) { LagerDto lagerDto = lagerCall.lagerFindByPrimaryKeyOhneExc(allLagerEntry.getStockId()); if (lagerDto.getBVersteckt() > 0) continue; BigDecimal amount = lagerCall.getLagerstandOhneExc(itemDto.getIId(), lagerDto.getIId()); if (amount.signum() == 1) { StockAmountEntry stockAmountEntry = new StockAmountEntry( returnItemInfo ? mapFromInternal(itemMapper.mapEntry(itemDto)) : null, stockMapper.mapEntry(lagerDto), amount); stockEntries.add(stockAmountEntry); } } } } catch (NamingException e) { respondUnavailable(e); } catch (RemoteException e) { respondUnavailable(e); } catch (EJBExceptionLP e) { respondBadRequest(e); } return stockEntries; }
From source file:org.openhab.binding.systeminfo.model.OshiSysteminfo.java
@Override public DecimalType getBatteryRemainingTime(int index) throws DeviceNotFoundException { PowerSource powerSource = (PowerSource) getDevice(powerSources, index); double remainingTimeInSeconds = powerSource.getTimeRemaining(); // The getTimeRemaining() method returns (-1.0) if is calculating or (-2.0) if the time is unlimited. BigDecimal remainingTime = getTimeInMinutes(remainingTimeInSeconds); return remainingTime.signum() == 1 ? new DecimalType(remainingTime) : null; }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
/** * {@inheritDoc}/*from w w w. jav a 2s. co m*/ * * This information is available only on Mac and Linux OS. */ @Override public DecimalType getCpuLoad1() { BigDecimal avarageCpuLoad = getAvarageCpuLoad(1); return avarageCpuLoad.signum() == -1 ? null : new DecimalType(avarageCpuLoad); }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
/** * {@inheritDoc}//from w w w .ja v a 2 s. com * * This information is available only on Mac and Linux OS. */ @Override public DecimalType getCpuLoad5() { BigDecimal avarageCpuLoad = getAvarageCpuLoad(5); return avarageCpuLoad.signum() == -1 ? null : new DecimalType(avarageCpuLoad); }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
/** * {@inheritDoc}/*from www . j a v a2 s . c o m*/ * * This information is available only on Mac and Linux OS. */ @Override public DecimalType getCpuLoad15() { BigDecimal avarageCpuLoad = getAvarageCpuLoad(15); return avarageCpuLoad.signum() == -1 ? null : new DecimalType(avarageCpuLoad); }
From source file:com.autentia.intra.validator.AccountEntryValidator.java
/** */ public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { log.info("validate - value = " + value); if (value != null) { // Check if value is a BigDecimal if (!(value instanceof BigDecimal)) { log.info("validate - value is not a BigDecimal (" + value.getClass().getName() + ")"); throw new ValidatorException( new FacesMessage("Las cantidades monetarias deben ser de tipo BigDecimal")); }/* w w w . j a v a 2 s . c o m*/ // Check if it has no more than 2 decimal digits BigDecimal bd = (BigDecimal) value; if (bd.scale() > 2) { log.info("validate - value has more than 2 decimals (" + value + ")"); throw new ValidatorException( new FacesMessage("Las cantidades monetarias no pueden tener mas de dos decimales")); } AccountEntryBean bean = (AccountEntryBean) FacesUtils.getBean("accountEntryBean"); AccountEntryType type = bean.getType(); AccountEntryGroup group = type.getGroup(); if (group.getId() == ConfigurationUtil.getDefault().getCostId()) { if (bd.signum() != -1) { log.info("validate - value cost is negative (" + value + ")"); throw new ValidatorException(new FacesMessage("La cantidad debe ser negativa")); } } if (group.getId() == ConfigurationUtil.getDefault().getIncomeId()) { if (bd.signum() != 1) { log.info("validate - value incom is positive (" + value + ")"); throw new ValidatorException(new FacesMessage("La cantidad debe ser positiva")); } } } }
From source file:org.openhab.binding.systeminfo.internal.model.OshiSysteminfo.java
@Override public DecimalType getBatteryRemainingTime(int index) throws DeviceNotFoundException { // In the current OSHI version a new query is required for the battery data values to be updated // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310 powerSources = hal.getPowerSources(); PowerSource powerSource = (PowerSource) getDevice(powerSources, index); double remainingTimeInSeconds = powerSource.getTimeRemaining(); // The getTimeRemaining() method returns (-1.0) if is calculating or (-2.0) if the time is unlimited. BigDecimal remainingTime = getTimeInMinutes(remainingTimeInSeconds); return remainingTime.signum() == 1 ? new DecimalType(remainingTime) : null; }