Example usage for java.math BigDecimal ONE

List of usage examples for java.math BigDecimal ONE

Introduction

In this page you can find the example usage for java.math BigDecimal ONE.

Prototype

BigDecimal ONE

To view the source code for java.math BigDecimal ONE.

Click Source Link

Document

The value 1, with a scale of 0.

Usage

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3SimpleEntityRepositoryTest.java

private SimpleEntity getEntity2() {
    SimpleEntity e = new SimpleEntity();
    e.setTheKey(ENTITY2_ID);//  ww w  .  j a  va  2 s .  c  o m
    e.setaBigInt(1L);
    e.setaBoolean(Boolean.TRUE);
    e.setaDecimal(BigDecimal.ONE);
    e.setaDouble(2.0d);
    e.setaFloat(2.0f);
    e.setAnInt(42);
    List<String> stringList = Lists.newArrayList("gamma", "delta");
    e.setaListOfString(stringList);
    List<Integer> intList = Lists.newArrayList(27, 666);
    e.setaListOfInt(intList);
    Map<String, String> mapStringString = Maps.newHashMap();
    mapStringString.put("hello", "world");
    mapStringString.put("what's", "up");
    e.setaMapOfStringToString(mapStringString);
    Map<Integer, String> mapIntString = Maps.newHashMap();
    mapIntString.put(3, "three");
    mapIntString.put(4, "four");
    e.setaMapOfIntToString(mapIntString);
    Set<String> stringSet = Sets.newHashSet();
    stringSet.add("baz");
    stringSet.add("bat");
    e.setaSetOfString(stringSet);
    Set<Integer> intSet = Sets.newHashSet();
    intSet.add(4321);
    intSet.add(8765);
    e.setaSetOfInt(intSet);
    e.setaString("Ninja");
    e.setaUuid(TimeUUIDUtils.getUniqueTimeUUIDinMillis());
    return e;
}

From source file:org.openvpms.archetype.function.reminder.ReminderFunctionsTestCase.java

/**
 * Tests the {@link ReminderFunctions#getDocumentFormReminder} method.
 *//*from w  ww.ja  va 2 s  .  c  o m*/
@Test
public void testGetDocumentFormReminder() {
    Party patient = TestHelper.createPatient();
    DocumentAct form = (DocumentAct) create(PatientArchetypes.DOCUMENT_FORM);
    ActBean formBean = new ActBean(form);
    formBean.addNodeParticipation("patient", patient);
    save(form);

    // verify a form not associated with any invoice item nor product returns null
    assertNull(getDocumentFormReminder(form));

    // create an invoice item and associate the form with it
    Act item = FinancialTestHelper.createChargeItem(CustomerAccountArchetypes.INVOICE_ITEM, patient,
            TestHelper.createProduct(), BigDecimal.ONE);
    ActBean itemBean = new ActBean(item);
    itemBean.addNodeRelationship("documents", form);
    save(item, form);

    // associate a single reminder with the invoice item, and verify it is returned by getDocumentFormReminder()
    Act reminder = ReminderTestHelper.createReminder(patient, ReminderTestHelper.createReminderType());
    itemBean.addNodeRelationship("reminders", reminder);
    save(item, reminder);
    assertEquals(reminder, getDocumentFormReminder(form));
}

From source file:org.sakaiproject.nakamura.personal.LitePersonalTrackingStore.java

/**
 * {@inheritDoc}//from   ww  w  . j a v  a2 s  .c  o  m
 * 
 * @see org.sakaiproject.nakamura.api.personal.PersonalTrackingStore#recordActivity(java.lang.String,
 *      java.lang.String, java.lang.String, java.lang.String, java.util.Date)
 */
public void recordActivity(String resourceId, String resourceType, String activityType, String userId,
        Calendar timestamp) {
    Session session = null;
    try {
        session = repository.loginAdministrative();
        final ContentManager cm = session.getContentManager();
        final String trackingNodePath = "/activity/" + resourceType + "/" + resourceId;
        Content trackingNode = cm.get(trackingNodePath);
        if (trackingNode == null) {
            trackingNode = new Content(trackingNodePath, new HashMap<String, Object>());
        }
        if (!trackingNode.hasProperty("count")) {
            trackingNode.setProperty("count", BigDecimal.ZERO);
        }
        if (!trackingNode.hasProperty("sling:resourceType")) {
            trackingNode.setProperty("sling:resourceType", "sakai/resource-activity");
        }
        final String generatedNodeName = Base64
                .encodeBase64URLSafeString(asShorterByteArray(UUID.randomUUID()));
        final String activityNodePath = trackingNodePath + "/" + generatedNodeName;
        Content activityNode = null;
        if (cm.exists(activityNodePath)) {
            activityNode = cm.get(activityNodePath);
        } else {
            activityNode = new Content(activityNodePath, new HashMap<String, Object>());
        }
        BigDecimal activityCount = (BigDecimal) trackingNode.getProperty("count");
        activityNode.setProperty("sling:resourceType", "sakai/resource-update");
        trackingNode.setProperty("count", activityCount.add(BigDecimal.ONE));
        activityNode.setProperty("resourceId", resourceId);
        activityNode.setProperty("resourcetype", resourceType);
        activityNode.setProperty("activitytype", activityType);
        activityNode.setProperty("timestamp", timestamp);
        activityNode.setProperty("userid", userId);
        cm.update(activityNode);
        cm.update(trackingNode);
    } catch (AccessDeniedException e) {
        LOG.error(e.getLocalizedMessage(), e);
    } catch (StorageClientException e) {
        LOG.error(e.getLocalizedMessage(), e);
    } finally {
        if (session != null) {
            try {
                session.logout();
            } catch (ClientPoolException e) {
                LOG.error(e.getLocalizedMessage(), e);
                throw new IllegalStateException(e);
            }
        }
    }

}

