List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:churashima.action.manage.ExpensesAction.java
@Execute(validator = false) public String searchInit() { ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class); List<Expenses> expensesList = expensesDao.selectForSearch(null, null, null, null, null, null, expensesForm.searchPrice, null, null); expensesForm.expensesList = expensesList; // ??//w ww . j av a 2 s.c o m BigDecimal sumPriceTotal = BigDecimal.valueOf(0); for (Expenses expenses : expensesList) { sumPriceTotal = sumPriceTotal.add(expenses.price); } expensesForm.sumPriceTotal = sumPriceTotal; SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class); expensesForm.subjectList = subjectDao.selectForSearch(null, null); return "expensesList.jsp"; }
From source file:com.trenako.web.controllers.form.WishListFormTests.java
@Test public void shouldCreateEditingWishListForms() { WishListForm form = WishListForm.newForm(privateWishList(), messageSource); assertNotNull("Editing form is null", form); assertEquals(privateWishList(), form.getWishList()); assertEquals(BigDecimal.valueOf(100), form.getBudget()); assertEquals("{(public)=, (private)=checked}", form.getVisibilities().toString()); }
From source file:com.liato.bankdroid.banking.banks.bitcoin.Bitcoin.java
public Urllib login() throws LoginException, BankException { urlopen = new Urllib(context); try {//from w w w .j a v a 2s . co m String response = urlopen.open(API_URL + username); if (response == null || "".equals(response)) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } ObjectMapper vObjectMapper = new ObjectMapper(); vObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); vObjectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); BlockchainResponse r = vObjectMapper.readValue(urlopen.open(API_URL + username), BlockchainResponse.class); Account a = new Account("Bitcoin", new BigDecimal(r.getFinalBalance()).divide(BigDecimal.valueOf(100000000)), "1"); a.setCurrency("BTC"); accounts.add(a); setCurrency("BTC"); } catch (JsonParseException e) { throw new BankException(res.getText(R.string.invalid_bitcoin_address).toString()); } catch (ClientProtocolException e) { e.printStackTrace(); throw new BankException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.algomedica.service.LicenseManagerServiceImpl.java
@Override public Customer generateLicense(LicenseForm licenseForm, long userId) { LicenseDetail detail = new LicenseDetail(); Customer customer;//w w w . ja va2 s. c o m try { if (licenseForm != null && StringUtils.isNotEmpty(licenseForm.getLsmacAddress()) && StringUtils.isNotBlank(licenseForm.getLsType()) && licenseForm.getLsExipryDays() != 0) { if (licenseDao.getLicenceByMacAddress( licenseForm.getLsmacAddress().replaceAll("..(?!$)", "$0:")) != null) { LOGGER.error(ErrorCodesConstants.DUPLICATE_MAC_ADDRESS); throw new ApplicationException(ErrorCodesConstants.DUPLICATE_MAC_ADDRESS_CODE, ErrorCodesConstants.DUPLICATE_MAC_ADDRESS); } customer = customerDao.getCustomerById(licenseForm.getCustomerId()); if (customer == null) { throw new DuplicateFieldException(ErrorCodesConstants.NO_RECORD_EXIST_CODE, ErrorCodesConstants.NO_RECORD_EXIST); } // generate license function calling area detail.setLsExipryDate(calculateExpiryDate(licenseForm.getLsExipryDays())); detail.setLsExpiryDays(BigDecimal.valueOf(licenseForm.getLsExipryDays())); LicenseManager lm = new LicenseManager(); LicenseContent lc = new LicenseContent(customer.getOrgName(), licenseForm.getLsmacAddress().replace(":", ""), licenseForm.getLsType(), getTime(detail.getLsExipryDate().getTime()), licenseForm.getLsCategory()); detail = lm.generateLicenseKey(lc, detail); // code merging is pending detail.setCreatedBy(userId); detail.setLsCost(BigDecimal.valueOf(Double.parseDouble(licenseForm.getLsCost()))); detail.setLsLicenseType(licenseForm.getLsType()); detail.setLsCategory(licenseForm.getLsCategory()); String macAddress = licenseForm.getLsmacAddress().replaceAll("..(?!$)", "$0:"); detail.setLsMacAddress(macAddress); detail.setLsModelName(licenseForm.getLsmodelName()); detail.setLsModelNumber(licenseForm.getLsmodelNumber()); detail.setLsOpsEmail(licenseForm.getLsOpsEmail()); detail.setLsOpsName(licenseForm.getLsOpsName()); detail.setLsOpsPhone(licenseForm.getLsOpsPhone()); detail.setOrganization(customer); detail.setLsStatus(ApplicationConstant.STATUC_ACTIVE); customer.getLicenseDetails().add(detail); customerDao.updateCustomer(customer); } else { throw new ApplicationException(ErrorCodesConstants.INVALID_INPUT_CODE, ErrorCodesConstants.INVALID_INPUT); } } catch (KeyGenerationException e) { LOGGER.error("During generating License exception occured "); throw new ApplicationException(ErrorCodesConstants.INTERNAL_SYSTEM_ERROR_CODE, ErrorCodesConstants.INTERNAL_SYSTEM_ERROR, e); } catch (ApplicationException e) { LOGGER.error("During generating License exception occured "); throw new ApplicationException(e.getCode(), e.getMessage(), e); } catch (Exception e) { LOGGER.error("During generating License Exception occured "); throw new ApplicationException(ErrorCodesConstants.INTERNAL_SYSTEM_ERROR_CODE, ErrorCodesConstants.INTERNAL_SYSTEM_ERROR, e); } return customer; }
From source file:com.ameer.testweb.test.repository.EmployeeRepositoryTest.java
@Test public void createEmployee() { List<Identities> ids = new ArrayList<>(); List<PaySlip> slips = new ArrayList<>(); List<Position> ps = new ArrayList<>(); List<Deductions> ds = new ArrayList<>(); List<Benefits> b = new ArrayList<>(); Names fullname = new Names.Builder("Ameer").lastname("Mallagie").build(); Demographics demo = new Demographics.Builder("Male").race("Transparent").build(); Contact contact = new Contact.Builder("0769594969").homeNum("0219527100").build(); AddressRepo = ctx.getBean(AddressRepository.class); Address address = new Address.Builder("40 Someplace").postalCode(7650).build(); AddressRepo.save(address);/* www.jav a 2 s.c om*/ IdentityRepo = ctx.getBean(IdentitiesRepository.class); Identities identity = new Identities.Builder("Captain").idValue("CAP213").build(); Identities identities = new Identities.Builder("Superhero").idValue("BAT312").build(); ids.add(identity); ids.add(identities); IdentityRepo.save(identity); IdentityRepo.save(identities); PaySlipRepo = ctx.getBean(PaySlipRepository.class); PaySlip paySlip = new PaySlip.Builder(BigDecimal.valueOf(20000.00)).netPay(BigDecimal.valueOf(15000.00)) .build(); slips.add(paySlip); // Long idd = paySlip.getId(); // // PaySlip obj = PaySlipRepo.findOne(idd); // PaySlipRepo.delete(obj); BenefitsRepo = ctx.getBean(BenefitsRepository.class); Benefits benefits = new Benefits.Builder("Lunch Money").benefitValue(BigDecimal.valueOf(250.00)).build(); BenefitsRepo.save(benefits); b.add(benefits); SalaryRepo = ctx.getBean(SalaryRepository.class); Salary salary = new Salary.Builder(BigDecimal.valueOf(15000.00)).build(); SalaryRepo.save(salary); DeductionsRepo = ctx.getBean(DeductionsRepository.class); Deductions deductions = new Deductions.Builder("Medical Aid").deductValue(BigDecimal.valueOf(350.00)) .build(); DeductionsRepo.save(deductions); ds.add(deductions); PositionRepo = ctx.getBean(PositionRepository.class); Position position = new Position.Builder("PRM").status("Close").benefit(b).deduction(ds).salary(salary) .build(); PositionRepo.save(position); ps.add(position); JobRepo = ctx.getBean(JobRepository.class); Job job = new Job.Builder("Programmer").positions(ps).build(); JobRepo.save(job); EmpRepo = ctx.getBean(EmployeeRepository.class); Employee emp = new Employee.Builder(1).name(fullname).demographics(demo).contact(contact).address(address) .paySlips(slips).identity(ids).position(position).numOfDependants(2).build(); EmpRepo.save(emp); id = emp.getId(); PaySlipRepo = ctx.getBean(PaySlipRepository.class); PaySlip newpaySlip = new PaySlip.Builder(BigDecimal.valueOf(20000.00)).netPay(BigDecimal.valueOf(15000.00)) .employee(emp).build(); PaySlipRepo.save(newpaySlip); Assert.assertNotNull(emp); }
From source file:com.formulaone.service.merchant.ReqRespSerialDeserialTest.java
@Test @Ignore/* w w w . ja v a 2s . c om*/ public void testMerchantRequestSerialization() throws Exception { // Requestjason deserialization // CompanyDetails CompanyRequest company = new CompanyRequest(); company.setName("TamTam ltd."); company.setPhone("14501234123"); AddressRequest addr = new AddressRequest(); addr.setAddress("123 rue Alphonse Daudet"); addr.setCity("Laval"); addr.setState("qc"); addr.setZipCode("H6Y 1R5"); company.setAddress(addr); // build OwnerShip details OwnershipDetailsRequest details = new OwnershipDetailsRequest(); details.setDob(DateTime.now()); details.setDriverlicense("A123456789876"); details.setFirstName("Paul"); details.setLastName("Jackson"); details.setMiddleName("william"); details.setPosition("taxi driver"); details.setSsn("123456"); details.setTaxiId("taxi12345"); // bank details BankingDetailsRequest bankingDetails = new BankingDetailsRequest(); bankingDetails.setBankAccountNumber("1234567"); bankingDetails.setRoutingNumber("12345123"); // General GeneralRequest general = new GeneralRequest(); general.setAnnualProcessing("annualProcessing"); general.setCountryOfIncorporation("Canada"); general.setDescriptor("Descriptor"); general.setPhoneNumber("1514333444"); general.setWebsite("http://www.myComany.com"); general.setBusinessType("online stuff"); MerchantRequest request = new MerchantRequest("testName", "testname@hotmail.com", "legal name llc", "describe the business", BigDecimal.valueOf(334.37), company, details, bankingDetails, general); System.out.println("Request: " + request); String str = objectMapper.writeValueAsString(request); System.out.println("Serialized obkject: " + str); }
From source file:net.ceos.project.poi.annotated.bean.PerformanceObjectBuilder.java
/** * Create a PerformanceObject for tests. * // w ww. j a v a 2 s . co m * @return the {@link PerformanceObject} */ public static PerformanceObject buildPerformanceObject(int multiplier) { PerformanceObject toValidate = new PerformanceObject(); toValidate.setDateAttribute1(new Date()); toValidate.setDateAttribute2(new Date()); toValidate.setDateAttribute3(new Date()); toValidate.setStringAttribute1("some string"); toValidate.setStringAttribute2("some string"); toValidate.setStringAttribute3("some string"); toValidate.setStringAttribute4("some string"); toValidate.setStringAttribute5("some string"); toValidate.setStringAttribute6("some string"); toValidate.setStringAttribute7("some string"); toValidate.setStringAttribute8("some string"); toValidate.setStringAttribute9("some string"); toValidate.setStringAttribute10("some string"); toValidate.setStringAttribute11("some string"); toValidate.setStringAttribute12("some string"); toValidate.setIntegerAttribute1(6 * multiplier); toValidate.setIntegerAttribute2(11 * multiplier); toValidate.setIntegerAttribute3(33 * multiplier); toValidate.setIntegerAttribute4(46 * multiplier); toValidate.setIntegerAttribute5(2 * multiplier); toValidate.setIntegerAttribute6(7 * multiplier); toValidate.setIntegerAttribute7(9 * multiplier); toValidate.setDoubleAttribute1(Double.valueOf("11.3") * multiplier); toValidate.setDoubleAttribute2(Double.valueOf("237.131") * multiplier); toValidate.setDoubleAttribute3(Double.valueOf("25.777") * multiplier); toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier); toValidate.setBooleanAttribute1(Boolean.TRUE); toValidate.setBooleanAttribute2(Boolean.TRUE); toValidate.setBooleanAttribute3(Boolean.FALSE); toValidate.setBooleanAttribute4(Boolean.TRUE); /* create sub object Job */ Job job = new Job(); job.setJobCode(0005); job.setJobFamily("Family Job Name"); job.setJobName("Job Name"); toValidate.setJob(job); toValidate.setIntegerPrimitiveAttribute1(2 * multiplier); toValidate.setIntegerPrimitiveAttribute2(3 * multiplier); toValidate.setIntegerPrimitiveAttribute3(11 * multiplier); toValidate.setIntegerPrimitiveAttribute4(5 * multiplier); toValidate.setIntegerPrimitiveAttribute5(12 * multiplier); toValidate.setDoublePrimitiveAttribute(44.6 * multiplier); toValidate.setLongPrimitiveAttribute(987654321L * multiplier); toValidate.setBooleanPrimitiveAttribute(true); /* create sub object AddressInfo */ AddressInfo ai = new AddressInfo(); ai.setAddress("this is the street"); ai.setNumber(99); ai.setCity("this is the city"); ai.setCityCode(70065); ai.setCountry("This is a Country"); toValidate.setAddressInfo(ai); toValidate.setFloatAttribute(14.765f * multiplier); toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier); toValidate.setUnitFamily(UnitFamily.COMPONENTS); toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier))); // TODO add new fields below return toValidate; }
From source file:per.mnn.controller.CheckoutController.java
@RequestMapping(value = "/confirm", method = RequestMethod.POST) public ModelAndView confirm(HttpServletRequest request, HttpServletResponse respond) throws UnsupportedEncodingException { request.setCharacterEncoding("UTF-8"); ModelAndView retval = new ModelAndView("confirmation"); String name = request.getParameter("name"); String email = request.getParameter("email"); String phone = request.getParameter("phone"); String address = request.getParameter("address"); String cityRegion = request.getParameter("cityRegion"); String creditcard = request.getParameter("creditcard"); if (name == null || name.isEmpty()) { retval.addObject("nameError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); }/*from w w w. jav a 2 s.c om*/ if (email == null || email.isEmpty()) { retval.addObject("emailError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); } if (phone == null || phone.isEmpty()) { retval.addObject("phoneError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); } if (address == null || address.isEmpty()) { retval.addObject("addressError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); } if (cityRegion == null || cityRegion.isEmpty()) { retval.addObject("cityRegionError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); } if (creditcard == null || creditcard.isEmpty()) { retval.addObject("creditcardError", "true"); retval.addObject("validationErrorFlag", "true"); retval.setViewName("checkout"); } if (retval.getViewName() == "confirmation") { ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("cart"); Session sess = HibernateUtil.getSessionFactory().openSession(); Transaction tran = sess.beginTransaction(); Customer customer = new Customer(name, email, phone, address, cityRegion, creditcard); sess.save(customer); CustomerOrder order = new CustomerOrder(); order.setCustomer(customer); order.setAmount(BigDecimal.valueOf(cart.getTotal())); order.setDateCreated(new Date()); order.setConfirmationNumber(new Random().nextInt(999999999)); sess.save(order); for (ShoppingCartItem item : cart.getItems()) { OrderedProductId id = new OrderedProductId(order.getId(), item.getProduct().getId()); OrderedProduct orderedProduct = new OrderedProduct(); orderedProduct.setId(id); orderedProduct.setCustomerOrder(order); orderedProduct.setProduct(item.getProduct()); orderedProduct.setQuantity((short) item.getQuantity()); sess.save(orderedProduct); order.getOrderedProducts().add(orderedProduct); } tran.commit(); sess.close(); cart.clear(); request.getSession().invalidate(); retval.addObject("customer", customer); retval.addObject("orderRecord", order); retval.addObject("orderedProducts", order.getOrderedProducts()); } return retval; }
From source file:org.impotch.calcul.assurancessociales.CalculCotisationAvsAiApgIndependantTest.java
@Test public void calculCotisationAvsAiApg2009() { assertThat(calculateur2009.calculCotisationAvsAiApg(BigDecimal.valueOf(1000))) .isEqualByComparingTo("460.00"); assertThat(calculateur2009.calculCotisationAvsAiApg(BigDecimal.valueOf(100000))).isEqualTo("9500.00"); }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.solution.SolutionPerJob.java
public void setCost() { double cost = deltaBar * numOnDemandVM + rhoBar * numReservedVM + sigmaBar * numSpotVM + job.getPenalty() * (job.getHup() - numberUsers); BigDecimal c = BigDecimal.valueOf(cost).setScale(4, RoundingMode.HALF_EVEN); this.cost = c.doubleValue(); }