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:org.openvpms.component.business.service.archetype.helper.IMObjectBeanTestCase.java

/**
 * Tests the {@link IMObjectBean#getBigDecimal} methods.
 */// w  ww .  ja  v a 2s.c om
@Test
public void testGetBigDecimal() {
    IMObjectBean bean = createBean("act.types");

    assertNull(bean.getBigDecimal("amount"));
    assertEquals(bean.getBigDecimal("amount", BigDecimal.ZERO), BigDecimal.ZERO);

    BigDecimal expected = new BigDecimal("1234.56");
    bean.setValue("amount", expected);
    assertEquals(expected, bean.getBigDecimal("amount"));

    // quantity has a default value
    assertTrue(BigDecimal.ONE.compareTo(bean.getBigDecimal("quantity")) == 0);
}

From source file:org.opentestsystem.authoring.testauth.service.impl.PublishingRecordServiceImpl.java

/**
 * save new INPROGRESS status row w/ same assessment ID and w/ incremented version # of PUBLISHED row
 *//* w w  w .  j  a va  2 s .co  m*/
private void processNextVersion(final Assessment assessment, final PublishingRecord publishingRecord,
        final boolean incrementNextMajor) {
    if (!this.approvalService.isAdminUser()) {
        throw new LocalizedException("publishingRecord.invalid.user");
    }
    publishingRecord.setId(null);
    publishingRecord.setPublishingStatus(PublishingStatus.INPROGRESS);
    assessment.setStatus(PublishingStatus.INPROGRESS);
    if (incrementNextMajor) {
        final BigDecimal major = new BigDecimal(
                StringUtils.substringBefore(publishingRecord.getVersion(), "."));
        publishingRecord.setVersion(major.add(BigDecimal.ONE).toString() + ".0");
    } else {
        publishingRecord.setVersion(
                new BigDecimal(publishingRecord.getVersion()).add(new BigDecimal("0.1")).toString());
    }

    assessment.setVersion(publishingRecord.getVersion());
    assessment.setLocked(false);
    this.assessmentRepository.save(assessment);
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

@Test
public void testAlreadyMigratedEvent() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> eventUsername = initEvent(categories);
    Event event = eventUsername.getKey();

    try {/*from   ww  w  .j ava2 s.c om*/
        ZonedDateTime migrationTs = ZonedDateTime.now(ZoneId.of("UTC"));
        eventMigrationRepository.insertMigrationData(event.getId(), currentVersion, migrationTs,
                EventMigration.Status.COMPLETE.toString());
        eventRepository.updatePrices("CHF", 40, false, BigDecimal.ONE, "STRIPE", event.getId(),
                PriceContainer.VatStatus.NOT_INCLUDED, 1000);
        dataMigrator.migrateEventsToCurrentVersion();
        EventMigration eventMigration = eventMigrationRepository.loadEventMigration(event.getId());
        assertNotNull(eventMigration);
        //assertEquals(migrationTs.toString(), eventMigration.getBuildTimestamp().toString());
        assertEquals(currentVersion, eventMigration.getCurrentVersion());

        List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
        assertNotNull(tickets);
        assertFalse(tickets.isEmpty());
        assertEquals(AVAILABLE_SEATS, tickets.size());//<-- the migration has not been done
        assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
    } finally {
        eventManager.deleteEvent(event.getId(), eventUsername.getValue());
    }
}

From source file:org.openvpms.web.workspace.patient.history.PatientHistoryIteratorTestCase.java

/**
 * Creates a new charge item./*from w w  w  .j  a va 2s .  com*/
 *
 * @param startTime the start time
 * @param patient   the patient
 * @param product   the product
 * @return a new charge item
 */
private FinancialAct createChargeItem(Date startTime, Party patient, Product product) {
    FinancialAct item = FinancialTestHelper.createChargeItem(INVOICE_ITEM, patient, product, BigDecimal.ONE);
    item.setActivityStartTime(startTime);
    save(item);
    return item;
}

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

