Example usage for java.math BigDecimal getClass

List of usage examples for java.math BigDecimal getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.swingtech.commons.util.ClassUtil.java

/**
 * NOTE: When using this to print an object it will not display the
 * primitive type boolean. Must use the wrapper class. All other primitives
 * work fine./*w ww. jav  a2  s . c  o m*/
 *
 * NOTE: If an int value has a 0 it won't display.
 *
 * NOTE: Object must have a public constructor.
 *
 * @param object
 * @return
 */
public static String getXMLForObject(final Object object) {
    ByteArrayOutputStream baos = null;
    XMLEncoder e = null;

    baos = new ByteArrayOutputStream();
    e = new XMLEncoder(new BufferedOutputStream(baos));

    e.setPersistenceDelegate(Date.class, new PersistenceDelegate() {
        @Override
        protected Expression instantiate(final Object oldInstance, final Encoder out) {
            final Date date = (Date) oldInstance;
            final Long time = new Long(date.getTime());
            return new Expression(date, date.getClass(), "new", new Object[] { time });
        }
    });

    e.setPersistenceDelegate(BigDecimal.class, new PersistenceDelegate() {
        @Override
        protected Expression instantiate(final Object oldInstance, final Encoder out) {
            final BigDecimal bigDec = (BigDecimal) oldInstance;
            final double doubleVal = bigDec.doubleValue();
            return new Expression(bigDec, bigDec.getClass(), "new", new Object[] { new Double(doubleVal) });
        }
    });

    e.writeObject(object);
    e.close();

    return baos.toString();
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationPropertiesWithBigDecimalArray() {
    ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray();

    BigDecimal bigDecimalValue = config.bigDecimalArray[0];

    assertEquals(BigDecimal.class, bigDecimalValue.getClass());
    assertEquals(3, config.bigDecimalArray.length);
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationXMLWithBigDecimalArray() {
    ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray();

    BigDecimal bigDecimalValue = config.bigDecimalArray[0];

    assertEquals(BigDecimal.class, bigDecimalValue.getClass());
    assertEquals(3, config.bigDecimalArray.length);
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationPropertiesWithBigDecimalList() {
    ConfigurationPropertiesWithList config = prepareConfigurationPropertiesWithList();

    BigDecimal bigDecimalValue = config.bigDecimalList.get(0);

    assertEquals(BigDecimal.class, bigDecimalValue.getClass());
    assertEquals(3, config.bigDecimalList.size());
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationXMLWithBigDecimalList() {
    ConfigurationXMLWithList config = prepareConfigurationXMLWithList();

    BigDecimal bigDecimalValue = config.bigDecimalList.get(0);

    assertEquals(BigDecimal.class, bigDecimalValue.getClass());
    assertEquals(3, config.bigDecimalList.size());
}

From source file:org.kuali.rice.core.api.criteria.CriteriaDecimalValue.java

/**
 * Since BigDecimal is not technically immutable we defensively copy when needed.
 *
 * see Effective Java 2nd ed. page 79 for details.
 *
 * @param val the big decimal to check//from w ww  . j  a  v  a 2 s. c o m
 * @return the safe BigDecimal
 */
private static BigDecimal safeInstance(BigDecimal val) {
    if (val.getClass() != BigDecimal.class) {
        return new BigDecimal(val.toPlainString());
    }
    return val;
}

From source file:org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement.java

/**
 * Sets the BigDecimal property in the paramMap. Special implementation note - Null values aren't supported in
 * the Map. So, if a null value is passed in, this implementation will remove the entry from the map.
 * //from w  ww  . j  av a 2  s  .c o m
 * @param key
 *          Key in the paramMap.
 * @param value
 *          The property value to set.
 */
public void setBigDecimalProperty(final String key, final BigDecimal value) {
    this.updateOk();
    trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setBigDecimal", key)); //$NON-NLS-1$ //$NON-NLS-2$
    Map theMap = getParamMapBD();
    if (value != null) {
        checkType(key, value.getClass().getName(), true);
        theMap.put(key, value.toString());
    } else {
        theMap.remove(key);
    }
}

From source file:org.pentaho.platform.repository.runtime.RuntimeElement.java

/**
 * Sets the BigDecimal property in the paramMap. Special implementation note - Null values aren't supported in
 * the Map. So, if a null value is passed in, this implementation will remove the entry from the map.
 * /*from   ww w.  java2  s  .co  m*/
 * @param key
 *          Key in the paramMap.
 * @param value
 *          The property value to set.
 */
public void setBigDecimalProperty(final String key, final BigDecimal value) {
    this.updateOk();
    trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setBigDecimal", key)); //$NON-NLS-1$ //$NON-NLS-2$
    checkType(key, value.getClass().getName(), true);
    Map theMap = getParamMapBD();
    if (value != null) {
        theMap.put(key, value.toString());
    } else {
        theMap.remove(key);
    }
}