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:de.jfachwert.math.Bruch.java

private static Bruch toBruch(BigDecimal decimal) {
    int scale = decimal.scale();
    BigInteger z = decimal.movePointRight(scale).toBigInteger();
    BigInteger n = BigDecimal.ONE.movePointRight(scale).toBigInteger();
    return Bruch.of(z, n).kuerzen();
}

From source file:py.una.pol.karaku.test.test.dao.interceptors.BigDecimalInterceptorTest.java

@Test
public void testBigDecimal() {

    CaseSensitiveTest cst = new CaseSensitiveTest(BigDecimal.ONE);
    interceptorHandler.intercept(Operation.CREATE, cst);

    cst = new CaseSensitiveTest(new BigDecimal("12.01"));
    interceptorHandler.intercept(Operation.CREATE, cst);

    cst = new CaseSensitiveTest(new BigDecimal("0.01"));
    interceptorHandler.intercept(Operation.CREATE, cst);

    cst = new CaseSensitiveTest(new BigDecimal("0000000.01"));
    interceptorHandler.intercept(Operation.CREATE, cst);

    cst = new CaseSensitiveTest(new BigDecimal("100000000.01"));
    interceptorHandler.intercept(Operation.CREATE, cst);

    cst = new CaseSensitiveTest(new BigDecimal("-1.01"));
    interceptorHandler.intercept(Operation.CREATE, cst);
}

From source file:org.apache.hadoop.hbase.client.coprocessor.BigDecimalColumnInterpreter.java

@Override
public BigDecimal increment(BigDecimal val) {
    return ((val == null) ? null : val.add(BigDecimal.ONE));
}

From source file:com.jive.myco.seyren.core.service.notification.HttpNotificationServiceTest.java

@Test
public void checkingOutTheHappyPath() {

    String seyrenUrl = clientDriver.getBaseUrl() + "/seyren";

    when(mockSeyrenConfig.getGraphiteUrl()).thenReturn(clientDriver.getBaseUrl() + "/graphite");
    when(mockSeyrenConfig.getBaseUrl()).thenReturn(seyrenUrl);

    Check check = new Check().withEnabled(true).withName("check-name").withTarget("statsd.metric.name")
            .withState(AlertType.ERROR).withWarn(BigDecimal.ONE).withError(BigDecimal.TEN);

    Subscription subscription = new Subscription().withType(SubscriptionType.HTTP)
            .withTarget(clientDriver.getBaseUrl() + "/myendpoint/thatdoesstuff");

    Alert alert = new Alert().withTarget("the.target.name").withValue(BigDecimal.valueOf(12))
            .withWarn(BigDecimal.valueOf(5)).withError(BigDecimal.valueOf(10)).withFromType(AlertType.WARN)
            .withToType(AlertType.ERROR);

    List<Alert> alerts = Arrays.asList(alert);

    BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();

    clientDriver.addExpectation(// w  ww . j a  va 2s  .  co m
            onRequestTo("/myendpoint/thatdoesstuff").withMethod(Method.POST).capturingBodyIn(bodyCapture),
            giveResponse("success", "text/plain"));

    service.sendNotification(check, subscription, alerts);

    JsonNode node = bodyCapture.getContent();

    assertThat(node, hasJsonPath("$.seyrenUrl", is(seyrenUrl)));
    assertThat(node, hasJsonPath("$.check.name", is("check-name")));
    assertThat(node, hasJsonPath("$.check.state", is("ERROR")));
    assertThat(node, hasJsonPath("$.alerts", hasSize(1)));
    assertThat(node, hasJsonPath("$.alerts[0].target", is("the.target.name")));
    assertThat(node, hasJsonPath("$.alerts[0].value", is(12)));
    assertThat(node, hasJsonPath("$.alerts[0].warn", is(5)));
    assertThat(node, hasJsonPath("$.alerts[0].error", is(10)));
    assertThat(node, hasJsonPath("$.alerts[0].fromType", is("WARN")));
    assertThat(node, hasJsonPath("$.alerts[0].toType", is("ERROR")));
    assertThat(node, hasJsonPath("$.preview", Matchers.startsWith("<br />")));
    assertThat(node, hasJsonPath("$.preview", containsString(check.getTarget())));

    verify(mockSeyrenConfig).getGraphiteUrl();
    verify(mockSeyrenConfig).getBaseUrl();

}

From source file:fakingXmocking.CurrencyConversionHttpClientFake.java

private BigDecimal findConversionRate(String from, String to) {
    BigDecimal rate = currenciesAndRates.get(from + '>' + to);

    if (rate != null) {
        return rate;
    }//from w  ww.  j  a  va2s .co m

    // Special cases:
    if (from.equals(to)) {
        rate = BigDecimal.ONE;
    } else if ("USD".equals(from) && "CNY".equals(to)) {
        rate = BigDecimal.TEN;
    } else if ("CNY".equals(from) && "USD".equals(to)) {
        rate = new BigDecimal("0.1");
    } else {
        rate = DEFAULT_RATE;
    }

    return rate;
}

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