public void activar(ActionEvent event) {
    try {/*from   w w  w  .  j  a  v  a  2 s  .co m*/
        if (event != null) {
            if (this.getSelectedPolitica() != null) {
                LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
                User user = loginMB.getUser();
                PoliticaService service = (PoliticaService) ServiceFinder.findBean("PoliticaService");
                this.getSelectedPolitica().setNactivo(BigDecimal.ONE);
                this.getSelectedPolitica().setDfechamodificacion(new Date());
                this.getSelectedPolitica().setVusuariomodificacion(user.getVlogin());
                service.saveOrUpdate(this.getSelectedPolitica());
                this.setListaPolitica(service.getPoliticas());
            } else {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Debe seleccionar politica a activar.");
                FacesContext.getCurrentInstance().addMessage(null, message);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.cryptomath.CryptoMath.java

public static BigDecimal inverse(final BigDecimal value) {
    if (isNotZero(value)) {
        return BigDecimal.ONE.setScale(MAX_SCALE_FOR_INVERSE).divide(value, BigDecimal.ROUND_HALF_UP);
        //       return BigDecimal.ONE.setScale(MAX_SCALE_FOR_INVERSE).divide(value);
    }/*from w w  w .j  a  v a 2  s.  co m*/
    return null;
}

From source file:org.openhab.persistence.dynamodb.internal.AbstractDynamoDBItemSerializationTest.java

@Test
public void testUpDownTypeWithRollershutterItem() throws IOException {
    // note: comes back as PercentType instead of the original UpDownType
    DynamoDBItem<?> dbItemDown = testStateGeneric(UpDownType.DOWN, BigDecimal.ZERO);
    testAsHistoricGeneric(dbItemDown, new RollershutterItem("foo"), new PercentType(BigDecimal.ZERO));

    DynamoDBItem<?> dbItemUp = testStateGeneric(UpDownType.UP, BigDecimal.ONE);
    testAsHistoricGeneric(dbItemUp, new RollershutterItem("foo"), new PercentType(BigDecimal.ONE));
}

From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java

/**
 * Verifies that {@link TillRules#transfer} throws TillRuleException if
 * an attempt is made to transfer to the same till.
 */// w w  w . j a v  a  2s.c o  m
@Test
public void testTransferToSameTill() {
    List<FinancialAct> payment = createPayment(till);
    payment.get(0).setStatus(POSTED);
    Act balance = checkAddToTillBalance(till, payment, false, BigDecimal.ONE);

    try {
        rules.transfer(balance, payment.get(0), till);
    } catch (TillRuleException expected) {
        assertEquals(InvalidTransferTill, expected.getErrorCode());
    }
}

From source file:org.yes.cart.web.support.service.impl.ProductServiceFacadeImplTest.java

@Test
public void testGetSkuPriceSearchAndProductDetailsNoPriceB2BStrict() throws Exception {

    final PriceService priceService = context.mock(PriceService.class, "priceService");
    final PricingPolicyProvider pricingPolicyProvider = context.mock(PricingPolicyProvider.class,
            "pricingPolicyProvider");
    final ShopService shopService = context.mock(ShopService.class, "shopService");

    final ShoppingCart cart = context.mock(ShoppingCart.class, "cart");
    final ShoppingContext cartCtx = context.mock(ShoppingContext.class, "cartCtx");
    final PricingPolicyProvider.PricingPolicy policy = context.mock(PricingPolicyProvider.PricingPolicy.class,
            "policy");

    final Shop b2b = context.mock(Shop.class, "b2b");

    context.checking(new Expectations() {
        {/*from w  ww. j a  v  a 2 s . c  o m*/
            allowing(cart).getShoppingContext();
            will(returnValue(cartCtx));
            allowing(cartCtx).getShopId();
            will(returnValue(234L));
            allowing(cartCtx).getCustomerShopId();
            will(returnValue(345L));
            allowing(cartCtx).getShopCode();
            will(returnValue("SHOP10"));
            allowing(cartCtx).getCountryCode();
            will(returnValue("GB"));
            allowing(cartCtx).getStateCode();
            will(returnValue("GB-LON"));
            allowing(cart).getCustomerEmail();
            will(returnValue("bob@doe.com"));
            allowing(cart).getCurrencyCode();
            will(returnValue("EUR"));
            allowing(pricingPolicyProvider).determinePricingPolicy("SHOP10", "EUR", "bob@doe.com", "GB",
                    "GB-LON");
            will(returnValue(policy));
            allowing(policy).getID();
            will(returnValue("P1"));
            allowing(priceService).getMinimalPrice(123L, "ABC", 345L, null, "EUR", BigDecimal.ONE, false, "P1");
            will(returnValue(null));
            allowing(shopService).getById(345L);
            will(returnValue(b2b));
            allowing(b2b).isB2BStrictPriceActive();
            will(returnValue(true));
        }
    });

    final ProductServiceFacade facade = new ProductServiceFacadeImpl(null, null, null, null, null, null,
            pricingPolicyProvider, priceService, null, null, null, shopService, null);

    final ProductPriceModel model = facade.getSkuPrice(cart, 123L, "ABC", BigDecimal.ONE);

    assertNotNull(model);

    assertNull(model.getRef());

    assertEquals("EUR", model.getCurrency());
    assertNull(model.getQuantity());

    assertNull(model.getRegularPrice());
    assertNull(model.getSalePrice());

    assertFalse(model.isTaxInfoEnabled());
    assertFalse(model.isTaxInfoUseNet());
    assertFalse(model.isTaxInfoShowAmount());

    assertNull(model.getPriceTaxCode());
    assertNull(model.getPriceTaxRate());
    assertFalse(model.isPriceTaxExclusive());
    assertNull(model.getPriceTax());

    context.assertIsSatisfied();

}

From source file:pe.gob.mef.gescon.hibernate.impl.BaseLegalDaoImpl.java

@Override
public List<HashMap> getTbaselegalesByLinkId(final BigDecimal id) throws Exception {
    final StringBuilder sql = new StringBuilder();
    Object object = null;/*  w ww  .j a v  a 2s  .  c  o  m*/
    try {
        sql.append(
                "SELECT a.nbaselegalid AS ID, a.vnumero AS NUMERO, a.vnombre AS NOMBRE, a.vsumilla AS SUMILLA, ");
        sql.append("       a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechavigencia AS FECHA, ");
        sql.append("       e.ntipovinculo AS IDESTADO, c.vnombre AS ESTADO ");
        sql.append("FROM TBASELEGAL a ");
        sql.append("INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid ");
        sql.append(
                "INNER JOIN TVINCULO_BASELEGAL e ON a.nbaselegalid = e.nbaselegalid AND e.nbaselegalvinculadaid = :ID ");
        sql.append("INNER JOIN MTESTADO_BASELEGAL c ON e.ntipovinculo = c.nestadoid ");
        sql.append("WHERE a.nactivo = :ACTIVO ");
        sql.append(
                "AND a.nbaselegalid IN(SELECT d.nbaselegalid FROM TVINCULO_BASELEGAL d WHERE d.nbaselegalvinculadaid = :ID)");
        sql.append("ORDER BY a.vnumero ");

        object = getHibernateTemplate().execute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                Query query = session.createSQLQuery(sql.toString());
                query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
                query.setParameter("ACTIVO", BigDecimal.ONE);
                query.setParameter("ID", id);
                return query.list();
            }
        });
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
    return (List<HashMap>) object;
}