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(long unscaledVal, int scale) 

Source Link

Document

Translates a long unscaled value and an int scale into a BigDecimal .

Usage

From source file:Main.java

public static void main(String... args) {
    long base = 12345;
    int scale = 4;

    BigDecimal number = BigDecimal.valueOf(base, scale);
    System.out.println(number);/*  w  ww .j  a va  2  s  . com*/
    BigDecimal pointRight = number.movePointRight(5);
    System.out.println(pointRight + "; my scale is " + pointRight.scale());
    BigDecimal scaleBy = number.scaleByPowerOfTen(5);
    System.out.println(scaleBy + "; my scale is " + scaleBy.scale());
}

From source file:Main.java

public static void main(String[] args) {
    Long l = new Long("12345678");

    // assign the bigdecimal value of l to bg scale is 4
    BigDecimal bg = BigDecimal.valueOf(l, 4);

    System.out.println(bg);/*from ww w . j  a  va 2s  .c o  m*/
}

From source file:Main.java

public static BigDecimal long2Decimal(long money) {
    return BigDecimal.valueOf(money, 2);
}

From source file:com.aoindustries.website.signup.SignupCustomizeManagementActionHelper.java

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SignupSelectPackageForm signupSelectPackageForm,
        SignupCustomizeServerForm signupCustomizeServerForm,
        SignupCustomizeManagementForm signupCustomizeManagementForm) throws IOException, SQLException {
    AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();
    PackageDefinition packageDefinition = rootConn.getPackageDefinitions()
            .get(signupSelectPackageForm.getPackageDefinition());
    if (packageDefinition == null)
        throw new SQLException(
                "Unable to find PackageDefinition: " + signupSelectPackageForm.getPackageDefinition());
    List<PackageDefinitionLimit> limits = packageDefinition.getLimits();

    // Get the total harddrive space in gigabytes
    int totalHardwareDiskSpace = SignupCustomizeServerActionHelper.getTotalHardwareDiskSpace(rootConn,
            signupCustomizeServerForm);//from  w w w .  ja  v  a 2 s .co m

    // Find all the options
    List<Option> backupOnsiteOptions = new ArrayList<Option>();
    List<Option> backupOffsiteOptions = new ArrayList<Option>();
    List<Option> distributionScanOptions = new ArrayList<Option>();
    List<Option> failoverOptions = new ArrayList<Option>();
    for (PackageDefinitionLimit limit : limits) {
        Resource resource = limit.getResource();
        String resourceName = resource.getName();
        if (resourceName.startsWith("backup_onsite_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower == PackageDefinitionLimit.UNLIMITED || limitPower > 0) {
                // This is per gigabyte of physical space
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                backupOnsiteOptions.add(new Option(limit.getPkey(), resource.toString(),
                        additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace))));
            }
        } else if (resourceName.startsWith("backup_offsite_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower == PackageDefinitionLimit.UNLIMITED || limitPower > 0) {
                // This is per gigabyte of physical space
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                backupOffsiteOptions.add(new Option(limit.getPkey(), resource.toString(),
                        additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace))));
            }
        }
    }
    // Distribution scan option
    {
        Resource resource = rootConn.getResources().get(Resource.DISTRIBUTION_SCAN);
        if (resource == null) {
            servletContext.log(null,
                    new SQLException("Unable to find Resource: " + Resource.DISTRIBUTION_SCAN));
        } else {
            PackageDefinitionLimit limit = packageDefinition.getLimit(resource);
            if (limit != null) {
                int hard = limit.getHardLimit();
                if (hard == PackageDefinitionLimit.UNLIMITED || hard > 0) {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    distributionScanOptions
                            .add(new Option(limit.getPkey(), resource.toString(), additionalRate));
                }
            }
        }
    }
    // Failover option
    {
        Resource resource = rootConn.getResources().get(Resource.FAILOVER);
        if (resource == null) {
            servletContext.log(null, new SQLException("Unable to find Resource: " + Resource.FAILOVER));
        } else {
            PackageDefinitionLimit limit = packageDefinition.getLimit(resource);
            if (limit != null) {
                int hard = limit.getHardLimit();
                if (hard == PackageDefinitionLimit.UNLIMITED || hard > 0) {
                    // This is per gigabyte of physical space
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    additionalRate = additionalRate.multiply(BigDecimal.valueOf(totalHardwareDiskSpace));
                    failoverOptions.add(new Option(limit.getPkey(), resource.toString(), additionalRate));

                    // Only once the failover option is available will the MySQL replication option be available
                    Resource mrResource = rootConn.getResources().get(Resource.MYSQL_REPLICATION);
                    if (mrResource == null) {
                        servletContext.log(null,
                                new SQLException("Unable to find Resource: " + Resource.MYSQL_REPLICATION));
                    } else {
                        PackageDefinitionLimit mrLimit = packageDefinition.getLimit(mrResource);
                        if (mrLimit != null) {
                            int mrHard = mrLimit.getHardLimit();
                            if (mrHard == PackageDefinitionLimit.UNLIMITED || mrHard > 0) {
                                BigDecimal mrAdditionalRate = mrLimit.getAdditionalRate();
                                if (mrAdditionalRate == null)
                                    mrAdditionalRate = BigDecimal.valueOf(0, 2);
                                failoverOptions.add(new Option(mrLimit.getPkey(), mrResource.toString(),
                                        additionalRate.add(mrAdditionalRate)));
                            }
                        }
                    }
                }
            }
        }
    }

    if (!backupOnsiteOptions.isEmpty())
        backupOnsiteOptions.add(0, new Option(-1, "No On-Site Backup", BigDecimal.valueOf(0, 2)));
    if (!backupOffsiteOptions.isEmpty())
        backupOffsiteOptions.add(0, new Option(-1, "No Off-Site Backup", BigDecimal.valueOf(0, 2)));
    if (!distributionScanOptions.isEmpty())
        distributionScanOptions.add(0, new Option(-1, "No daily scans", BigDecimal.valueOf(0, 2)));
    if (!failoverOptions.isEmpty())
        failoverOptions.add(0, new Option(-1, "No Fail-Over Mirror", BigDecimal.valueOf(0, 2)));

    // Sort by price
    Collections.sort(backupOnsiteOptions, new Option.PriceComparator());
    Collections.sort(backupOffsiteOptions, new Option.PriceComparator());
    Collections.sort(distributionScanOptions, new Option.PriceComparator());
    Collections.sort(failoverOptions, new Option.PriceComparator());

    // Clear any customization settings that are not part of the current package definition (this happens when they
    // select a different package type)
    if (signupCustomizeManagementForm.getBackupOnsiteOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getBackupOnsiteOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setBackupOnsiteOption(-1);
    }
    if (signupCustomizeManagementForm.getBackupOffsiteOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getBackupOffsiteOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setBackupOffsiteOption(-1);
    }
    if (signupCustomizeManagementForm.getDistributionScanOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getDistributionScanOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setDistributionScanOption(-1);
    }
    if (signupCustomizeManagementForm.getFailoverOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeManagementForm.getFailoverOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeManagementForm.setFailoverOption(-1);
    }

    // Store to request
    request.setAttribute("packageDefinition", packageDefinition);
    request.setAttribute("hardwareRate", SignupCustomizeServerActionHelper.getHardwareMonthlyRate(rootConn,
            signupCustomizeServerForm, packageDefinition));
    request.setAttribute("backupOnsiteOptions", backupOnsiteOptions);
    request.setAttribute("backupOffsiteOptions", backupOffsiteOptions);
    request.setAttribute("distributionScanOptions", distributionScanOptions);
    request.setAttribute("failoverOptions", failoverOptions);
}

