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:org.openinfobutton.responder.service.impl.ResponderServiceImplMockitoTest.java

private Collection<Asset> getTestAssets() {

    Collection<Asset> assets = new ArrayList<>();

    Asset a1 = new Asset();
    a1.setAssetId(BigDecimal.ONE);
    a1.setDisplayName("a1");

    Asset a10 = new Asset();
    a10.setAssetId(BigDecimal.TEN);
    a10.setDisplayName("a10");

    assets.add(a1);/*from   w w w  . j av a  2s  . c o  m*/
    assets.add(a10);

    return assets;

}

From source file:op.care.prescription.DlgOnDemand.java

private void txtEDosisFocusLost(FocusEvent e) {
    SYSTools.handleBigDecimalFocusLost(e, new BigDecimal(BigInteger.ZERO), new BigDecimal(1000),
            BigDecimal.ONE);
}

From source file:com.opengamma.web.analytics.blotter.OtcTradeBuilder.java

private ManageableTrade buildTrade(BeanDataSource tradeData) {
    ManageableTrade.Meta meta = ManageableTrade.meta();
    BeanBuilder<? extends ManageableTrade> tradeBuilder = tradeBuilder(tradeData, meta.uniqueId(),
            meta.tradeDate(), meta.tradeTime(), meta.premium(), meta.premiumCurrency(), meta.premiumDate(),
            meta.premiumTime());//from  ww w .ja  va 2 s.  c om
    tradeBuilder.set(meta.attributes(), tradeData.getMapValues(meta.attributes().name()));
    tradeBuilder.set(meta.quantity(), BigDecimal.ONE);
    // the link needs to be non-null but the real ID can't be set until the security has been created later
    tradeBuilder.set(meta.securityLink(), new ManageableSecurityLink());
    String counterparty = (String) tradeData.getValue(COUNTERPARTY);
    if (StringUtils.isEmpty(counterparty)) {
        counterparty = DEFAULT_COUNTERPARTY;
    }
    tradeBuilder.set(meta.counterpartyExternalId(), ExternalId.of(CPTY_SCHEME, counterparty));
    return tradeBuilder.build();
}

From source file:org.openhab.io.transport.modbus.ModbusBitUtilities.java

/**
 * Convert command to array of registers using a specific value type
 *
 * @param command command to be converted
 * @param type value type to use in conversion
 * @return array of registers//from w ww.j  a  v a 2s .  c o m
 * @throws NotImplementedException in cases where implementation is lacking for the type. This is thrown with 1-bit
 *             and 8-bit value types
 */