/**
 * {@inheritDoc}//from  w w  w  .ja  v  a  2 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 = slingRepository.loginAdministrative(null);
        Node trackingNode = JcrUtils.deepGetOrCreateNode(session,
                "/activity/" + resourceType + "/" + resourceId);
        if (!trackingNode.hasProperty("count")) {
            trackingNode.setProperty("count", 0);
        }
        if (!trackingNode.hasProperty("sling:resourceType")) {
            trackingNode.setProperty("sling:resourceType", "sakai/resource-activity");
        }
        String generatedNodeName = Base64.encodeBase64URLSafeString(asShorterByteArray(UUID.randomUUID()));
        Node activityNode = trackingNode.addNode(generatedNodeName);
        BigDecimal activityCount = trackingNode.getProperty("count").getDecimal();
        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);
        if (session.hasPendingChanges()) {
            session.save();
        }
    } catch (RepositoryException e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.logout();
        }
    }

}

From source file:org.moserp.product.repository.ProductUtil.java

public void addAttributes(Product product) {
    ProductAttributeValue attributeValue = new ProductAttributeValue();
    attributeValue.setCode("TEST_ATTRIBUTE_VALUE");
    attributeValue.setName("Test Attr. Value");
    attributeValue.setValue(BigDecimal.ONE);
    attributeValue.setUnit(new RestUri("unit link"));
    product.addAttribute(attributeValue);
}

From source file:mobi.nordpos.catalog.action.ProductCreateActionBean.java

public Resolution add() {
    Product product = getProduct();/*from   www. j av a  2 s  . co m*/
    product.setId(UUID.randomUUID().toString());
    try {
        productPersist.init(getDataBaseConnection());
        taxPersist.init(getDataBaseConnection());
        product.setTax(taxPersist.read(product.getTaxCategory().getId()));
        BigDecimal taxRate = product.getTax().getRate();

        if (getIsTaxInclude() && taxRate != BigDecimal.ZERO) {
            BigDecimal bdTaxRateMultiply = taxRate.add(BigDecimal.ONE);
            product.setPriceSell(product.getPriceSell().divide(bdTaxRateMultiply, MathContext.DECIMAL64));
        }

        getContext().getMessages().add(new SimpleMessage(getLocalizationKey("message.Product.added"),
                productPersist.add(product).getName(), product.getProductCategory().getName()));
    } catch (SQLException ex) {
        getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage()));
        return getContext().getSourcePageResolution();
    }
    return new ForwardResolution(CategoryProductListActionBean.class).addParameter("category.id",
            product.getProductCategory().getId());
}

From source file:com.qcadoo.model.internal.units.UnitConversionImpl.java

@Override
public UnitConversion reverse() {
    return new UnitConversionImpl(unitTo, unitFrom, BigDecimal.ONE.divide(ratio, mathContext), mathContext);
}

From source file:com.seyren.core.service.notification.BigPandaNotificationServiceTest.java

@Test
public void checkingOutTheHappyPath() {

    String seyrenUrl = clientDriver.getBaseUrl() + "/seyren";

    when(mockSeyrenConfig.getGraphiteUrl()).thenReturn(clientDriver.getBaseUrl() + "/graphite");
    when(mockSeyrenConfig.getBaseUrl()).thenReturn(seyrenUrl);
    when(mockSeyrenConfig.getBigPandaNotificationUrl())
            .thenReturn(clientDriver.getBaseUrl() + "/bigpanda/test");
    when(mockSeyrenConfig.getBigPandaAuthBearer()).thenReturn("test-auth-bearer");

    Check check = new Check().withEnabled(true).withName("check-name").withDescription("Testing Description")
            .withTarget("the.target.name").withState(AlertType.ERROR).withWarn(BigDecimal.ONE)
            .withError(BigDecimal.TEN).withId("testing");

    Subscription subscription = new Subscription().withType(SubscriptionType.BIGPANDA)
            .withTarget("testing_app_key");

    DateTime timestamp = new DateTime(1420070400000L);

    Alert alert = new Alert().withTarget("the.target.name").withValue(BigDecimal.valueOf(12))
            .withWarn(BigDecimal.valueOf(5)).withError(BigDecimal.valueOf(10)).withFromType(AlertType.WARN)
            .withToType(AlertType.ERROR).withTimestamp(timestamp);

    List<Alert> alerts = Arrays.asList(alert);

    BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();

    clientDriver.addExpectation(//from w w  w.  j  a v  a2  s.c o m
            onRequestTo("/bigpanda/test").withMethod(Method.POST).capturingBodyIn(bodyCapture),
            giveResponse("success", "text/plain"));

    service.sendNotification(check, subscription, alerts);

    JsonNode node = bodyCapture.getContent();

    assertThat(node, hasJsonPath("$.seyrenCheckUrl", is(seyrenUrl + "/#/checks/" + check.getId())));
    assertThat(node, hasJsonPath("$.app_key", is("testing_app_key")));
    assertThat(node, hasJsonPath("$.check", is("the.target.name")));
    assertThat(node, hasJsonPath("$.status", is("critical")));
    assertThat(node, hasJsonPath("$.service", is("check-name")));
    assertThat(node, hasJsonPath("$.description", is("Testing Description")));
    assertThat(node, hasJsonPath("$.timestamp", is(1420070400L)));
    assertThat(node, hasJsonPath("$.currentValue", is(12)));
    assertThat(node, hasJsonPath("$.thresholdWarning", is(5)));
    assertThat(node, hasJsonPath("$.thresholdCritical", is(10)));
    assertThat(node, hasJsonPath("$.previewGraph", containsString("the.target.name")));
    assertThat(node, hasJsonPath("$.previewGraph", containsString("/graphite")));

}