From source file:de.brands4friends.daleq.examples.JdbcOrderDaoTest.java

@Before
public void setUp() {

    this.orderDao = new JdbcOrderDao();
    this.orderDao.setDataSource(dataSource);

    final Table customers = aTable(CustomerTable.class).with(aRow(CUSTOMER_1), aRow(CUSTOMER_2),
            aRow(CUSTOMER_3));// w ww  .j a va 2s.c  o m
    final Table products = aTable(ProductTable.class).with(aRow(PRODUCT_1).f(PRICE, "1.00"),
            aRow(PRODUCT_10).f(PRICE, "10.00"), aRow(PRODUCT_9_99).f(PRICE, "9.99"),
            aRow(PRODUCT_50).f(PRICE, "50.00"));
    daleq.insertIntoDatabase(customers, products);

    creationDay = new LocalDate(2012, 8, 1);
    duringCreationDay = creationDay.toDateTime(new LocalTime(10, 30));
    fortyEuro = BigDecimal.valueOf(400, 2);
}

From source file:com.aoindustries.website.signup.SignupCustomizeServerActionHelper.java

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        HttpServletResponse response, SignupSelectPackageForm signupSelectPackageForm,
        SignupCustomizeServerForm signupCustomizeServerForm) throws IOException, SQLException {
    AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();
    PackageDefinition packageDefinition = rootConn.getPackageDefinitions()
            .get(signupSelectPackageForm.getPackageDefinition());
    if (packageDefinition == null)
        throw new SQLException(
                "Unable to find PackageDefinition: " + signupSelectPackageForm.getPackageDefinition());
    List<PackageDefinitionLimit> limits = packageDefinition.getLimits();

    // Find the cheapest resources to scale prices from
    int maxPowers = 0;
    PackageDefinitionLimit cheapestPower = null;
    int maxCPUs = 0;
    PackageDefinitionLimit cheapestCPU = null;
    int maxRAMs = 0;
    PackageDefinitionLimit cheapestRAM = null;
    int maxSataControllers = 0;
    PackageDefinitionLimit cheapestSataController = null;
    int maxScsiControllers = 0;
    PackageDefinitionLimit cheapestScsiController = null;
    int maxDisks = 0;
    PackageDefinitionLimit cheapestDisk = null;
    for (PackageDefinitionLimit limit : limits) {
        String resourceName = limit.getResource().getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                if (limitPower > maxPowers)
                    maxPowers = limitPower;
                if (cheapestPower == null)
                    cheapestPower = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestPower = limit;
                }// www  . j  a  v  a  2s .  c o m
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                if (limitCpu > maxCPUs)
                    maxCPUs = limitCpu;
                if (cheapestCPU == null)
                    cheapestCPU = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestCPU = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                if (limitRAM > maxRAMs)
                    maxRAMs = limitRAM;
                if (cheapestRAM == null)
                    cheapestRAM = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestRAM = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                if (limitSataController > maxSataControllers)
                    maxSataControllers = limitSataController;
                if (cheapestSataController == null)
                    cheapestSataController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestSataController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                if (limitScsiController > maxScsiControllers)
                    maxScsiControllers = limitScsiController;
                if (cheapestScsiController == null)
                    cheapestScsiController = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestScsiController = limit;
                }
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int hardLimit = limit.getHardLimit();
            if (hardLimit > 0) {
                if (cheapestDisk == null)
                    cheapestDisk = limit;
                else {
                    BigDecimal additionalRate = limit.getAdditionalRate();
                    if (additionalRate == null)
                        additionalRate = BigDecimal.valueOf(0, 2);
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    if (additionalRate.compareTo(cheapestRate) < 0)
                        cheapestDisk = limit;
                }
                if (hardLimit > maxDisks)
                    maxDisks = hardLimit;
            }
        }
    }
    if (cheapestCPU == null)
        throw new SQLException("Unable to find cheapestCPU");
    if (cheapestRAM == null)
        throw new SQLException("Unable to find cheapestRAM");
    if (cheapestDisk == null)
        throw new SQLException("Unable to find cheapestDisk");

    // Find all the options
    List<Option> powerOptions = new ArrayList<Option>();
    List<Option> cpuOptions = new ArrayList<Option>();
    List<Option> ramOptions = new ArrayList<Option>();
    List<Option> sataControllerOptions = new ArrayList<Option>();
    List<Option> scsiControllerOptions = new ArrayList<Option>();
    List<List<Option>> diskOptions = new ArrayList<List<Option>>();
    for (int c = 0; c < maxDisks; c++)
        diskOptions.add(new ArrayList<Option>());
    for (PackageDefinitionLimit limit : limits) {
        Resource resource = limit.getResource();
        String resourceName = resource.getName();
        if (resourceName.startsWith("hardware_power_")) {
            int limitPower = limit.getHardLimit();
            if (limitPower > 0) {
                assert cheapestPower != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestPower.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxPowers == 1 ? resource.toString()
                        : (maxPowers + "x" + resource.toString());
                powerOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxPowers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_processor_")) {
            int limitCpu = limit.getHardLimit();
            if (limitCpu > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestCPU.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxCPUs == 1 ? resource.toString() : (maxCPUs + "x" + resource.toString());
                cpuOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxCPUs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_ram_")) {
            int limitRAM = limit.getHardLimit();
            if (limitRAM > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestRAM.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxRAMs == 1 ? resource.toString() : (maxRAMs + "x" + resource.toString());
                ramOptions.add(new Option(limit.getPkey(), description,
                        BigDecimal.valueOf(maxRAMs).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_sata_")) {
            int limitSataController = limit.getHardLimit();
            if (limitSataController > 0) {
                assert cheapestSataController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestSataController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxSataControllers == 1 ? resource.toString()
                        : (maxSataControllers + "x" + resource.toString());
                sataControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxSataControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_controller_scsi_")) {
            int limitScsiController = limit.getHardLimit();
            if (limitScsiController > 0) {
                assert cheapestScsiController != null;
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal cheapestRate = cheapestScsiController.getAdditionalRate();
                if (cheapestRate == null)
                    cheapestRate = BigDecimal.valueOf(0, 2);
                String description = maxScsiControllers == 1 ? resource.toString()
                        : (maxScsiControllers + "x" + resource.toString());
                scsiControllerOptions.add(new Option(limit.getPkey(), description, BigDecimal
                        .valueOf(maxScsiControllers).multiply(additionalRate.subtract(cheapestRate))));
            }
        } else if (resourceName.startsWith("hardware_disk_")) {
            int limitDisk = limit.getHardLimit();
            if (limitDisk > 0) {
                BigDecimal additionalRate = limit.getAdditionalRate();
                if (additionalRate == null)
                    additionalRate = BigDecimal.valueOf(0, 2);
                BigDecimal adjustedRate = additionalRate;
                // Discount adjusted rate if the cheapest disk is of this type
                if (cheapestDisk.getResource().getName().startsWith("hardware_disk_")) {
                    BigDecimal cheapestRate = cheapestDisk.getAdditionalRate();
                    if (cheapestRate == null)
                        cheapestRate = BigDecimal.valueOf(0, 2);
                    adjustedRate = adjustedRate.subtract(cheapestRate);
                }
                for (int c = 0; c < maxDisks; c++) {
                    List<Option> options = diskOptions.get(c);
                    // Add none option
                    if (maxDisks > 1 && options.isEmpty())
                        options.add(new Option(-1, "None",
                                c == 0 ? adjustedRate.subtract(additionalRate) : BigDecimal.valueOf(0, 2)));
                    options.add(new Option(limit.getPkey(), resource.toString(),
                            c == 0 ? adjustedRate : additionalRate));
                }
            }
        }
    }

    // Sort by price
    Collections.sort(powerOptions, new Option.PriceComparator());
    Collections.sort(cpuOptions, new Option.PriceComparator());
    Collections.sort(ramOptions, new Option.PriceComparator());
    Collections.sort(sataControllerOptions, new Option.PriceComparator());
    Collections.sort(scsiControllerOptions, new Option.PriceComparator());
    for (List<Option> diskOptionList : diskOptions)
        Collections.sort(diskOptionList, new Option.PriceComparator());

    // Clear any customization settings that are not part of the current package definition (this happens when they
    // select a different package type)
    if (signupCustomizeServerForm.getPowerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getPowerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setPowerOption(-1);
    }
    if (signupCustomizeServerForm.getCpuOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getCpuOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setCpuOption(-1);
    }
    if (signupCustomizeServerForm.getRamOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getRamOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setRamOption(-1);
    }
    if (signupCustomizeServerForm.getSataControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getSataControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setSataControllerOption(-1);
    }
    if (signupCustomizeServerForm.getScsiControllerOption() != -1) {
        PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits()
                .get(signupCustomizeServerForm.getScsiControllerOption());
        if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
            signupCustomizeServerForm.setScsiControllerOption(-1);
    }
    List<String> formDiskOptions = signupCustomizeServerForm.getDiskOptions();
    while (formDiskOptions.size() > maxDisks)
        formDiskOptions.remove(formDiskOptions.size() - 1);
    for (int c = 0; c < formDiskOptions.size(); c++) {
        String S = formDiskOptions.get(c);
        if (S != null && S.length() > 0 && !S.equals("-1")) {
            int pkey = Integer.parseInt(S);
            PackageDefinitionLimit pdl = rootConn.getPackageDefinitionLimits().get(pkey);
            if (pdl == null || !packageDefinition.equals(pdl.getPackageDefinition()))
                formDiskOptions.set(c, "-1");
        }
    }

    // Determine if at least one disk is selected
    boolean isAtLeastOneDiskSelected = signupCustomizeServerForm.isAtLeastOneDiskSelected();

    // Default to cheapest if not already selected
    if (cheapestPower != null && signupCustomizeServerForm.getPowerOption() == -1)
        signupCustomizeServerForm.setPowerOption(cheapestPower.getPkey());
    if (signupCustomizeServerForm.getCpuOption() == -1)
        signupCustomizeServerForm.setCpuOption(cheapestCPU.getPkey());
    if (signupCustomizeServerForm.getRamOption() == -1)
        signupCustomizeServerForm.setRamOption(cheapestRAM.getPkey());
    if (cheapestSataController != null && signupCustomizeServerForm.getSataControllerOption() == -1)
        signupCustomizeServerForm.setSataControllerOption(cheapestSataController.getPkey());
    if (cheapestScsiController != null && signupCustomizeServerForm.getScsiControllerOption() == -1)
        signupCustomizeServerForm.setScsiControllerOption(cheapestScsiController.getPkey());
    for (int c = 0; c < maxDisks; c++) {
        List<Option> options = diskOptions.get(c);
        if (!options.isEmpty()) {
            Option firstOption = options.get(0);
            if (!isAtLeastOneDiskSelected && options.size() >= 2
                    && firstOption.getPriceDifference().compareTo(BigDecimal.ZERO) < 0) {
                firstOption = options.get(1);
            }
            String defaultSelected = Integer.toString(firstOption.getPackageDefinitionLimit());
            if (formDiskOptions.size() <= c || formDiskOptions.get(c) == null
                    || formDiskOptions.get(c).length() == 0 || formDiskOptions.get(c).equals("-1"))
                formDiskOptions.set(c, defaultSelected);
        } else {
            formDiskOptions.set(c, "-1");
        }
    }

    // Find the basePrice (base plus minimum number of cheapest of each resource class)
    BigDecimal basePrice = packageDefinition.getMonthlyRate();
    if (basePrice == null)
        basePrice = BigDecimal.valueOf(0, 2);
    if (cheapestPower != null && cheapestPower.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestPower.getAdditionalRate().multiply(BigDecimal.valueOf(maxPowers)));
    if (cheapestCPU.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestCPU.getAdditionalRate().multiply(BigDecimal.valueOf(maxCPUs)));
    if (cheapestRAM.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestRAM.getAdditionalRate());
    if (cheapestSataController != null && cheapestSataController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestSataController.getAdditionalRate());
    if (cheapestScsiController != null && cheapestScsiController.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestScsiController.getAdditionalRate());
    if (cheapestDisk.getAdditionalRate() != null)
        basePrice = basePrice.add(cheapestDisk.getAdditionalRate());

    // Store to request
    request.setAttribute("packageDefinition", packageDefinition);
    request.setAttribute("powerOptions", powerOptions);
    request.setAttribute("cpuOptions", cpuOptions);
    request.setAttribute("ramOptions", ramOptions);
    request.setAttribute("sataControllerOptions", sataControllerOptions);
    request.setAttribute("scsiControllerOptions", scsiControllerOptions);
    request.setAttribute("diskOptions", diskOptions);
    request.setAttribute("basePrice", basePrice);
}

From source file:de.brands4friends.daleq.examples.JdbcProductDaoTest.java

private BigDecimal aPrice(final int priceVal) {
    return BigDecimal.valueOf(priceVal, 2);
}

From source file:dk.clanie.bitcoin.client.BitcoindClientIntegrationTest.java

@Test
public void testCreateRawTransaction() throws Exception {
    AddressAndAmount aaa = new AddressAndAmount("mj3QxNUyp4Ry2pbbP19tznUAAPqFvDbRFq",
            BigDecimal.valueOf(100000000L, 8));
    List<TransactionOutputRef> txOuts = newArrayList();
    txOuts.add(new TransactionOutputRef("280acc1c3611fee83331465c715b0da2d10b65733a688ee2273fdcc7581f149b", 0));
    StringResponse createRawTransactionResponse = bc.createRawTransaction(txOuts, aaa, aaa);
    print(createRawTransactionResponse);

}

From source file:de.hybris.platform.test.HJMPTest.java

@Test
public void testWriteReadValues() {
    LOG.debug(">>> testWriteReadValues()");

    final Float floatValue = new Float(1234.5678f);
    /* conv-LOG */LOG.debug(">>> Float (" + floatValue + ") <<<");
    remote.setFloat(floatValue);/*from  w w  w  . ja va 2s.c  o m*/
    assertEquals(floatValue, remote.getFloat());

    final Double doubleValue = new Double(2234.5678d);
    /* conv-LOG */LOG.debug(">>> Double (" + doubleValue + ") <<<");
    remote.setDouble(doubleValue);
    assertEquals(doubleValue, remote.getDouble());

    final Character characterValue = Character.valueOf('g');
    /* conv-LOG */LOG.debug(">>> Character (" + characterValue + ") <<<");
    remote.setCharacter(characterValue);
    assertEquals(characterValue, remote.getCharacter());

    final Integer integerValue = Integer.valueOf(3357);
    /* conv-LOG */LOG.debug(">>> Integer (" + integerValue + ") <<<");
    remote.setInteger(integerValue);
    assertEquals(integerValue, remote.getInteger());

    final Long longValue = Long.valueOf(4357L);
    /* conv-LOG */LOG.debug(">>> Long (" + longValue + ") <<<");
    remote.setLong(longValue);
    assertEquals(longValue, remote.getLong());

    final Calendar now = Utilities.getDefaultCalendar();
    now.set(Calendar.MILLISECOND, 0);

    /* conv-LOG */LOG.debug(">>> Date (" + now + ", ms=" + now.getTime() + ")<<<");
    remote.setDate(now.getTime());
    final java.util.Date got = remote.getDate();
    /* conv-LOG */LOG.debug(">>> found (" + got.getTime() + ")<<<");
    assertEquals(now.getTime(), got);

    // try to get 123,4567 as big decimal
    final BigDecimal bigDecimalValue = BigDecimal.valueOf(1234567, 4);
    /* conv-LOG */LOG.debug(">>> BigDecimal (" + bigDecimalValue + ")<<<");
    remote.setBigDecimal(bigDecimalValue);
    assertTrue(remote.getBigDecimal().compareTo(bigDecimalValue) == 0);

    final java.sql.Timestamp timestamp = new java.sql.Timestamp(now.getTime().getTime());
    /* conv-LOG */LOG.debug(">>> Timestamp (" + timestamp + ", ms=" + timestamp.getTime() + ")<<<");
    remote.setDate(timestamp);
    final java.util.Date got2 = remote.getDate();
    /* conv-LOG */LOG.debug(">>> found (" + got2.getTime() + ")<<<");
    assertEquals(now.getTime(), got2);

    final String str = "Alles wird gut!";
    /* conv-LOG */LOG.debug(">>> String (" + str + ")<<<");
    remote.setString(str);
    assertEquals(str, remote.getString());

    final String longstr = "Alles wird lange gut!";
    /* conv-LOG */LOG.debug(">>> Long String (" + longstr + ")<<<");
    remote.setLongString(longstr);
    assertEquals(longstr, remote.getLongString());

    //put 50000 chars into it
    String longstr2 = "";
    for (int i2 = 0; i2 < 5000; i2++) {
        longstr2 += "01234567890";
    }
    remote.setLongString(longstr2);
    assertEquals(longstr2, remote.getLongString());

    /*
     * remote.setString( "" ); assertEquals( "" , remote.getString() ); remote.setString( null ); assertNull(
     * remote.getString() ); remote.setLongString( "" ); assertEquals( "" , remote.getLongString() );
     * remote.setLongString( null ); assertNull( remote.getLongString() );
     */

    final Boolean booleanValue = Boolean.TRUE;
    /* conv-LOG */LOG.debug(">>> Boolean (" + booleanValue + ")<<<");
    remote.setBoolean(booleanValue);
    assertEquals(booleanValue, remote.getBoolean());

    final float floatValue2 = 5234.5678f;
    /* conv-LOG */LOG.debug(">>> float (" + floatValue2 + ") <<<");
    remote.setPrimitiveFloat(floatValue2);
    assertTrue(">>> float (" + floatValue2 + ") <<<", floatValue2 == remote.getPrimitiveFloat());

    final double doubleValue2 = 6234.5678d;
    /* conv-LOG */LOG.debug(">>> double (" + doubleValue2 + ") <<<");
    remote.setPrimitiveDouble(doubleValue2);
    assertTrue(">>> double (" + doubleValue2 + ") <<<", doubleValue2 == remote.getPrimitiveDouble());

    final int integerValue2 = 7357;
    /* conv-LOG */LOG.debug(">>> int (" + integerValue2 + ") <<<");
    remote.setPrimitiveInteger(integerValue2);
    assertTrue(integerValue2 == remote.getPrimitiveInteger());

    final long longValue2 = 8357L;
    /* conv-LOG */LOG.debug(">>> long (" + longValue2 + ") <<<");
    remote.setPrimitiveLong(longValue2);
    assertTrue(">>> long (" + longValue2 + ") <<<", longValue2 == remote.getPrimitiveLong());

    final byte byteValue = 123;
    /* conv-LOG */LOG.debug(">>> byte (" + byteValue + ") <<<");
    remote.setPrimitiveByte(byteValue);
    assertTrue(">>> byte (" + byteValue + ") <<<", byteValue == remote.getPrimitiveByte());

    final boolean booleanValue2 = true;
    /* conv-LOG */LOG.debug(">>> boolean (" + booleanValue2 + ") <<<");
    remote.setPrimitiveBoolean(booleanValue2);
    assertTrue(">>> boolean (" + booleanValue2 + ") <<<", booleanValue2 == remote.getPrimitiveBoolean());

    final char characterValue2 = 'g';
    /* conv-LOG */LOG.debug(">>> char (" + characterValue2 + ") <<<");
    remote.setPrimitiveChar(characterValue2);
    assertTrue(">>> char (" + characterValue2 + ") <<<", characterValue2 == remote.getPrimitiveChar());

    final ArrayList list = new ArrayList();
    LOG.debug(">>> Serializable with standard classes (" + list + ") <<<");
    remote.setSerializable(list);
    assertEquals(list, remote.getSerializable());

    if (!Config.isOracleUsed()) {
        try {
            final HashMap bigtest = new HashMap();
            LOG.debug(">>> Serializable with standard classes (big thing) <<<");
            final byte[] byteArray = new byte[100000];
            bigtest.put("test", byteArray);
            remote.setSerializable(bigtest);
            final Map longtestret = (Map) remote.getSerializable();
            assertTrue(longtestret.size() == 1);
            final byte[] byteArray2 = (byte[]) longtestret.get("test");
            assertTrue(byteArray2.length == 100000);
        } catch (final Exception e) {
            throw new JaloSystemException(e,
                    "Unable to write big serializable object, db: " + Config.getDatabase() + ".", 0);
        }
    }

    /* conv-LOG */LOG.debug(">>> Serializable (null) <<<");
    remote.setSerializable(null);
    assertNull(remote.getSerializable());

    //         try
    //         {
    //            final Dummy dummy = new Dummy();
    //            /*conv-LOG*/ LOG.debug(">>> Serializable with custom classes ("+dummy+") <<<");
    //            remote.setSerializable( dummy );
    //            final Serializable x = remote.getSerializable();
    //            assertTrue( dummy.equals( x ) || x == null );
    //            if( x == null )
    //               /*conv-LOG*/ LOG.debug(">>> ok, we're still unable of writing non-serverside classes to database : read NULL ");
    //         }
    //         catch( Exception e )
    //         {
    //            /*conv-LOG*/ LOG.debug(">>> ok, we're still unable of writing non-serverside classes to database : " + e );
    //         }

    //
    // search
    //

    try {
        /* conv-LOG */LOG.debug(">>> Search ( " + str + ", " + integerValue2 + " ) <<<");
        home.finderTest(str, integerValue2);
    } catch (final Exception e) {
        e.printStackTrace();
        fail("TestItem not found!");
    }

    //
    // 'null' tests
    //

    /* conv-LOG */LOG.debug(">>> String (null) <<<");
    remote.setString(null);
    assertNull(remote.getString());

    /* conv-LOG */LOG.debug(">>> Character (null) <<<");
    remote.setCharacter(null);
    assertNull(remote.getCharacter());

    /* conv-LOG */LOG.debug(">>> Integer (null) <<<");
    remote.setInteger(null);
    assertNull(remote.getInteger());

    /* conv-LOG */LOG.debug(">>> Date (null) <<<");
    remote.setDate(null);
    assertNull(remote.getDate());

    /* conv-LOG */LOG.debug(">>> Double (null) <<<");
    remote.setDouble(null);
    assertNull(remote.getDouble());

    /* conv-LOG */LOG.debug(">>> Float (null) <<<");
    remote.setFloat(null);
    assertNull(remote.getFloat());
}

From source file:net.sf.json.TestJSONArray.java

public void testConstructor_Object_Array_BigDecimal() {
    // bug 1596168

    // an array of BigDecimals
    Number[] numberArray = new Number[] { BigDecimal.valueOf(10000000000L, 10), new BigDecimal("-1.0"),
            new BigDecimal("99.99E-1") };

    assertEquals("1.0000000000", numberArray[0].toString());
    assertEquals("-1.0", numberArray[1].toString());
    assertEquals("9.999", numberArray[2].toString());

    JSONArray jsonNumArray = JSONArray.fromObject(numberArray);

    assertEquals("1.0000000000", jsonNumArray.get(0).toString());
    assertEquals("-1.0", jsonNumArray.get(1).toString());
    assertEquals("9.999", jsonNumArray.get(2).toString());
}