public static ModbusRegisterArray commandToRegisters(Command command, ModbusConstants.ValueType type) {
    DecimalType numericCommand;
    if (command instanceof OnOffType || command instanceof OpenClosedType) {
        numericCommand = translateCommand2Boolean(command).get() ? new DecimalType(BigDecimal.ONE)
                : DecimalType.ZERO;
    } else if (command instanceof DecimalType) {
        numericCommand = (DecimalType) command;
    } else {
        throw new NotImplementedException(String.format(
                "Command '%s' of class '%s' cannot be converted to registers. Please use OnOffType, OpenClosedType, or DecimalType commands.",
                command, command.getClass().getName()));
    }
    if (type.getBits() != 16 && type.getBits() != 32 && type.getBits() != 64) {
        throw new IllegalArgumentException(String.format(
                "Illegal type=%s (bits=%d). Only 16bit and 32bit types are supported", type, type.getBits()));
    }
    switch (type) {
    case INT16:
    case UINT16: {
        short shortValue = numericCommand.shortValue();
        // big endian byte ordering
        byte b1 = (byte) (shortValue >> 8);
        byte b2 = (byte) shortValue;

        ModbusRegister register = new BasicModbusRegister(b1, b2);
        return new BasicModbusRegisterArray(new ModbusRegister[] { register });
    }
    case INT32:
    case UINT32: {
        int intValue = numericCommand.intValue();
        // big endian byte ordering
        byte b1 = (byte) (intValue >> 24);
        byte b2 = (byte) (intValue >> 16);
        byte b3 = (byte) (intValue >> 8);
        byte b4 = (byte) intValue;
        ModbusRegister register = new BasicModbusRegister(b1, b2);
        ModbusRegister register2 = new BasicModbusRegister(b3, b4);
        return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 });
    }
    case INT32_SWAP:
    case UINT32_SWAP: {
        int intValue = numericCommand.intValue();
        // big endian byte ordering
        byte b1 = (byte) (intValue >> 24);
        byte b2 = (byte) (intValue >> 16);
        byte b3 = (byte) (intValue >> 8);
        byte b4 = (byte) intValue;
        ModbusRegister register = new BasicModbusRegister(b3, b4);
        ModbusRegister register2 = new BasicModbusRegister(b1, b2);
        return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 });
    }
    case FLOAT32: {
        float floatValue = numericCommand.floatValue();
        int intBits = Float.floatToIntBits(floatValue);
        // big endian byte ordering
        byte b1 = (byte) (intBits >> 24);
        byte b2 = (byte) (intBits >> 16);
        byte b3 = (byte) (intBits >> 8);
        byte b4 = (byte) intBits;
        ModbusRegister register = new BasicModbusRegister(b1, b2);
        ModbusRegister register2 = new BasicModbusRegister(b3, b4);
        return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 });
    }
    case FLOAT32_SWAP: {
        float floatValue = numericCommand.floatValue();
        int intBits = Float.floatToIntBits(floatValue);
        // big endian byte ordering
        byte b1 = (byte) (intBits >> 24);
        byte b2 = (byte) (intBits >> 16);
        byte b3 = (byte) (intBits >> 8);
        byte b4 = (byte) intBits;
        ModbusRegister register = new BasicModbusRegister(b3, b4);
        ModbusRegister register2 = new BasicModbusRegister(b1, b2);
        return new BasicModbusRegisterArray(new ModbusRegister[] { register, register2 });
    }
    case INT64:
    case UINT64: {
        long longValue = numericCommand.longValue();
        // big endian byte ordering
        byte b1 = (byte) (longValue >> 56);
        byte b2 = (byte) (longValue >> 48);
        byte b3 = (byte) (longValue >> 40);
        byte b4 = (byte) (longValue >> 32);
        byte b5 = (byte) (longValue >> 24);
        byte b6 = (byte) (longValue >> 16);
        byte b7 = (byte) (longValue >> 8);
        byte b8 = (byte) longValue;
        return new BasicModbusRegisterArray(
                new ModbusRegister[] { new BasicModbusRegister(b1, b2), new BasicModbusRegister(b3, b4),
                        new BasicModbusRegister(b5, b6), new BasicModbusRegister(b7, b8) });
    }
    case INT64_SWAP:
    case UINT64_SWAP: {
        long longValue = numericCommand.longValue();
        // big endian byte ordering
        byte b1 = (byte) (longValue >> 56);
        byte b2 = (byte) (longValue >> 48);
        byte b3 = (byte) (longValue >> 40);
        byte b4 = (byte) (longValue >> 32);
        byte b5 = (byte) (longValue >> 24);
        byte b6 = (byte) (longValue >> 16);
        byte b7 = (byte) (longValue >> 8);
        byte b8 = (byte) longValue;
        return new BasicModbusRegisterArray(
                new ModbusRegister[] { new BasicModbusRegister(b7, b8), new BasicModbusRegister(b5, b6),
                        new BasicModbusRegister(b3, b4), new BasicModbusRegister(b1, b2) });
    }
    default:
        throw new NotImplementedException(
                String.format("Illegal type=%s. Missing implementation for this type", type));
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.nettoExport.NettoCSVTransformerTest.java

private void prepareTestData() {

    /*// ww w .  j  av a  2  s .  co m
     * Create a Numeric Attribute
     */
    AttributeTypeGroup atg = testDataHelper.createAttributeTypeGroup("test", "test description");
    numberAT = testDataHelper.createNumberAttributeType("Complexity", "description", atg);
    testDataHelper.getBuildingBlockType(TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE)
            .addAttributeTypeTwoWay(numberAT);

    NumberAV numberAV1;
    NumberAV numberAV2;

    numberAV1 = testDataHelper.createNumberAV(BigDecimal.ONE, numberAT);
    numberAV2 = testDataHelper.createNumberAV(BigDecimal.TEN, numberAT);

    sourceList = new ArrayList<BuildingBlock>();

    InformationSystem is = testDataHelper.createInformationSystem("Unit-Test Information-System");
    isArray = new InformationSystemRelease[4];

    isArray[0] = testDataHelper.createInformationSystemRelease(is, "1.0", "Description", "10.10.2015",
            "10.10.2020", TypeOfStatus.PLANNED);
    isArray[1] = testDataHelper.createInformationSystemRelease(is, "2.0", "Description", "11.09.2016",
            "10.10.2020", TypeOfStatus.CURRENT);
    isArray[2] = testDataHelper.createInformationSystemRelease(is, "3.0", "Description", "12.08.2017",
            "10.10.2020", TypeOfStatus.PLANNED);
    isArray[3] = testDataHelper.createInformationSystemRelease(is, "4.0", "Description", "13.07.2018",
            "10.10.2020", TypeOfStatus.CURRENT);

    testDataHelper.createAVA(isArray[0], numberAV1);
    testDataHelper.createAVA(isArray[1], numberAV2);
    testDataHelper.createAVA(isArray[2], numberAV1);
    testDataHelper.createAVA(isArray[3], numberAV2);

    sourceList.add(isArray[0]);
    sourceList.add(isArray[1]);
    sourceList.add(isArray[2]);
    sourceList.add(isArray[3]);

}

