Example usage for java.math BigDecimal shortValue

List of usage examples for java.math BigDecimal shortValue

Introduction

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

Prototype

public short shortValue() 

Source Link

Document

Returns the value of the specified number as a short .

Usage

From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java

/**
 * Converts a list of BigDecimals to a list of shorts.
 * @param    List<BigDecimal>    list of BigDecimals
 * @return                       list of shorts
 *///from w  w  w . j ava 2  s .  c om
public static List<Short> toShortList(List<BigDecimal> list) {

    List<Short> shortList = new ArrayList<Short>();

    for (BigDecimal val : list) {
        if (!OverFlowUtil.shortOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
        shortList.add(val.shortValue());
    }

    return shortList;

}

From source file:com.ipcglobal.fredimport.xls.DistinctCategoriesSpreadsheet.java

/**
 * Populate cell.// w  w  w  .  j  a  v  a 2  s. com
 *
 * @param rowData the row data
 * @param colCnt the col cnt
 * @param dataType the data type
 * @param obj the obj
 * @throws Exception the exception
 */
private void populateCell(Row rowData, int colCnt, DataType dataType, Object obj) throws Exception {
    int cellType = 0;

    if (dataType == DataType.Numeric)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.NumericDec2)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.Text)
        cellType = XSSFCell.CELL_TYPE_STRING;
    else if (dataType == DataType.Date)
        cellType = XSSFCell.CELL_TYPE_STRING;
    else if (dataType == DataType.Accounting)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    else if (dataType == DataType.Percent)
        cellType = XSSFCell.CELL_TYPE_NUMERIC;
    Cell cellData = rowData.createCell(colCnt, cellType);

    short findFormat = -1;
    if (dataType == DataType.Date)
        findFormat = formatMmDdYyyy;
    else if (dataType == DataType.Percent)
        findFormat = formatPercent;
    else if (dataType == DataType.Accounting)
        findFormat = formatAccounting;
    else if (dataType == DataType.Numeric)
        findFormat = formatNumeric;
    else if (dataType == DataType.NumericDec2)
        findFormat = formatNumericDec2;
    else
        findFormat = formatGeneral;
    CellStyle style = findCellStyle("Arial", HSSFColor.BLACK.index, (short) 11, XSSFFont.BOLDWEIGHT_NORMAL,
            cellStyleFromDataAlign(findAlignByDataType(dataType)), XSSFCellStyle.VERTICAL_TOP, BG_COLOR_NONE,
            CellBorder.All_Thin, findFormat);
    cellData.setCellStyle(style);

    if (dataType == DataType.Numeric || dataType == DataType.NumericDec2 || dataType == DataType.Accounting
            || dataType == DataType.Percent) {
        if (obj == null)
            ; // leave the cell empty
        else if (obj instanceof BigDecimal) {
            BigDecimal value = (BigDecimal) obj;
            if (value != null)
                cellData.setCellValue(value.doubleValue());
        } else if (obj instanceof Integer) {
            Integer value = (Integer) obj;
            if (value != null)
                cellData.setCellValue(value.intValue());
        } else if (obj instanceof Long) {
            Long value = (Long) obj;
            if (value != null)
                cellData.setCellValue(value.longValue());
        } else if (obj instanceof Double) {
            Double value = (Double) obj;
            if (value != null)
                cellData.setCellValue(value.doubleValue());
        } else if (obj instanceof Short) {
            Short value = (Short) obj;
            if (value != null)
                cellData.setCellValue(value.shortValue());
        } else if (obj instanceof String) {
            String value = (String) obj;
            if (value != null)
                cellData.setCellValue(value);
        } else
            throw new Exception("Unsupported numeric type: " + obj.getClass().getSimpleName());
    } else if (dataType == DataType.Date) {
        Date date = (Date) obj;
        if (date != null)
            cellData.setCellValue(date);
    } else {
        cellData.setCellValue((String) obj);
    }
}

From source file:org.kalypso.model.wspm.tuhh.core.wprof.BCEShapeWPRofContentProvider.java

private <T> T toNumber(final BigDecimal in, final Class<T> outType) {
    if (Byte.class == outType)
        return outType.cast(in.byteValue());
    if (Short.class == outType)
        return outType.cast(in.shortValue());
    if (Integer.class == outType)
        return outType.cast(in.intValue());
    if (Long.class == outType)
        return outType.cast(in.longValue());
    if (Float.class == outType)
        return outType.cast(in.floatValue());
    if (Double.class == outType)
        return outType.cast(in.doubleValue());

    if (BigInteger.class == outType)
        return outType.cast(in.toBigInteger());

    return outType.cast(in);
}

From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java

/**
 * Convert a {@link BigDecimal} to another type
 * /* w w w.j  av  a 2 s  . c  o m*/
 * @param type
 *            the class to convert too
 * @param value
 *            the value to convert
 * @return Number
 *            the converted number of null.
 *            
 */
protected Number allocateNumber(Class type, BigDecimal value) {
    if (type == Byte.class || type == byte.class) {
        return new Byte(value.byteValue());
    }
    if (type == Short.class || type == short.class) {
        return new Short(value.shortValue());
    }
    if (type == Integer.class || type == int.class) {
        return new Integer(value.intValue());
    }
    if (type == Long.class || type == long.class) {
        return new Long(value.longValue());
    }
    if (type == Float.class || type == float.class) {
        return new Float(value.floatValue());
    }
    if (type == Double.class || type == double.class) {
        return new Double(value.doubleValue());
    }
    if (type == BigDecimal.class) {
        return value;
    }
    if (type == BigInteger.class) {
        return BigInteger.valueOf(value.longValue());
    }

    if (type == Money.class) {
        return new Money((BigDecimal) value);
    }

    return null;
}