From source file:org.kuali.kfs.module.endow.document.validation.impl.SecurityPreRule.java

/**
 * @see org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.rice.kns.document.MaintenanceDocument)
 */// ww w  .  j  ava2s .c  o m
@Override
protected boolean doCustomPreRules(MaintenanceDocument maintenanceDocument) {

    boolean preRulesOK = true;
    setupConvenienceObjects(maintenanceDocument);

    if (KFSConstants.MAINTENANCE_NEW_ACTION
            .equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())
            || KFSConstants.MAINTENANCE_COPY_ACTION
                    .equals(maintenanceDocument.getNewMaintainableObject().getMaintenanceAction())) {

        String securityID = newSecurity.getUserEnteredSecurityIDprefix();

        // the user should enter the first 8 characters of the security and the system will compute the ninth digit
        if (StringUtils.isEmpty(securityID) || securityID.length() != 8) {
            GlobalVariables.getMessageMap().putError(
                    KFSConstants.MAINTENANCE_NEW_MAINTAINABLE
                            + EndowPropertyConstants.SECURITY_USER_ENTERED_ID_PREFIX,
                    EndowKeyConstants.SecurityConstants.ERROR_ENTERED_SECURITY_ID_SHOULD_BE_8_CHARS);
        } else {
            // compute the ninth digit of the security ID using the mod10 algorithm
            KEMService kemService = SpringContext.getBean(KEMService.class);

            securityID += kemService.mod10(securityID);

            newSecurity.setId(securityID);
        }

        // set default unit value to be -1 if Liability and 1 otherwise when creating a new security
        if (ObjectUtils.isNotNull(newSecurity.getClassCode())) {

            if (EndowConstants.ClassCodeTypes.LIABILITY.equals(newSecurity.getClassCode().getClassCodeType())) {
                newSecurity.setUnitValue(new BigDecimal(-1));
            } else {
                // when a security has a class code set to allow market instead of unit valuation, the system is setting
                // the unit value to null
                if (EndowConstants.ValuationMethod.MARKET
                        .equalsIgnoreCase(newSecurity.getClassCode().getValuationMethod())) {
                    newSecurity.setUnitValue(null);
                }
                // by default unit value is 1
                else {
                    newSecurity.setUnitValue(BigDecimal.ONE);
                }
            }
        }
    }

    preRulesOK &= conditionallyAskQuestion(maintenanceDocument);
    return preRulesOK;
}

From source file:com.ning.billing.analytics.dao.TestAnalyticsDao.java

private void setupBusinessAccount() {
    final List<String> tags = new ArrayList<String>();
    tags.add("batch1");
    tags.add("great,guy");
    account = new BusinessAccount(ACCOUNT_KEY, BigDecimal.ONE, tags, new DateTime(DateTimeZone.UTC),
            BigDecimal.TEN, "ERROR_NOT_ENOUGH_FUNDS", "CreditCard", "Visa", "FRANCE");

    final IDBI dbi = helper.getDBI();
    businessAccountDao = dbi.onDemand(BusinessAccountDao.class);

    // Healthcheck test to make sure MySQL is setup properly
    try {/*w ww . j a va 2s .com*/
        businessAccountDao.test();
    } catch (Throwable t) {
        Assert.fail(t.toString());
    }
}

From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java

public void set(BigDecimal totalSecondsBd) {
    long totalSeconds = totalSecondsBd.longValue();
    BigDecimal fractionalSecs = totalSecondsBd.remainder(BigDecimal.ONE);
    int nanos = fractionalSecs.multiply(IntervalDayTimeUtils.NANOS_PER_SEC_BD).intValue();
    set(totalSeconds, nanos);/*from  w w w. j  a  v a  2 s .  c om*/
}

From source file:com.opengamma.web.analytics.blotter.OtcTradeBuilder.java