From source file:com.opengamma.financial.property.DefaultPropertyFunctionsTest.java

private SimpleTrade createTrade(final SecuritySource securities) {
    final SimpleTrade trade = new SimpleTrade();
    trade.setQuantity(BigDecimal.ONE);
    trade.setSecurityLink(createSecurityLink(securities));
    return trade;
}

From source file:org.openinfobutton.responder.service.impl.ResponderServiceImplMockitoTest.java

public List<ValueSetCode> getRxNormFilterValueSet() {

    List<ValueSetCode> valueSet = new ArrayList<>();
    ValueSetCode v1 = new ValueSetCode();
    v1.setValueSetId(BigDecimal.ZERO);
    v1.setCode("A");

    ValueSetCode v2 = new ValueSetCode();
    v2.setValueSetId(BigDecimal.ONE);
    v2.setCode("B");

    valueSet.add(v1);/*  w  w  w .ja  v a 2s  .  c  o  m*/
    valueSet.add(v2);

    return valueSet;
}

From source file:org.marketcetera.saclient.SAClientWSTest.java

@Test
public void setProperties() throws Exception {
    final ModuleURN input1 = new ModuleURN("test:prov:me:A");
    final Map<String, Object> i2 = new HashMap<String, Object>();
    i2.put("first", BigDecimal.ONE);
    i2.put("second", "mnext");
    i2.put("third", 999);
    //Test a non-empty and an empty map.
    List<Map<String, Object>> inputs = Arrays.asList(i2, new HashMap<String, Object>());
    final Map<String, Object> out = new HashMap<String, Object>();
    out.put("first", BigDecimal.TEN);
    out.put("second", "next");
    out.put("third", 909);
    //Test a non-empty and an empty map.
    List<Map<String, Object>> outputs = Arrays.asList(out, new HashMap<String, Object>());
    for (int i = 0; i < inputs.size(); i++) {
        final Map<String, Object> input2 = inputs.get(i);
        final Map<String, Object> output = outputs.get(i);
        testAPI(new WSTester<Map<String, Object>>() {
            @Override//  w  w w.j a v a  2s.  c  o  m
            protected Map<String, Object> invokeApi(boolean isNullParams) throws Exception {
                return getClient().setProperties(isNullParams ? null : input1, isNullParams ? null : input2);
            }

            @Override
            protected Map<String, Object> setReturnValue(boolean isNullParams) {
                getMockSAService()
                        .setPropertiesOut(isNullParams ? null : new MapWrapper<String, Object>(output));
                return isNullParams ? null : output;
            }

            @Override
            protected void verifyInputParams(boolean isNullParams) throws Exception {
                assertEquals(isNullParams ? null : input1, getMockSAService().getURN());
                MapWrapper<String, Object> mapWrapper = getMockSAService().getPropertiesIn();
                verifyEquals(isNullParams ? null : input2, mapWrapper == null ? null : mapWrapper.getMap());
            }
        });
        resetServiceParameters();
    }
}

From source file:org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast.java

