Example usage for java.math BigDecimal TEN

List of usage examples for java.math BigDecimal TEN

Introduction

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

Prototype

BigDecimal TEN

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

Click Source Link

Document

The value 10, with a scale of 0.

Usage

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static String printZahl102(BigDecimal value) {
    if (value == null || value.compareTo(BigDecimal.ZERO) != 1 || value.compareTo(BigDecimal.TEN.pow(8)) != -1)
        throw new IllegalArgumentException("Can't print decimal value '" + value + "'!");
    else/*from   w ww. j a v a2s  .c  om*/
        return DatatypeConverter.printDecimal(value.setScale(2, BigDecimal.ROUND_HALF_UP));
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testUpdateBoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, 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> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);/*from   w  w  w  . j  a v a  2 s.c o  m*/
    Event event = pair.getKey();
    TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
    TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), "default", 20,
            new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null);
    eventManager.updateCategory(category.getId(), event.getId(), tcm, pair.getValue());
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertEquals(0, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:org.onehippo.repository.mock.MockNodeTest.java

@Test
public void testVariousTypesOfProperties() throws RepositoryException, IOException {
    MockNode root = MockNode.root();//from   www .  jav  a 2  s . c  om
    MockNode node = root.addNode("node1", "nt:unstructured");

    Calendar now = Calendar.getInstance();
    byte[] binaryData = new byte[1];

    node.setProperty("string1", "stringvalue1");
    node.setProperty("boolean1", true);
    node.setProperty("long1", Long.MAX_VALUE);
    node.setProperty("date1", now);
    node.setProperty("double1", Double.MAX_VALUE);
    node.setProperty("bigdecimal1", BigDecimal.TEN);
    node.setProperty("binary", new MockBinary(new ByteArrayInputStream(binaryData)));

    assertTrue(node.getProperty("boolean1").getBoolean());
    assertEquals(Long.MAX_VALUE, node.getProperty("long1").getLong());
    assertEquals(ISO8601.format(now), ISO8601.format(node.getProperty("date1").getDate()));
    assertEquals(Double.toString(Double.MAX_VALUE), Double.toString(node.getProperty("double1").getDouble()));
    assertEquals(BigDecimal.TEN, node.getProperty("bigdecimal1").getDecimal());
    assertEquals("stringvalue1", node.getProperty("string1").getString());
    assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(binaryData),
            node.getProperty("binary").getBinary().getStream()));

    node.setProperty("stringarray1", new String[] { "stringvalue1", "stringvalue2" });
    node.setProperty("booleanarray1", new MockValue[] { new MockValue(PropertyType.BOOLEAN, "true"),
            new MockValue(PropertyType.BOOLEAN, "false") });
    node.setProperty("longarray1", new MockValue[] { new MockValue(PropertyType.LONG, "123"),
            new MockValue(PropertyType.LONG, "456") });
    node.setProperty("datearray1",
            new MockValue[] { new MockValue(PropertyType.DATE, "2013-10-30T00:00:00.000Z"),
                    new MockValue(PropertyType.DATE, "2013-10-31T00:00:00.000Z") });
    node.setProperty("doublearray1", new MockValue[] { new MockValue(PropertyType.DOUBLE, "1.23"),
            new MockValue(PropertyType.DOUBLE, "4.56") });
    node.setProperty("bigdecimalarray1", new MockValue[] { new MockValue(PropertyType.DECIMAL, "1.23E3"),
            new MockValue(PropertyType.DECIMAL, "4.56E3") });

    Value[] values = node.getProperty("stringarray1").getValues();
    assertEquals(2, values.length);
    assertEquals("stringvalue1", values[0].getString());
    assertEquals("stringvalue2", values[1].getString());

    values = node.getProperty("booleanarray1").getValues();
    assertEquals(2, values.length);
    assertEquals(true, values[0].getBoolean());
    assertEquals(false, values[1].getBoolean());

    values = node.getProperty("longarray1").getValues();
    assertEquals(2, values.length);
    assertEquals(123, values[0].getLong());
    assertEquals(456, values[1].getLong());

    values = node.getProperty("datearray1").getValues();
    assertEquals(2, values.length);
    assertEquals("2013-10-30T00:00:00.000Z", ISO8601.format(values[0].getDate()));
    assertEquals("2013-10-31T00:00:00.000Z", ISO8601.format(values[1].getDate()));

    values = node.getProperty("doublearray1").getValues();
    assertEquals(2, values.length);
    assertEquals(Double.toString(1.23d), Double.toString(values[0].getDouble()));
    assertEquals(Double.toString(4.56), Double.toString(values[1].getDouble()));

    values = node.getProperty("bigdecimalarray1").getValues();
    assertEquals(2, values.length);
    assertEquals(new BigDecimal("1.23E3"), values[0].getDecimal());
    assertEquals(new BigDecimal("4.56E3"), values[1].getDecimal());
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static String printZahl152(BigDecimal value) {
    if (value == null || value.compareTo(BigDecimal.ZERO) != 1 || value.compareTo(BigDecimal.TEN.pow(13)) != -1)
        throw new IllegalArgumentException("Can't print decimal value '" + value + "'!");
    else/*from  w  w w  .  j a v a2  s .c om*/
        return DatatypeConverter.printDecimal(value.setScale(2, BigDecimal.ROUND_HALF_UP));
}