UniqueId addTrade(BeanDataSource tradeData, BeanDataSource securityData,
        BeanDataSource underlyingData, UniqueId nodeId) {
    /*// w w w . ja va  2 s  .  c o m
    validate:
      underlying is present
      underlying type is correct
    */
    ManageableSecurity underlying = buildUnderlying(underlyingData);
    ManageableSecurity security;
    if (underlying == null) {
        security = BlotterUtils.buildSecurity(securityData);
    } else {
        ManageableSecurity savedUnderlying = getSecurityMaster().add(new SecurityDocument(underlying))
                .getSecurity();
        security = buildSecurity(securityData, savedUnderlying);
    }
    ManageableSecurity savedSecurity = getSecurityMaster().add(new SecurityDocument(security)).getSecurity();
    ManageableTrade trade = buildTrade(tradeData);
    trade.setSecurityLink(new ManageableSecurityLink(savedSecurity.getUniqueId()));
    ManageablePosition position = new ManageablePosition();
    position.setQuantity(BigDecimal.ONE);
    position.setSecurityLink(new ManageableSecurityLink(trade.getSecurityLink()));
    position.setTrades(Lists.newArrayList(trade));
    ManageablePosition savedPosition = getPositionMaster().add(new PositionDocument(position)).getPosition();
    ManageableTrade savedTrade = savedPosition.getTrades().get(0);

    PortfolioSearchRequest searchRequest = new PortfolioSearchRequest();
    searchRequest.addNodeObjectId(nodeId.getObjectId());
    PortfolioSearchResult searchResult = getPortfolioMaster().search(searchRequest);
    ManageablePortfolio portfolio = searchResult.getSinglePortfolio();
    ManageablePortfolioNode node = findNode(portfolio, nodeId);
    node.addPosition(savedPosition.getUniqueId());
    getPortfolioMaster().update(new PortfolioDocument(portfolio));
    return savedTrade.getUniqueId();
}

From source file:nl.strohalm.cyclos.utils.conversion.NumberConverter.java

private BigDecimal getDelta() {
    if (delta == null) {
        final int precision = numberFormat.getMaximumFractionDigits();
        delta = BigDecimal.ONE.divide(BigDecimal.TEN.pow(precision), precision, RoundingMode.HALF_UP).negate();
    }//w  ww  . j a  v  a  2s . c  o m
    return delta;
}

From source file:pe.gob.mef.gescon.web.ui.PoliticaMB.java

public void cleanAttributes() {
    this.setId(BigDecimal.ZERO);
    this.setModuloid(null);
    this.setDescripcion(StringUtils.EMPTY);
    this.setNombre(StringUtils.EMPTY);
    this.setActivo(BigDecimal.ONE);
    this.setSelectedPolitica(null);
    Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
    if (iter.hasNext() == true) {
        iter.remove();//from  ww  w .j a va2s. c o m
        FacesContext.getCurrentInstance().renderResponse();
    }
}

From source file:br.com.anteros.vendas.gui.ProdutoConsultaDialog.java

/**
 * Seleciona os produtos./*from   ww w .  j a v  a2  s  . c  om*/
 */
public void selecionarProdutos() {
    List<Produto> selectedItens = adapter.getItensSelecionados();
    List<ItemPedido> pedidoItens = PedidoConsultaActivity.pedido.getItens();
    List<Produto> itensDeleted = new ArrayList<>();

    /**
     * Adiciona os itens selecionados no pedido
     */
    if (!pedidoItens.isEmpty()) {
        for (ItemPedido item : pedidoItens) {
            for (Produto prod : selectedItens) {
                if (item.getProduto().getId().equals(prod.getId())) {
                    item.setQtProduto(item.getQtProduto().add(BigDecimal.ONE));
                    item.setVlTotal(item.getVlProduto().multiply(item.getQtProduto()));
                    itensDeleted.add(prod);
                    break;
                }
            }
        }

        selectedItens.removeAll(itensDeleted);

        for (Produto prod : selectedItens) {
            ItemPedido item = new ItemPedido();
            item.setQtProduto(BigDecimal.ONE);
            item.setPedidoVenda(PedidoConsultaActivity.pedido);
            item.setProduto(prod);
            item.setVlProduto(prod.getVlProduto());
            item.setVlTotal(item.getVlProduto().multiply(item.getQtProduto()));
            pedidoItens.add(item);
        }

    } else {
        for (Produto prod : selectedItens) {
            ItemPedido item = new ItemPedido();
            item.setQtProduto(BigDecimal.ONE);
            item.setPedidoVenda(PedidoConsultaActivity.pedido);
            item.setProduto(prod);
            item.setVlProduto(prod.getVlProduto());
            item.setVlTotal(item.getVlProduto().multiply(item.getQtProduto()));
            pedidoItens.add(item);
        }
    }
    /**
     * Atribui os itens no pedido
     */
    PedidoConsultaActivity.pedido.setItens(pedidoItens);
    /**
     * Fecha dialog.
     */
    dismiss();
}