Example usage for java.math BigDecimal valueOf

List of usage examples for java.math BigDecimal valueOf

Introduction

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

Prototype

public static BigDecimal valueOf(double val) 

Source Link

Document

Translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double#toString(double) method.

Usage

From source file:edu.harvard.mcz.imagecapture.GeoreferenceDialog.java

private boolean saveData() {
    boolean result = true;
    this.okButton.grabFocus();
    if (textFieldDecimalLat.getText().length() > 0) {
        try {//from  w ww  .j av  a2s  .co m
            georeference.setDecLat(BigDecimal.valueOf(Double.parseDouble(textFieldDecimalLat.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Latitude number format");
            result = false;
        }
    }
    if (textFieldDecimalLong.getText().length() > 0) {
        try {
            georeference.setDecLong(BigDecimal.valueOf(Double.parseDouble(textFieldDecimalLong.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Longitude number format");
            result = false;
        }
    }
    if (cbDatum.getSelectedItem() != null) {
        georeference.setDatum(cbDatum.getSelectedItem().toString());
    }
    if (cbMethod.getSelectedItem() != null) {
        georeference.setGeorefmethod(cbMethod.getSelectedItem().toString());
    }

    if (txtGPSAccuracy.getText().length() > 0) {
        try {
            georeference.setGpsaccuracy(BigDecimal.valueOf(Double.parseDouble(txtGPSAccuracy.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: GPS Accuracy number format");
            result = false;
        }
    }

    if (comboBoxOrigUnits.getSelectedItem() != null) {
        georeference.setOrigLatLongUnits(comboBoxOrigUnits.getSelectedItem().toString());
    }

    if (txtLatDegrees.getText().length() > 0) {
        try {
            georeference.setLatDeg(Integer.parseInt(txtLatDegrees.getText()));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Lat Degrees number format");
            result = false;
        }
    }
    if (txtLatDecMin.getText().length() > 0) {
        try {
            georeference.setDecLatMin(BigDecimal.valueOf(Double.parseDouble(txtLatDecMin.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Lat Dec Min number format");
            result = false;
        }
    }
    if (txtLatMin.getText().length() > 0) {
        try {
            georeference.setLatMin(Integer.parseInt(txtLatMin.getText()));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Lat Min number format");
            result = false;
        }
    }
    if (txtLatSec.getText().length() > 0) {
        try {
            georeference.setLatSec(BigDecimal.valueOf(Double.parseDouble(txtLatSec.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Lat Degrees number format");
            result = false;
        }
    }
    if (cbLatDir.getSelectedItem() != null) {
        georeference.setLatDir(cbLatDir.getSelectedItem().toString());
    }

    if (txtLongDegrees.getText().length() > 0) {
        try {
            georeference.setLongDeg(Integer.parseInt(txtLongDegrees.getText()));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Long Degrees number format");
            result = false;
        }
    }
    if (txtLongDecMin.getText().length() > 0) {
        try {
            georeference.setDecLongMin(BigDecimal.valueOf(Double.parseDouble(txtLongDecMin.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Long Dec Min number format");
            result = false;
        }
    }
    if (txtLongMin.getText().length() > 0) {
        try {
            georeference.setLongMin(Integer.parseInt(txtLongMin.getText()));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Long Min number format");
            result = false;
        }
    }
    if (txtLongSec.getText().length() > 0) {
        try {
            georeference.setLongSec(BigDecimal.valueOf(Double.parseDouble(txtLongSec.getText())));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Long Degrees number format");
            result = false;
        }
    }
    if (cbLongDir.getSelectedItem() != null) {
        georeference.setLongDir(cbLongDir.getSelectedItem().toString());
    }

    if (txtErrorRadius.getText().length() > 0) {
        try {
            georeference.setMaxErrorDistance(Integer.parseInt(txtErrorRadius.getText()));
        } catch (NumberFormatException e) {
            lblErrorLabel.setText("Error: Error radius number format");
            result = false;
        }
    }

    if (comboBoxErrorUnits.getSelectedItem() != null) {
        georeference.setMaxErrorUnits(comboBoxErrorUnits.getSelectedItem().toString());
    }

    georeference.setDeterminedByAgent(this.textFieldDetBy.getText());

    try {
        georeference.setDeterminedDate(new SimpleDateFormat("yyyy-MM-dd").parse(this.textDetDate.getText()));
    } catch (ParseException e) {
        lblErrorLabel.setText("Error: Error date determined format");
        result = false;
    }

    georeference.setLatLongRefSource(this.textRefSource.getText());

    georeference.setLatLongRemarks(this.textFieldRemarks.getText());

    return result;
}

From source file:net.ceos.project.poi.annotated.bean.ObjectMaskBuilder.java

/**
 * Transform BigDecimal values to validate.
 * //from  w  w  w.j av  a 2 s  . c o  m
 * @param fieldName
 * @param value
 * @return
 */
private static BigDecimal transformValuesToValidate(String fieldName, BigDecimal value) {
    ObjectMask a = new ObjectMask();
    try {
        Field f = a.getClass().getDeclaredField(fieldName);

        if (f.isAnnotationPresent(XlsElement.class)) {
            XlsElement xlsAnnotation = (XlsElement) f.getAnnotation(XlsElement.class);

            if (StringUtils.isNotBlank(xlsAnnotation.transformMask())) {
                DecimalFormat df = new DecimalFormat(xlsAnnotation.transformMask());
                String formattedValue = df.format((BigDecimal) value);
                value = BigDecimal.valueOf(Double.valueOf(formattedValue.replace(",", ".")));
            }
        }

    } catch (NoSuchFieldException | SecurityException e) {
        e.printStackTrace();
    }
    return value;
}

From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java

@Override
public byte[] encodeInt(Object data) throws EBusTypeException {

    IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD);
    IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD);
    IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR);

    Calendar calendar = null;/*  www  . j  av a  2  s  .  c o m*/
    byte[] result = new byte[this.getTypeLength()];

    if (data instanceof EBusDateTime) {
        calendar = ((EBusDateTime) data).getCalendar();

    } else if (data instanceof Calendar) {
        calendar = (Calendar) data;
    }

    // set date to midnight
    calendar = (Calendar) calendar.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    if (calendar != null) {
        if (StringUtils.equals(variant, DEFAULT)) {

            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
            dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1;

            result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0],
                    bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(dayOfWeek)[0],
                    bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] };

        } else if (StringUtils.equals(variant, SHORT)) {

            result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0],
                    bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0],
                    bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] };

        } else if (StringUtils.equals(variant, HEX)) {

            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
            dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1;

            result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0],
                    charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(dayOfWeek)[0],
                    charType.encode(calendar.get(Calendar.YEAR) % 100)[0] };

        } else if (StringUtils.equals(variant, HEX_SHORT)) {

            result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0],
                    charType.encode(calendar.get(Calendar.MONTH) + 1)[0],
                    charType.encode(calendar.get(Calendar.YEAR) % 100)[0] };

        } else if (StringUtils.equals(variant, DAYS)) {

            long millis = calendar.getTimeInMillis();

            calendar.clear();
            calendar.set(1900, 0, 1, 0, 0);
            long millis1900 = calendar.getTimeInMillis();

            BigDecimal days = new BigDecimal(millis - millis1900);
            days = days.divide(BigDecimal.valueOf(86400000), 0, RoundingMode.HALF_UP);

            result = wordType.encode(days);
        }
    }

    return result;
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#add(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *//*w w  w  . jav a  2  s.com*/
@SuppressWarnings("unchecked")
@Test
public void testAddObjectNumberClassOfT() {
    assertEquals("null", null, add(null, null, null));
    assertEquals("null", null, add("123.456", null, null));
    assertEquals("null", null, add("123.456", 1, null));
    assertEquals("null", null, add("", 10, null));
    assertEquals("null", null, add(null, 10, null));
    assertEquals("null", null, add(123.456, 10, null));
    assertEquals("123 + .456: Float", (Object) 123.456f, add(123, .456, Float.class));
    assertEquals("123 + .456: Float", (Object) Float.class, add(123, .456, Float.class).getClass());
    assertEquals("123 + .456: Float", (Object) Float.class, add(123L, .456d, Float.class).getClass());
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            assertEquals("null: default: " + type.getSimpleName(), valueOf(null, typeOfN),
                    add(null, null, typeOfN));
            assertEquals("123.456: " + type.getSimpleName(), valueOf(123 + .456, typeOfN),
                    add("123", .456, typeOfN));
            assertEquals("NaN + 123: " + type.getSimpleName(), valueOf(123, typeOfN), add("NaN", 123, typeOfN));
            assertEquals("123 + NaN: " + type.getSimpleName(), valueOf("123", typeOfN),
                    add("123", Float.NaN, typeOfN));
            assertEquals("invalid + 123: " + type.getSimpleName(), valueOf(123, typeOfN),
                    add("not a number", 123, typeOfN));
            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("-Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("-Infinity", 123, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("Infinity", 123, typeOfN));

            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 - Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.NEGATIVE_INFINITY, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 + Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.POSITIVE_INFINITY, typeOfN));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:gov.nih.nci.iso21090.hibernate.tuple.IsoConstantTuplizerHelper.java

private Object convertValue(Object value, Class targetType) {
    if (value == null) {
        return null;
    }//from   w ww .  ja v a2s. co  m
    if (targetType.isAssignableFrom(value.getClass())) {
        return value;
    }

    try {

        if (value.getClass() == String.class) {
            if (Boolean.class == targetType) {
                if ("1".equals(value)) {
                    return Boolean.TRUE;
                } else if ("0".equals(value)) {
                    return Boolean.FALSE;
                } else {
                    return Boolean.valueOf((String) value);
                }
            } else if (Integer.class == targetType) {
                return Integer.valueOf((String) value);
            } else if (BigDecimal.class == targetType) {
                return BigDecimal.valueOf(Double.valueOf((String) value));
            } else if (URI.class == targetType) {
                return new URI((String) value);
            }
        }
    } catch (Exception e) {
        throw new HibernateException(
                "Error in converting String tyoe to " + targetType.getName() + " for " + value, e);
    }
    throw new HibernateException("Can not convert Non-String type to target type of " + targetType.getName());
}

From source file:com.wicht.benchmark.utils.Benchs.java

/**
 * Compute the values of the benchmarks to get the optimal prefix for the results.
 *
 * @param benchmarks The benchmarks to compute.
 *
 * @return The Prefix for the results.//  ww  w.j av a2 s  . c  om
 */
private static Prefix computeOptimalPrefix(Iterable<NamedBenchmark> benchmarks) {
    Prefix maxPrefix = null;

    for (NamedBenchmark benchmark : benchmarks) {
        BigDecimal mean = BigDecimal.valueOf(benchmark.getMean());

        Prefix prefix = Prefix.getScalePrefix(mean.doubleValue());

        maxPrefix = max(maxPrefix, prefix);
    }

    return maxPrefix;
}

From source file:com.streamsets.pipeline.stage.it.DecimalTypeIT.java

@Test
public void zeroScale() throws Exception {
    executeUpdate("CREATE TABLE `tbl` (id int, dec decimal(2, 0)) PARTITIONED BY (dt string) STORED AS AVRO");

    HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().decimalConfig(2, 0).build();
    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build();

    List<Record> records = new LinkedList<>();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("id", Field.create(Field.Type.INTEGER, 1));
    map.put("dec", Field.create(BigDecimal.valueOf(12)));
    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));
    records.add(record);/*  w  w w .  ja  va  2s .c  om*/

    processRecords(processor, hiveTarget, records);

    assertQueryResult("select * from tbl order by id", new QueryValidator() {
        @Override
        public void validateResultSet(ResultSet rs) throws Exception {
            assertResultSetStructure(rs, new ImmutablePair("tbl.id", Types.INTEGER),
                    new ImmutablePair("tbl.dec", Types.DECIMAL), new ImmutablePair("tbl.dt", Types.VARCHAR));

            Assert.assertTrue("Table tbl doesn't contain any rows", rs.next());
            Assert.assertEquals(1, rs.getLong(1));
            Assert.assertEquals(BigDecimal.valueOf(12), rs.getBigDecimal(2));

            Assert.assertFalse("Unexpected number of rows", rs.next());
        }
    });
}

From source file:com.opengamma.bloombergexample.loader.ExampleBondPortfolioLoader.java

/**
 * Create a position of a random number of shares.
 * <p>/*w ww  .jav a 2 s .com*/
 * This creates the position using a random number of units.
 * 
 * @param security  the security to add a position for, not null
 * @return the position, not null
 */
protected ManageablePosition createPosition(BondSecurity security) {
    s_logger.warn("Creating position {}", security);
    int shares = (RandomUtils.nextInt(490) + 10) * 10;
    ExternalId buid = security.getExternalIdBundle().getExternalId(ExternalSchemes.BLOOMBERG_BUID);
    ExternalIdBundle bundle;
    if (buid != null) {
        bundle = ExternalIdBundle.of(buid);
    } else {
        bundle = security.getExternalIdBundle();
    }
    return new ManageablePosition(BigDecimal.valueOf(shares), bundle);
}

From source file:churashima.action.manage.ExpensesAction.java

@Execute(input = "expenses.jsp")
public String entryExecute() {

    ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class);
    SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class);

    Expenses expenses = new Expenses();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");

    try {//from w  w w .  jav  a 2s.c om
        expenses.date = sdf.parse(expensesForm.strDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    if (expensesForm.subjectId == null) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.required", //??????
                new Object[] { "" }));
        ActionMessagesUtil.addErrors(RequestUtil.getRequest(), errors);

        expensesForm.subjectList = subjectDao.selectForSearch(null, null);

        return "expenses.jsp";
    }

    expenses.subjectId = expensesForm.subjectId;
    expenses.place = expensesForm.place;
    expenses.name = expensesForm.name;
    expenses.comment = expensesForm.comment;
    expenses.category = expensesForm.category;
    expenses.categoryDetail = expensesForm.detail;
    expenses.openFlg = expensesForm.openFlg;
    expenses.isExcludeTax = expensesForm.isExcludeTax;

    TaxDao taxDao = SingletonS2Container.getComponent(TaxDao.class);
    BigDecimal tax = taxDao.selectByDate(expenses.date);

    if (Const.TAX_EXCLUDE.equals(expensesForm.isExcludeTax)) {
        // ?????
        expenses.priceTax = expensesForm.price.multiply(tax);
        expenses.priceExcludeTax = expensesForm.price;
        expenses.price = expenses.priceExcludeTax.add(expenses.priceTax);

    } else {
        // ????
        expenses.price = expensesForm.price;
        expenses.priceExcludeTax = expensesForm.price.divide(BigDecimal.valueOf(1).add(tax), 3,
                BigDecimal.ROUND_HALF_UP); // ?
        expenses.priceTax = expenses.price.subtract(expenses.priceExcludeTax);
    }

    // 
    Timestamp now = new Timestamp(System.currentTimeMillis());
    expenses.deleted = false;
    expenses.updDate = now;
    expenses.updId = null;
    expenses.insDate = now;
    expenses.insId = null;

    try {
        expensesDao.insert(expenses);
    } catch (SQLRuntimeException e) {
        SQLException e2 = (SQLException) e.getCause();
        if (e2.getErrorCode() == 0) {

            //???
            ActionMessages errors = new ActionMessages();
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.already.entried", //??????
                    new Object[] { "????" }));
            ActionMessagesUtil.addErrors(RequestUtil.getRequest(), errors);

            return "/manage/expenses";
        }
    }
    return "/manage/expenses";
}