@Override
public Result getNextBigDecimal() throws ExecException {
    PhysicalOperator in = inputs.get(0);
    Byte resultType = in.getResultType();
    switch (resultType) {
    case DataType.BAG:
    case DataType.TUPLE:
    case DataType.MAP:
    case DataType.DATETIME:
        return error();

    case DataType.BYTEARRAY: {
        DataByteArray dba;/*from  w w w . j  av a2 s  . c  om*/
        Result res = in.getNextDataByteArray();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            try {
                dba = (DataByteArray) res.result;
            } catch (ClassCastException e) {
                // res.result is not of type ByteArray. But it can be one of the types from which cast is still possible.
                if (realType == null)
                    // Find the type and cache it.
                    realType = DataType.findType(res.result);
                try {
                    res.result = DataType.toBigDecimal(res.result, realType);
                } catch (ClassCastException cce) {
                    // Type has changed. Need to find type again and try casting it again.
                    realType = DataType.findType(res.result);
                    res.result = DataType.toBigDecimal(res.result, realType);
                }
                return res;
            }
            try {
                if (null != caster) {
                    res.result = caster.bytesToBigDecimal(dba.get());
                } else {
                    int errCode = 1075;
                    String msg = unknownByteArrayErrorMessage + "BigDecimal.";
                    throw new ExecException(msg, errCode, PigException.INPUT);
                }
            } catch (ExecException ee) {
                throw ee;
            } catch (IOException e) {
                log.error("Error while casting from ByteArray to BigDecimal");
            }
        }
        return res;
    }

    case DataType.BOOLEAN: {
        Result res = in.getNextBoolean();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            if ((Boolean) res.result) {
                res.result = BigDecimal.ONE;
            } else {
                res.result = BigDecimal.ZERO;
            }
        }
        return res;
    }
    case DataType.INTEGER: {
        Result res = in.getNextInteger();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = BigDecimal.valueOf(((Integer) res.result).longValue());
        }
        return res;
    }

    case DataType.DOUBLE: {
        Result res = in.getNextDouble();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = BigDecimal.valueOf(((Double) res.result).doubleValue());
        }
        return res;
    }

    case DataType.LONG: {
        Result res = in.getNextLong();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = BigDecimal.valueOf(((Long) res.result).longValue());
        }
        return res;
    }

    case DataType.FLOAT: {
        Result res = in.getNextFloat();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = BigDecimal.valueOf(((Float) res.result).doubleValue());
        }
        return res;
    }

    case DataType.CHARARRAY: {
        Result res = in.getNextString();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = new BigDecimal((String) res.result);
        }
        return res;
    }

    case DataType.BIGINTEGER: {
        Result res = in.getNextBigInteger();
        if (res.returnStatus == POStatus.STATUS_OK && res.result != null) {
            res.result = new BigDecimal((BigInteger) res.result);
        }
        return res;
    }

    case DataType.BIGDECIMAL:
        return in.getNextBigDecimal();

    }

    return error();
}

From source file:org.adempiere.webui.dashboard.CalendarWindow.java

private void syncModel() {
    Hashtable<String, BigDecimal> ht = new Hashtable<String, BigDecimal>();

    List<?> list = calendars.getModel().get(calendars.getBeginDate(), calendars.getEndDate(), null);
    int size = list.size();
    for (Iterator<?> it = list.iterator(); it.hasNext();) {
        String key = ((ADCalendarEvent) it.next()).getR_RequestType_ID() + "";

        if (!ht.containsKey(key))
            ht.put(key, BigDecimal.ONE);
        else {/*from  w w w.j av a  2 s. c  o  m*/
            BigDecimal value = ht.get(key);
            ht.put(key, value.add(BigDecimal.ONE));
        }
    }

    Hashtable<Object, String> htTypes = new Hashtable<Object, String>();
    for (int i = 0; i < lbxRequestTypes.getItemCount(); i++) {
        Listitem li = lbxRequestTypes.getItemAtIndex(i);
        if (li != null && li.getValue() != null)
            htTypes.put(li.getValue(), li.getLabel());
    }

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    Enumeration<?> keys = ht.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        BigDecimal value = ht.get(key);
        String name = (String) htTypes.get(key);
        pieDataset.setValue(name == null ? "" : name,
                new Double(size > 0 ? value.doubleValue() / size * 100 : 0));
    }

    JFreeChart chart = ChartFactory.createPieChart3D(Msg.getMsg(Env.getCtx(), "EventsAnalysis"), pieDataset,
            true, true, true);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setForegroundAlpha(0.5f);
    BufferedImage bi = chart.createBufferedImage(600, 250);
    try {
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
        AImage image = new AImage("Pie Chart", bytes);
        myChart.setContent(image);
    } catch (IOException e) {
        e.printStackTrace();
    }
    htTypes = null;
    ht = null;
}