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:uk.dsxt.voting.client.web.MockVotingApiResource.java

License:asdf

@POST
@Path("/vote")
@Produces("application/json")
public RequestResult vote(@FormParam("cookie") String cookie, @FormParam("votingId") String votingId,
        @FormParam("votingChoice") String votingChoice) {
    try {//from   ww  w . j a  va 2 s. c om
        log.debug("vote method called. cookie={}; votingId={}; votingChoice={}", cookie, votingId,
                votingChoice);
        VotingChoice choice = mapper.readValue(votingChoice, VotingChoice.class);
        for (String question : choice.getQuestionChoices().keySet()) {
            log.debug("Question: {}, Answer: {}", question, choice.getQuestionChoices().get(question));
        }
        final AnswerWeb[] answers1 = new AnswerWeb[4];
        answers1[0] = new AnswerWeb("1", "answer_1", BigDecimal.TEN);
        answers1[1] = new AnswerWeb("2", "answer_2", BigDecimal.ONE);
        answers1[2] = new AnswerWeb("3", "answer_3", BigDecimal.TEN);
        answers1[3] = new AnswerWeb("4", "answer_4", BigDecimal.ONE);

        final AnswerWeb[] answers2 = new AnswerWeb[1];
        answers2[0] = new AnswerWeb("1", "yes", BigDecimal.TEN);

        final QuestionWeb[] questions = new QuestionWeb[3];
        questions[0] = new QuestionWeb("1", "question_1_multi", answers1, true, 1);
        questions[1] = new QuestionWeb("2", "question_2_yes_no", answers2, false, 1);
        questions[2] = new QuestionWeb("3", "question_3_no_vote", new AnswerWeb[0], false, 1);
        return new RequestResult<>(new VotingInfoWeb(questions, new BigDecimal(22), 57000L), null);
    } catch (Exception e) {
        log.error("vote method failed. cookie={}; votingId={}; votingChoice={}", cookie, votingId, votingChoice,
                e);
        return new RequestResult<>(APIException.UNKNOWN_EXCEPTION);
    }
}

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

public void save(ActionEvent event) {
    try {//  ww w  . j  a  va2s.co m
        if (CollectionUtils.isEmpty(this.getListaParametro())) {
            this.setListaParametro(Collections.EMPTY_LIST);
        }
        Parametro parametro = new Parametro();
        parametro.setVnombre(this.getNombre());
        parametro.setVvalor(this.getValor());
        parametro.setVdescripcion(this.getDescripcion());
        if (!errorValidation(parametro)) {
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User user = loginMB.getUser();
            ParametroService service = (ParametroService) ServiceFinder.findBean("ParametroService");
            parametro.setNparametroid(service.getNextPK());
            parametro.setVnombre(StringUtils.upperCase(this.getNombre().trim()));
            parametro.setVvalor(this.getValor());
            parametro.setVdescripcion(StringUtils.capitalize(this.getDescripcion().trim()));
            parametro.setNactivo(BigDecimal.ONE);
            parametro.setDfechacreacion(new Date());
            parametro.setVusuariocreacion(user.getVlogin());
            service.saveOrUpdate(parametro);
            this.setListaParametro(service.getParametros());
            this.cleanAttributes();
            RequestContext.getCurrentInstance().execute("PF('newDialog').hide();");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.benfante.minimark.blo.ImporterBo.java

public List<Question> readQuestionSet(Reader r) throws ParseException, IOException {
    List<Question> result = new LinkedList<Question>();
    int lineCount = 0;
    String line = null;//from w w  w  . j  a v  a  2s.c  om
    BufferedReader br = null;
    if (r instanceof BufferedReader) {
        br = (BufferedReader) r;
    } else {
        br = new BufferedReader(r);
    }
    endstream: while ((line = br.readLine()) != null) {
        lineCount++;
        // skip empty and comment lines
        if (StringUtils.isBlank(line) || line.charAt(0) == 'c') {
            continue;
        }
        char questionType = 0;
        String questionId = "";
        StringBuffer questionText = new StringBuffer();
        List<FixedAnswer> answers = new LinkedList<FixedAnswer>();
        String tmp;
        if (line.charAt(0) != 'd') {
            throw new ParseException("Start of question not found", lineCount);
        }
        StringTokenizer tk = new StringTokenizer(line, "|");
        tk.nextToken(); // skip the initial 'd'
        // question id
        tmp = tk.nextToken();
        if (tmp != null) {
            questionId = tmp;
        } else {
            throw new ParseException("Question id not found", lineCount);
        }
        // question type
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            questionType = Character.toUpperCase(tmp.charAt(0));
            if ((questionType != 'A') && (questionType != 'R') && (questionType != 'C')
                    && (questionType != 'T')) {
                throw new ParseException("Question type unknown", lineCount);
            }
        } else {
            throw new ParseException("Question type not found", lineCount);
        }
        // answer scrambling flag
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            //                char acf = tmp.charAt(0);
            //                switch (acf) {
            //                    case 'u':
            //                        answerScrambling = false;
            //                        break;
            //                    case 's':
            //                        answerScrambling = true;
            //                        break;
            //                    default:
            //                        throw new ParseException("Answer scrambling flag unknown", lineCount);
            //                }
        } else {
            throw new ParseException("Answer scrambling flag not found", lineCount);
        }
        // question text
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            questionText.append(tmp);
            if ((questionType == 'A') || (questionType == 'T')) { // multiline questions
                while ((line = br.readLine()) != null) {
                    lineCount++;
                    if (StringUtils.isBlank(line)) {
                        break;
                    }
                    questionText.append('\n').append(line);
                }
            }
        } else {
            throw new ParseException("Question text not found", lineCount);
        }
        // suggested answers
        if ((questionType == 'R') || (questionType == 'C')) {
            while ((line = br.readLine()) != null) {
                lineCount++;
                if (StringUtils.isBlank(line)) {
                    break;
                }
                tk = new StringTokenizer(line, "|");
                // correct char
                tmp = tk.nextToken();
                boolean correct = false;
                if ((tmp != null) && (tmp.length() > 0)) {
                    char correctChar = line.charAt(0);
                    if (correctChar == 'y') {
                        correct = true;
                    } else if (correctChar == 'n') {
                        correct = false;
                    } else {
                        throw new ParseException("Correct char unknown", lineCount);
                    }
                } else {
                    throw new ParseException("Correct char not found (" + tmp + ")", lineCount);
                }
                tmp = tk.nextToken();
                String answerText = null;
                if ((tmp != null) && (tmp.length() > 0)) {
                    answerText = tmp;
                } else {
                    throw new ParseException("Answer text not found", lineCount);
                }
                FixedAnswer fixedAnswer = new FixedAnswer();
                fixedAnswer.setContent(answerText);
                fixedAnswer.setContentFilter(TextFilterUtils.HTML_FILTER_CODE);
                fixedAnswer.setCorrect(correct);
                fixedAnswer.setWeight(BigDecimal.ONE);
                answers.add(fixedAnswer);
            }
        }
        Question newQuestion = makeQuestion(questionType, questionId, questionText.toString(), answers);
        result.add(newQuestion);
    }
    return result;
}