From source file:com.stratio.ingestion.sink.cassandra.EventParserTest.java

@Test
public void shouldParsePrimitiveTypes() throws Exception {
    Object integer = EventParser.parseValue("1", DataType.Name.INT);
    assertThat(integer).isInstanceOf(Integer.class).isEqualTo(1);
    integer = EventParser.parseValue(Integer.toString(Integer.MAX_VALUE), DataType.Name.INT);
    assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MAX_VALUE);
    integer = EventParser.parseValue(Integer.toString(Integer.MIN_VALUE), DataType.Name.INT);
    assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MIN_VALUE);
    integer = EventParser.parseValue(" 1 2 ", DataType.Name.INT);
    assertThat(integer).isInstanceOf(Integer.class).isEqualTo(12);

    Object counter = EventParser.parseValue("1", DataType.Name.COUNTER);
    assertThat(counter).isEqualTo(1L);/*from  www.  j  ava  2s.co  m*/
    counter = EventParser.parseValue(Long.toString(Long.MAX_VALUE), DataType.Name.COUNTER);
    assertThat(counter).isEqualTo(Long.MAX_VALUE);
    counter = EventParser.parseValue(Long.toString(Long.MIN_VALUE), DataType.Name.COUNTER);
    assertThat(counter).isEqualTo(Long.MIN_VALUE);
    counter = EventParser.parseValue(" 1 2 ", DataType.Name.COUNTER);
    assertThat(counter).isEqualTo(12L);

    Object _float = EventParser.parseValue("1", DataType.Name.FLOAT);
    assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f);
    _float = EventParser.parseValue("1.0", DataType.Name.FLOAT);
    assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f);
    _float = EventParser.parseValue(Float.toString(Float.MAX_VALUE), DataType.Name.FLOAT);
    assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MAX_VALUE);
    _float = EventParser.parseValue(Float.toString(Float.MIN_VALUE), DataType.Name.FLOAT);
    assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MIN_VALUE);
    _float = EventParser.parseValue(" 1 . 0 ", DataType.Name.FLOAT);
    assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f);

    Object _double = EventParser.parseValue("1", DataType.Name.DOUBLE);
    assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0);
    _double = EventParser.parseValue("0", DataType.Name.DOUBLE);
    assertThat(_double).isInstanceOf(Double.class).isEqualTo(0.0);
    _double = EventParser.parseValue(Double.toString(Double.MAX_VALUE), DataType.Name.DOUBLE);
    assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MAX_VALUE);
    _double = EventParser.parseValue(Double.toString(Double.MIN_VALUE), DataType.Name.DOUBLE);
    assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MIN_VALUE);
    _double = EventParser.parseValue(" 1 . 0 ", DataType.Name.DOUBLE);
    assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0);

    for (DataType.Name type : Arrays.asList(DataType.Name.BIGINT)) {
        Object bigInteger = EventParser.parseValue("1", type);
        assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(1L);
        bigInteger = EventParser.parseValue("0", type);
        assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(0L);
        bigInteger = EventParser.parseValue(Long.toString(Long.MAX_VALUE), type);
        assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MAX_VALUE);
        bigInteger = EventParser.parseValue(Long.toString(Long.MIN_VALUE), type);
        assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MIN_VALUE);
    }

    for (DataType.Name type : Arrays.asList(DataType.Name.VARINT)) {
        Object bigInteger = EventParser.parseValue("1", type);
        assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ONE);
        bigInteger = EventParser.parseValue("0", type);
        assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ZERO);
        bigInteger = EventParser.parseValue(
                BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type);
        assertThat(bigInteger).isInstanceOf(BigInteger.class)
                .isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L)));
        bigInteger = EventParser.parseValue(
                BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type);
        assertThat(bigInteger).isInstanceOf(BigInteger.class)
                .isEqualTo(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L)));
    }

    Object bigDecimal = EventParser.parseValue("1", DataType.Name.DECIMAL);
    assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(1));
    bigDecimal = EventParser.parseValue("0", DataType.Name.DECIMAL);
    assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(0));
    bigDecimal = EventParser.parseValue(
            BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2)).toString(),
            DataType.Name.DECIMAL);
    assertThat(bigDecimal).isInstanceOf(BigDecimal.class)
            .isEqualTo(BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2)));
    bigDecimal = EventParser.parseValue(
            BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2)).toString(),
            DataType.Name.DECIMAL);
    assertThat(bigDecimal).isInstanceOf(BigDecimal.class)
            .isEqualTo(BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2)));
    bigDecimal = EventParser.parseValue(" 1 2 ", DataType.Name.DECIMAL);
    assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(12));

    Object string = EventParser.parseValue("string", DataType.Name.TEXT);
    assertThat(string).isInstanceOf(String.class).isEqualTo("string");

    Object bool = EventParser.parseValue("true", DataType.Name.BOOLEAN);
    assertThat(bool).isInstanceOf(Boolean.class).isEqualTo(true);

    Object addr = EventParser.parseValue("192.168.1.1", DataType.Name.INET);
    assertThat(addr).isInstanceOf(InetAddress.class).isEqualTo(InetAddress.getByName("192.168.1.1"));

    UUID randomUUID = UUID.randomUUID();
    Object uuid = EventParser.parseValue(randomUUID.toString(), DataType.Name.UUID);
    assertThat(uuid).isInstanceOf(UUID.class).isEqualTo(randomUUID);
}