From source file:fragment.web.AbstractCampaignPromotionsControllerTest.java

@Test
public void testGetCampaignPromotionFromForm() throws Exception {
    try {/*from w w w .j a v  a2 s.com*/
        Channel channel = channelService.getChannelById("3");
        List<String> channelIdLst = new ArrayList<String>();
        channelIdLst.add("3");
        CampaignPromotion campaignPromotion = generateCampaignPromotion(-2, false, false, true);
        CampaignPromotionsForm form = new CampaignPromotionsForm();
        form.setChannelIdLst(channelIdLst);
        form.setPromoCode("trial_camp");
        form.setUnlimited(true);
        form.setCampaignPromotion(campaignPromotion);
        BindingResult result = validate(form);
        CampaignPromotion promotion = campaignController.createCampaigns(form, result, map, null);
        Assert.assertNotNull(promotion);
        Assert.assertEquals(promotion.getDiscountType(), DiscountType.PERCENTAGE);
        Assert.assertEquals(promotion.getPercentOff(), BigDecimal.TEN);
        Assert.assertEquals(promotion.getPromoCode(), "trial_camp");
        Iterator<CampaignPromotionsInChannels> itr = promotion.getCampaignPromotionsInChannels().iterator();
        CampaignPromotionsInChannels objCampPromo = null;
        objCampPromo = itr.next();
        Assert.assertEquals(objCampPromo.getChannel(), channel);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Assert.fail();
    }
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testUpdateEventHeader() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, 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> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);//from  w  w  w. j  av a2 s .c  o  m
    Event event = pair.getLeft();
    String username = pair.getRight();

    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description new");
    desc.put("it", "muh description new");
    desc.put("de", "muh description new");

    EventModification em = new EventModification(event.getId(), Event.EventType.INTERNAL,
            "http://example.com/new", null, "http://example.com/tc", "https://example.com/img.png", null,
            event.getShortName(), "new display name", event.getOrganizationId(), event.getLocation(), "0.0",
            "0.0", ZoneId.systemDefault().getId(), desc,
            DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd().plusDays(42)), event.getRegularPrice(),
            event.getCurrency(), eventRepository.countExistingTickets(event.getId()), event.getVat(),
            event.isVatIncluded(), event.getAllowedPaymentProxies(), Collections.emptyList(), false, null, 7,
            null, null);

    eventManager.updateEventHeader(event, em, username);

    Event updatedEvent = eventRepository.findById(event.getId());

    Assert.assertEquals("http://example.com/new", updatedEvent.getWebsiteUrl());
    Assert.assertEquals("http://example.com/tc", updatedEvent.getTermsAndConditionsUrl());
    Assert.assertEquals("https://example.com/img.png", updatedEvent.getImageUrl());
    Assert.assertEquals("new display name", updatedEvent.getDisplayName());
}

From source file:org.apache.olingo.fit.proxy.APIBasicDesignTestITCase.java

/**
 * Java client should support the deletion based on locally created entity.
 * See also <a href="https://issues.apache.org/jira/browse/OLINGO-395">Olingo Issue 395</a>.
 *///  www  .  j  a v  a2 s . c o  m
@Test
public void issueOLINGO395() {
    Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    orderDate.clear();
    orderDate.set(2011, 3, 4, 16, 3, 57);
    order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));

    order.setShelfLife(BigDecimal.ZERO);

    final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);

    order.setOrderShelfLifes(osl);

    getContainer().getOrders().add(order);
    getContainer().getOrders().delete(order);

    getContainer().flush();

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected Exception
    }
    service.getContext().detachAll(); // avoid influences

    order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    getContainer().getOrders().delete(order);
    getContainer().flush(); // test service doesn't fail for delete requests about unexisting objects

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected Exception
    }
    service.getContext().detachAll(); // avoid influences
}

