Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

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

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

From source file:de.urszeidler.ethereum.licencemanager1.deployer.LicenseManagerDeployer.java

/**
 * @param args//from www.  j  a va2s  .  c  o  m
 */
public static void main(String[] args) {
    Options options = createOptions();
    CommandLineParser parser = new DefaultParser();
    int returnValue = 0;
    boolean dontExit = false;
    try {
        CommandLine commandLine = parser.parse(options, args);
        if (commandLine.hasOption("h")) {
            printHelp(options);
            return;
        }
        if (commandLine.hasOption("de"))
            dontExit = true;

        String senderKey = null;
        String senderPass = null;
        if (commandLine.hasOption("sk"))
            senderKey = commandLine.getOptionValue("sk");
        if (commandLine.hasOption("sp"))
            senderPass = commandLine.getOptionValue("sp");

        LicenseManagerDeployer manager = new LicenseManagerDeployer();

        try {
            manager.init(senderKey, senderPass);

            long currentMili = 0;
            EthValue balance = null;
            if (commandLine.hasOption("calcDeploymendCost")) {
                currentMili = System.currentTimeMillis();
                balance = manager.ethereum.getBalance(manager.sender);
            }
            if (commandLine.hasOption("observeBlock")) {
                manager.ethereum.events().observeBlocks()
                        .subscribe(b -> System.out.println("Block: " + b.blockNumber + " " + b.receipts));
            }

            if (commandLine.hasOption("f")) {
                String[] values = commandLine.getOptionValues("f");

                String filename = values[0];
                String isCompiled = values[1];
                manager.deployer.setContractSource(filename, Boolean.parseBoolean(isCompiled));
            }
            if (commandLine.hasOption("millis")) {
                manager.setMillis(Long.parseLong(commandLine.getOptionValue("millis")));
            }

            if (commandLine.hasOption("c")) {
                String[] values = commandLine.getOptionValues("c");
                if (values == null || values.length != 2) {
                    System.out.println("Error. Need 2 parameters: paymentAddress,name");
                    System.out.println("");
                    printHelp(options);
                    return;
                }

                String paymentAddress = values[0];
                String name = values[1];
                manager.deployLicenseManager(EthAddress.of(paymentAddress), name);
            } else if (commandLine.hasOption("l")) {
                String contractAddress = commandLine.getOptionValue("l");
                if (contractAddress == null) {
                    System.out.println("Error. Need 1 parameters: contract address");
                    System.out.println("");
                    printHelp(options);
                    return;
                }
                manager.setManager(EthAddress.of(contractAddress));
                manager.listContractData(EthAddress.of(contractAddress));
            } else if (commandLine.hasOption("cic")) {
                String[] values = commandLine.getOptionValues("cic");
                if (values == null || values.length != 6) {
                    System.out.println("Error. Need 6 itemName, textHash, url, lifeTime, price");
                    System.out.println("");
                    printHelp(options);
                    return;
                }
                String contractAddress = values[0];
                String itemName = values[1];
                String textHash = values[2];
                String url = values[3];
                String lifeTime = values[4];
                String price = values[5];

                manager.setManager(EthAddress.of(contractAddress));
                manager.createIssuerContract(itemName, textHash, url, Integer.parseInt(lifeTime),
                        Integer.parseInt(price));
            } else if (commandLine.hasOption("bli")) {
                String[] values = commandLine.getOptionValues("bli");
                if (values == null || values.length < 2 || values.length > 3) {
                    System.out.println(
                            "Error. Need 2-3 issuerAddress, name, optional an address when not use the sender.");
                    System.out.println("");
                    printHelp(options);
                    return;
                }
                String issuerAddress = values[0];
                String name = values[1];
                String address = values.length > 2 ? values[2] : null;

                manager.buyLicense(issuerAddress, name, address);
            } else if (commandLine.hasOption("v")) {
                String[] values = commandLine.getOptionValues("v");

                String issuerAddress = values[0];
                String message = values[1];
                String signature = values[2];
                String publicKey = values[3];

                manager.verifyLicense(issuerAddress, message, signature, publicKey);
            } else if (commandLine.hasOption("cs")) {
                String message = commandLine.getOptionValue("cs");
                if (message == null) {
                    System.out.println("Error. Need 1 parameter: message");
                    System.out.println("");
                    printHelp(options);
                    return;
                }
                String signature = createSignature(manager.sender, message);
                String publicKeyString = toPublicKeyString(manager.sender);
                System.out.println("The signature for the message is:");
                System.out.println(signature);
                System.out.println("The public key is:");
                System.out.println(publicKeyString);
            } else if (commandLine.hasOption("co")) {
                String[] values = commandLine.getOptionValues("co");
                if (values == null || values.length != 2) {
                    System.out.println("Error. Need 2 parameters: contractAddress, newOwnerAddress");
                    System.out.println("");
                    printHelp(options);
                    return;
                }

                String contractAddress = values[0];
                String newOwner = values[1];

                manager.changeOwner(EthAddress.of(contractAddress), EthAddress.of(newOwner));
            } else if (commandLine.hasOption("si")) {
                String contractAddress = commandLine.getOptionValue("si");
                if (contractAddress == null) {
                    System.out.println("Error. Need 1 parameters: contract address");
                    System.out.println("");
                    printHelp(options);
                    return;
                }
                manager.setManager(EthAddress.of(contractAddress));
                manager.stopIssue(contractAddress);
            } else if (commandLine.hasOption("ppuk")) {
                System.out.println("Public key: " + toPublicKeyString(manager.sender));
            }

            if (manager.licenseManager != null && commandLine.hasOption("wca")) {
                String[] values = commandLine.getOptionValues("wca");
                String filename = values[0];

                File file = new File(filename);
                IOUtils.write(
                        !commandLine.hasOption("cic") ? manager.licenseManager.contractAddress.withLeading0x()
                                : manager.licenseManager.contractInstance
                                        .contracts(manager.licenseManager.contractInstance.contractCount() - 1)
                                        .withLeading0x(),
                        new FileOutputStream(file), "UTF-8");
            }

            if (commandLine.hasOption("calcDeploymendCost")) {
                balance = balance.minus(manager.ethereum.getBalance(manager.sender));
                BigDecimal divide = new BigDecimal(balance.inWei())
                        .divide(BigDecimal.valueOf(1_000_000_000_000_000_000L));

                System.out.println("Deployment cost: " + (divide) + " in wei:" + balance.inWei()
                        + " time need: " + (System.currentTimeMillis() - currentMili));
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
            printHelp(options);
            returnValue = 10;
        }

    } catch (ParseException e1) {
        System.out.println(e1.getMessage());
        printHelp(options);
        returnValue = 10;
    }
    if (!dontExit)
        System.exit(returnValue);
}

From source file:be.ceau.chart.dataset.LineDataset.java

/**
 * Sets the backing data list to the argument, replacing any data already
 * added or set/*  w  w  w  .  j a v a2s  .c om*/
 * 
 * @param data
 *            The data to plot in a line
 */
public LineDataset setData(int... data) {
    clearData();
    if (data != null) {
        for (int i = 0; i < data.length; i++) {
            this.data.add(new BigDecimal(data[i]));
        }
    }
    return this;
}

From source file:be.ceau.chart.dataset.PolarDataset.java

/**
 * Sets the backing data list to the argument, replacing any data already
 * added or set//w ww .ja  va2  s. c o  m
 * 
 * @param data
 *            The data to plot in a line
 */
public PolarDataset setData(int... data) {
    clearData();
    if (data != null) {
        for (int i = 0; i < data.length; i++) {
            this.data.add(new BigDecimal(data[i]));
        }
    }
    return this;
}

From source file:edu.usu.sdl.openstorefront.validation.MaxValueRule.java

@Override
protected boolean validate(Field field, Object dataObject) {
    boolean valid = true;

    Max max = field.getAnnotation(Max.class);
    if (max != null) {
        try {/*  w w  w . ja v  a  2  s  .  co m*/
            String value = BeanUtils.getProperty(dataObject, field.getName());
            if (value != null) {
                try {
                    BigDecimal numberValue = new BigDecimal(value);
                    if (numberValue.compareTo(BigDecimal.valueOf(max.value())) == 1) {
                        valid = false;
                    }
                } catch (NumberFormatException e) {
                    throw new OpenStorefrontRuntimeException("This annotation is for numbers only",
                            "Programming error");
                }
            }
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
            throw new OpenStorefrontRuntimeException("Unexpected error occur trying to get value from object.",
                    ex);
        }
    }
    return valid;
}

From source file:edu.usu.sdl.openstorefront.validation.MinValueRule.java

@Override
protected boolean validate(Field field, Object dataObject) {
    boolean valid = true;

    Min min = field.getAnnotation(Min.class);
    if (min != null) {
        try {//from www. j a  v  a  2s.  c  o m
            String value = BeanUtils.getProperty(dataObject, field.getName());
            if (value != null) {
                try {
                    BigDecimal numberValue = new BigDecimal(value);
                    if (numberValue.compareTo(BigDecimal.valueOf(min.value())) == -1) {
                        valid = false;
                    }
                } catch (NumberFormatException e) {
                    throw new OpenStorefrontRuntimeException("This annotation is for numbers only",
                            "Programming error");
                }
            }
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
            throw new OpenStorefrontRuntimeException("Unexpected error occur trying to get value from object.",
                    ex);
        }
    }
    return valid;
}

From source file:lcn.module.batch.web.guide.service.GeneratingTradeItemReader.java

public Trade read() throws Exception {
    if (counter < limit) {
        counter++;/*from  w w w . j  a  v a 2 s  .  c om*/
        return new Trade("isin" + counter, counter, new BigDecimal(counter), "customer" + counter);
    }
    return null;
}

From source file:com.hangum.tadpole.engine.query.dao.rdb.OracleSequenceDAO.java

public OracleSequenceDAO() {
    this("", "", 0, new BigDecimal(0), 0);
}

From source file:example.springdata.rest.projections.Application.java

public @PostConstruct void init() {

    Customer dave = customers.save(new Customer("Dave", "Matthews", Gender.MALE, //
            new Address("4711 Some Place", "54321", "Charlottesville", "VA")));

    Order order = new Order();

    order.setCustomer(dave);//from   ww  w .j  av a 2  s  .  c om
    order.add(new LineItem("Lakewood guitar", new BigDecimal(1299.0)));

    orders.save(order);
}

From source file:it.mexican.demo.springdatajpa.factory.LoyaltyRepositoryImpl.java

public void logicalDelete(T entity) {
    ((Fields) entity).setDateDelete(new Date());
    ((Fields) entity).setUserDelete(new BigDecimal(0));
    super.save(entity);
}

From source file:cz.muni.fi.dndtroops.facade.TroopFacadeImplTest.java

@BeforeMethod
public void prepareHeroes() {
    troop1 = new TroopCreateDTO();
    troop1.setName("Troop A");
    troop1.setMission("mission");
    troop1.setMoney(new BigDecimal("11"));

    List<TroopDTO> list = troopFacade.getAllTroops();
    for (TroopDTO t : list) {
        troopFacade.deleteTroop(t.getId());
    }/*from  www . ja  va  2s . co  m*/

    heroA = new HeroCreateDTO();
    heroA.setName("Hero A");
    heroA.setLevel(1);
    heroA.setRole(RoleName.BARD);

}