From source file:org.openvpms.hl7.impl.TestPharmacyService.java

/**
 * Dispenses an order.//  w w w.j  a  va  2s . c om
 *
 * @param order the order
 */
private void dispense(RDE_O11 order) {
    Connection connection = null;
    try {
        connection = sendContext.newClient(outboundHost, outboundPort, false);

        RXO rxo = order.getORDER().getORDER_DETAIL().getRXO();
        BigDecimal quantity = new BigDecimal(rxo.getRequestedDispenseAmount().getValue());
        if (quantity.compareTo(BigDecimal.ONE) != 0 && dispenses != 1) {
            BigDecimal[] decimals = quantity.divideAndRemainder(BigDecimal.valueOf(dispenses));
            for (int i = 0; i < dispenses; ++i) {
                BigDecimal qty = (i == 0) ? decimals[0].add(decimals[1]) : decimals[0];
                RDS_O13 dispense = createRDS(order, qty);
                send(dispense, connection);
            }
        } else {
            RDS_O13 dispense = createRDS(order, quantity);
            send(dispense, connection);
        }
        if (returnAfterDispense) {
            quantity = quantity.negate();
            RDS_O13 dispense = createRDS(order, quantity);
            send(dispense, connection);
        }
    } catch (Throwable exception) {
        exception.printStackTrace();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:op.care.prescription.DlgOnDemand.java

private ListCellRenderer getRenderer() {
    return new ListCellRenderer() {
        @Override/*  w ww  . j  a v a  2 s . co m*/
        public java.awt.Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected,
                boolean cellHasFocus) {
            String text;
            if (o == null) {
                text = "<i>" + SYSTools.xx("nursingrecords.prescription.dlgOnDemand.noOutcomeCheck") + "</i>";
            } else if (o instanceof BigDecimal) {
                if (o.equals(new BigDecimal("0.5"))) {
                    text = "&frac12; " + SYSTools.xx("misc.msg.Hour");
                } else if (o.equals(BigDecimal.ONE)) {
                    text = "1 " + SYSTools.xx("misc.msg.Hour");
                } else {
                    text = o.toString() + " " + SYSTools.xx("misc.msg.Hours");
                }
            } else {
                text = o.toString();
            }
            return new DefaultListCellRenderer().getListCellRendererComponent(jList,
                    SYSTools.toHTMLForScreen(text), i, isSelected, cellHasFocus);
        }
    };
}

From source file:org.libreplan.web.montecarlo.MonteCarloTask.java

public BigDecimal getOptimisticDurationPercentageUpperLimit() {
    return BigDecimal.ONE;
}

From source file:org.yes.cart.payment.impl.PayPalProPaymentGatewayImpl.java

private NvpBuilder createAuthRequest(final Payment payment, final String paymentAction) {
    final NvpBuilder npvs = new NvpBuilder();
    npvs.addRaw("PAYMENTACTION", paymentAction);
    npvs.addRaw("INVNUM", payment.getOrderShipment());
    npvs.addRaw("CREDITCARDTYPE", payment.getCardType());
    npvs.addRaw("ACCT", payment.getCardNumber());
    npvs.addRaw("EXPDATE", payment.getCardExpireMonth() + payment.getCardExpireYear());
    npvs.addRaw("CVV2", payment.getCardCvv2Code());

    npvs.addRaw("AMT", payment.getPaymentAmount().setScale(2, RoundingMode.HALF_UP).toString());
    npvs.addRaw("CURRENCYCODE", payment.getOrderCurrency());

    int i = 0;//w  w  w .jav a  2s  . c o m

    BigDecimal itemsNetTotal = Total.ZERO;
    BigDecimal ship = Total.ZERO;

    for (final PaymentLine item : payment.getOrderItems()) {

        if (item.isShipment()) {

            ship = item.getUnitPrice();

        } else {

            final BigDecimal intQty = item.getQuantity().setScale(0, RoundingMode.CEILING);

            final String skuName;
            final BigDecimal qty;
            if (MoneyUtils.isFirstEqualToSecond(intQty, item.getQuantity())) {
                // integer qty
                skuName = item.getSkuName();
                qty = intQty.stripTrailingZeros();
            } else {
                // fractional qty
                skuName = item.getQuantity().toPlainString().concat("x ").concat(item.getSkuName());
                qty = BigDecimal.ONE;
            }

            npvs.addEncoded("L_NUMBER" + i,
                    item.getSkuCode().length() > ITEMSKU ? item.getSkuCode().substring(0, ITEMSKU - 1) + "~"
                            : item.getSkuCode());
            npvs.addEncoded("L_NAME" + i,
                    skuName.length() > ITEMNAME ? skuName.substring(0, ITEMNAME - 1) + "~" : skuName);

            npvs.addRaw("L_QTY" + i, qty.stripTrailingZeros().toPlainString());

            final BigDecimal itemNetAmount = item.getUnitPrice().multiply(item.getQuantity())
                    .subtract(item.getTaxAmount()).setScale(Total.ZERO.scale(), RoundingMode.HALF_UP);
            final BigDecimal itemNetPricePerAdjustedQty = itemNetAmount.divide(qty, Total.ZERO.scale(),
                    BigDecimal.ROUND_HALF_UP);
            // Need to do this to overcome rounding
            final BigDecimal restoredNetAmount = itemNetPricePerAdjustedQty.multiply(qty)
                    .setScale(Total.ZERO.scale(), BigDecimal.ROUND_HALF_UP);

            itemsNetTotal = itemsNetTotal.add(restoredNetAmount);
            //                final BigDecimal taxUnit = MoneyUtils.isFirstBiggerThanSecond(item.getTaxAmount(), Total.ZERO) ? item.getTaxAmount().divide(qty, Total.ZERO.scale(), BigDecimal.ROUND_HALF_UP) : Total.ZERO;

            npvs.addRaw("L_AMT" + i, itemNetPricePerAdjustedQty.toPlainString());

            //                npvs.addRaw("L_TAXAMT" + i, taxUnit.toPlainString());

            i++;
        }
    }

    final BigDecimal itemsAndShipping = itemsNetTotal.add(ship);
    final BigDecimal paymentNet = payment.getPaymentAmount().subtract(payment.getTaxAmount());
    if (MoneyUtils.isFirstBiggerThanSecond(itemsAndShipping, paymentNet)) {

        npvs.addRaw("SHIPDISCAMT", paymentNet.subtract(itemsAndShipping).toPlainString());

    }

    npvs.addRaw("ITEMAMT", itemsNetTotal.toPlainString());
    npvs.addRaw("SHIPPINGAMT", ship.toPlainString());
    npvs.addRaw("TAXAMT", payment.getTaxAmount().toPlainString());

    if (payment.getBillingAddress() != null) {
        npvs.addEncoded("EMAIL", payment.getBillingEmail());
        npvs.addEncoded("FIRSTNAME", payment.getBillingAddress().getFirstname());
        npvs.addEncoded("LASTNAME", payment.getBillingAddress().getLastname());
        npvs.addEncoded("STREET", payment.getBillingAddress().getAddrline1());
        if (StringUtils.isNotBlank(payment.getBillingAddress().getAddrline2())) {
            npvs.addEncoded("STREET2", payment.getBillingAddress().getAddrline2());
        }
        npvs.addEncoded("CITY", payment.getBillingAddress().getCity());
        npvs.addEncoded("STATE", payment.getBillingAddress().getStateCode());
        npvs.addEncoded("ZIP", payment.getBillingAddress().getStateCode());
        npvs.addEncoded("COUNTRYCODE", payment.getBillingAddress().getCountryCode());
    }

    if (payment.getShippingAddress() != null) {
        npvs.addEncoded("SHIPTONAME",
                payment.getShippingAddress().getFirstname() + " " + payment.getShippingAddress().getLastname());
        npvs.addEncoded("SHIPTOSTREET", payment.getShippingAddress().getAddrline1());
        if (StringUtils.isNotBlank(payment.getShippingAddress().getAddrline2())) {
            npvs.addEncoded("SHIPTOSTREET2", payment.getShippingAddress().getAddrline2());
        }
        npvs.addEncoded("SHIPTOCITY", payment.getShippingAddress().getCity());
        npvs.addEncoded("SHIPTOSTATE", payment.getShippingAddress().getStateCode());
        npvs.addEncoded("SHIPTOZIP", payment.getShippingAddress().getStateCode());
        npvs.addEncoded("SHIPTOCOUNTRY", payment.getShippingAddress().getCountryCode());
    }

    return npvs;
}

From source file:op.care.prescription.PnlScheduleDose.java

private void txtDoubleFocusLost(FocusEvent e) {
    SYSTools.handleBigDecimalFocusLost(e, BigDecimal.ZERO, new BigDecimal(10000), BigDecimal.ONE);
}

From source file:org.apache.olingo.fit.proxy.v3.InvokeTestITCase.java

@Test
public void changeProductDimensions() {
    // 0. create a product
    final Integer id = 101;

    Product product = container.newEntityInstance(Product.class);
    product.setProductId(id);/*from  w ww .j  av  a  2 s. co m*/
    product.setDescription("New product");

    final Dimensions origDimensions = container.newComplexInstance(Dimensions.class);
    origDimensions.setDepth(BigDecimal.ZERO);
    origDimensions.setHeight(BigDecimal.ZERO);
    origDimensions.setWidth(BigDecimal.ZERO);
    product.setDimensions(origDimensions);

    container.getProduct().add(product);
    container.flush();

    product = container.getProduct().getByKey(id).load();
    assertNotNull(product);
    assertEquals(id, product.getProductId());
    assertEquals(BigDecimal.ZERO, product.getDimensions().getDepth());
    assertEquals(BigDecimal.ZERO, product.getDimensions().getHeight());
    assertEquals(BigDecimal.ZERO, product.getDimensions().getWidth());

    try {
        // 1. invoke action bound to the product just created
        final Dimensions newDimensions = container.newComplexInstance(Dimensions.class);
        newDimensions.setDepth(BigDecimal.ONE);
        newDimensions.setHeight(BigDecimal.ONE);
        newDimensions.setWidth(BigDecimal.ONE);

        product.operations().changeProductDimensions(newDimensions).execute();

        // 2. check that invoked action has effectively run
        product = container.getProduct().getByKey(id).load();
        assertEquals(BigDecimal.ONE, product.getDimensions().getDepth());
        assertEquals(BigDecimal.ONE, product.getDimensions().getHeight());
        assertEquals(BigDecimal.ONE, product.getDimensions().getWidth());
    } catch (Exception e) {
        fail("Should never get here");
    } finally {
        // 3. remove the test product
        container.getProduct().delete(product.getProductId());
        container.flush();
    }
}

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

@Test
public void testGetSkuPriceSearchAndProductDetailsNoPrice() 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");

    context.checking(new Expectations() {
        {//  w w  w.  ja  v a 2 s .  c  o  m
            allowing(cart).getShoppingContext();
            will(returnValue(cartCtx));
            allowing(cartCtx).getShopId();
            will(returnValue(234L));
            allowing(cartCtx).getCustomerShopId();
            will(returnValue(234L));
            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", 234L, null, "EUR", BigDecimal.ONE, false, "P1");
            will(returnValue(null));
        }
    });

    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();

}