From source file:org.apache.olingo.fit.proxy.v4.APIBasicDesignTestITCase.java

/**
 * Java client should support the deletion based on locally created entity.
 * See also <a href="https://issues.apache.org/jira/browse/OLINGO-395">Olingo Issue 395</a>.
 *///from  w  w  w. j  a  v a 2  s .c  om
@Test
public void issueOLINGO395() {
    Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    orderDate.clear();
    orderDate.set(2011, 3, 4, 16, 3, 57);
    order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));

    order.setShelfLife(BigDecimal.ZERO);

    final PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);

    order.setOrderShelfLifes(osl);

    getContainer().getOrders().add(order);
    getContainer().getOrders().delete(order);

    getContainer().flush();

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
    }
    service.getContext().detachAll(); // avoid influences

    order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(1105);

    getContainer().getOrders().delete(order);
    getContainer().flush(); // test service doesn't fail for delete requests about unexisting objects

    service.getContext().detachAll();
    try {
        getContainer().getOrders().getByKey(1105).load();
        fail();
    } catch (IllegalArgumentException e) {
    }
    service.getContext().detachAll(); // avoid influences
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testNoPublicCategoryAvailable() {
    LocalDateTime start = LocalDateTime.now().minusHours(1);
    LocalDateTime end = LocalDateTime.now().plusHours(1);

    List<TicketCategoryModification> categories = Arrays.asList(
            new TicketCategoryModification(null, "default", 2,
                    new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
                    new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN,
                    false, "", true, null, null, null, null, null),
            new TicketCategoryModification(null, "default2", 10,
                    new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
                    new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN,
                    true, "", true, null, null, null, null, null));

    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    Pair<Event, String> eventAndUsername = initEvent(categories, organizationRepository, userManager,
            eventManager, eventRepository);
    Event event = eventAndUsername.getKey();
    List<TicketCategory> ticketCategories = ticketCategoryRepository.findByEventId(event.getId());
    TicketCategory first = ticketCategories.stream().filter(tc -> !tc.isAccessRestricted()).findFirst()
            .orElseThrow(IllegalStateException::new);
    reserveTickets(event, first, 2);/*from  w  w  w .j  ava 2s .c o  m*/
    assertTrue(
            waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));
    assertTrue(waitingQueueManager.subscribe(event, new CustomerName("John Doe 2", "John", "Doe 2", event),
            "john@doe2.com", null, Locale.ENGLISH));

    ZoneId zoneId = event.getZoneId();
    Result<TicketCategory> ticketCategoryResult = eventManager.updateCategory(first.getId(), event,
            new TicketCategoryModification(first.getId(), first.getName(), 3,
                    fromZonedDateTime(first.getInception(zoneId)),
                    fromZonedDateTime(first.getExpiration(zoneId)), Collections.emptyMap(), first.getPrice(),
                    false, "", true, null, null, null, null, null),
            eventAndUsername.getValue());
    assertTrue(ticketCategoryResult.isSuccess());
    assertEquals(1, ticketRepository.countReleasedTicketInCategory(event.getId(), first.getId()).intValue());
    //now we should have an extra available ticket
    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager
            .distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
}

From source file:org.apache.olingo.server.core.serializer.json.EdmAssistedJsonSerializerTest.java

@Test
public void entityCollectionWithComplexPropertyMetadataMin() throws Exception {
    Entity entity = new Entity();
    entity.setId(null);/*w ww .  ja v  a  2  s .c o m*/
    entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
    ComplexValue complexValue = new ComplexValue();
    complexValue.getValue()
            .add(new Property(null, "Inner1", ValueType.PRIMITIVE, BigDecimal.TEN.scaleByPowerOfTen(-5)));
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY, 13);
    time.set(Calendar.SECOND, 59);
    time.set(Calendar.MILLISECOND, 999);
    complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
    entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
    EntityCollection entityCollection = new EntityCollection();
    entityCollection.getEntities().add(entity);
    Assert.assertEquals(
            "{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\"," + "\"value\":[{"
                    + "\"Property1\":1," + "\"Property2\":{" + "\"Inner1\":0.00010,"
                    + "\"Inner2\":\"13:00:59.999\"}}]}",
            serialize(serializerMin, metadata, null, entityCollection, null));
}