List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:com.workday.autoparse.json.demo.InstanceUpdaterTest.java
@Test public void testSpecialObjects() { TestObject testObject = new TestObject(); testObject.myString = "antman"; testObject.myBigDecimal = BigDecimal.valueOf(1.1); testObject.myBigInteger = BigInteger.valueOf(1); Map<String, Object> updates = new HashMap<>(); updates.put("myString", "batman"); updates.put("myBigDecimal", BigDecimal.valueOf(2.2)); updates.put("myBigInteger", BigInteger.valueOf(2)); TestObject$$JsonObjectParser.INSTANCE.updateInstanceFromMap(testObject, updates, CONTEXT); assertEquals("myString", "batman", testObject.myString); assertEquals("myBigDecimal", BigDecimal.valueOf(2.2), testObject.myBigDecimal); assertEquals("myBigInteger", BigInteger.valueOf(2), testObject.myBigInteger); }
From source file:de.hybris.platform.commercefacades.product.converters.populator.VariantOptionDataPopulator.java
@Override public void populate(final VariantProductModel source, final VariantOptionData target) { Assert.notNull(source, "Parameter source cannot be null."); Assert.notNull(target, "Parameter target cannot be null."); if (source.getBaseProduct() != null) { final List<VariantAttributeDescriptorModel> descriptorModels = getVariantsService() .getVariantAttributesForVariantType(source.getBaseProduct().getVariantType()); final Collection<VariantOptionQualifierData> variantOptionQualifiers = new ArrayList<VariantOptionQualifierData>(); for (final VariantAttributeDescriptorModel descriptorModel : descriptorModels) { // Create the variant qualifier final VariantOptionQualifierData variantOptionQualifier = new VariantOptionQualifierData(); final String qualifier = descriptorModel.getQualifier(); variantOptionQualifier.setQualifier(qualifier); variantOptionQualifier.setName(descriptorModel.getName()); // Lookup the value final Object variantAttributeValue = lookupVariantAttributeName(source, qualifier); variantOptionQualifier//from w w w. j a v a2s. c om .setValue(variantAttributeValue == null ? "" : variantAttributeValue.toString()); // Add to list of variants variantOptionQualifiers.add(variantOptionQualifier); } target.setVariantOptionQualifiers(variantOptionQualifiers); target.setCode(source.getCode()); target.setUrl(getProductModelUrlResolver().resolve(source)); target.setStock(getStockConverter().convert(source)); final PriceDataType priceType; final PriceInformation info; if (CollectionUtils.isEmpty(source.getVariants())) { priceType = PriceDataType.BUY; info = getCommercePriceService().getWebPriceForProduct(source); } else { priceType = PriceDataType.FROM; info = getCommercePriceService().getFromPriceForProduct(source); } if (info != null) { final PriceData priceData = getPriceDataFactory().create(priceType, BigDecimal.valueOf(info.getPriceValue().getValue()), info.getPriceValue().getCurrencyIso()); target.setPriceData(priceData); } } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java
BigDecimal decodeBinDecimal(ByteBuf cb, int bufferLen, boolean isIntegerPortion) throws PEException { BigDecimal decimalPortion = new BigDecimal(0); if (bufferLen > 0) { ByteBuf decimalPortionBuf = cb.readBytes(bufferLen); if (isIntegerPortion) { int initialBytes = bufferLen % 4; if (initialBytes > 0) { long intValue = readValue(decimalPortionBuf, initialBytes); decimalPortion = BigDecimal.valueOf(intValue); }//ww w. ja v a2s . c om } int decimalPortionLen = decimalPortionBuf.readableBytes(); while (decimalPortionLen > 0) { int nextLen = (decimalPortionLen < 4) ? decimalPortionLen : 4; long intValue = readValue(decimalPortionBuf, nextLen); if (intValue > 0) { if (decimalPortion.longValue() == 0) { decimalPortion = decimalPortion.add(BigDecimal.valueOf(intValue)); } else { int digits = (int) (Math.log10(intValue) + 1); decimalPortion = decimalPortion.movePointRight(digits).add(BigDecimal.valueOf(intValue)); } } decimalPortionLen = decimalPortionBuf.readableBytes(); } } return decimalPortion; }
From source file:com.formulaone.service.merchant.ReqRespSerialDeserialTest.java
@Test @Ignore/*from w ww . jav a 2s . co m*/ public void testMerchantRequesttDeserialization() 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); MerchantRequest merchantRequest = objectMapper.readValue(str, MerchantRequest.class); System.out.println("Request is: " + merchantRequest); }
From source file:eugene.agent.noise.impl.PlaceOrderBehaviour.java
/** * Sends a {@link OrdType#LIMIT} order away from the current best price on this {@code side}. * * @param side side of the limit order.//from www . j a v a 2s . c om */ private void limitOutOfSpread(final Side side) { final Long ordQty = Double.valueOf(ordSize.sample()).longValue(); final BigDecimal priceMove = BigDecimal.valueOf(outOfSpreadPrice.sample()); final BigDecimal price = topOfBook.getLastPrice(side, YES).prevPrice(priceMove); session.send(newLimit(side, price, ordQty)); }
From source file:at.fh.swenga.firefighters.controller.FireFighterController.java
@RequestMapping(value = { "/", "index" }) public String index(Model model, HttpServletRequest request) { if (request.isUserInRole("ROLE_GLOBAL_ADMIN")) { List<FireBrigadeModel> fireBrigades = fireBrigadeRepository.findAll(); model.addAttribute("fireBrigades", fireBrigades); float males = fireFighterRepository.countByGender("m"); float females = fireFighterRepository.countByGender("w"); float sumFighters = males + females; float percentFem = females / sumFighters * 100; float percentMal = males / sumFighters * 100; percentFem = BigDecimal.valueOf(percentFem).setScale(2, RoundingMode.HALF_UP).floatValue(); percentMal = BigDecimal.valueOf(percentMal).setScale(2, RoundingMode.HALF_UP).floatValue(); model.addAttribute("males", percentMal); model.addAttribute("females", percentFem); model.addAttribute("sumFighters", sumFighters); List<Object[]> topFireBrigades = fireFighterRepository.groupByFireBrigade(); Map<String, BigInteger> topFireBrigadesMap = topFireBrigades.stream().collect(Collectors.toMap( a -> (String) fireBrigadeRepository.findById((int) a[1]).getName(), a -> (BigInteger) a[0])); Map<String, BigInteger> sortedTopFireBrigadesMap = MapUtil.sortByValue(topFireBrigadesMap); model.addAttribute("sortedTopFireBrigades", sortedTopFireBrigadesMap); } else if (!request.isUserInRole("ROLE_GLOBAL_ADMIN") && (request.isUserInRole("ROLE_ADMIN") || request.isUserInRole("ROLE_USER"))) { List<FireFighterModel> fireFighters = fireFighterRepository.findByFireBrigade(getSessionFireBrigade()); model.addAttribute("fireFighters", fireFighters); }/*from w ww .j av a2 s .co m*/ return "index"; }
From source file:com.base.dao.sql.ReflectionUtils.java
public static BigDecimal bigDecValue(Object value) throws NumberFormatException { if (value == null) return BigDecimal.valueOf(0L); Class c = value.getClass();//www . j a v a 2 s .c om if (c == BigDecimal.class) return (BigDecimal) value; if (c == BigInteger.class) return new BigDecimal((BigInteger) value); if (c.getSuperclass() == Number.class) return BigDecimal.valueOf(processDecimal(value)); if (c == Boolean.class) return BigDecimal.valueOf(((Boolean) value).booleanValue() ? 1 : 0); if (c == Character.class) return BigDecimal.valueOf(((Character) value).charValue()); return new BigDecimal(stringValue(value, true)); }
From source file:org.impotch.calcul.assurancessociales.CalculCotisationAvsAiApgIndependantTest.java
@Test public void calculCotisationAvsAiApg2011() { assertThat(calculateur2011.calculCotisationAvsAiApg(BigDecimal.valueOf(1000))).isEqualByComparingTo("475"); assertThat(calculateur2011.calculCotisationAvsAiApg(BigDecimal.valueOf(100000))) .isEqualByComparingTo("9700"); }
From source file:easycare.load.util.db.loader.UserDataLoader.java
private void createUsersWithSubsetLocations(ContextOfCurrentLoad context, Organisation organisation, String organisationNumber) { List<Location> locations = organisation.activeLocations(); BigDecimal totalLocations = BigDecimal.valueOf(locations.size()); BigDecimal twoThirdLocations = totalLocations .divide(BigDecimal.valueOf(_THREE), _SIX, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(2)) .setScale(0, RoundingMode.CEILING); Location[] locationsToAdd = locations.subList(0, twoThirdLocations.intValue()).toArray(new Location[0]); List<Role> roles = newArrayList(seedData.getRole(ROLE_CLINICIAN)); buildUser(context, "remy" + organisationNumber, "Remy", "Roam", organisation, roles, organisationNumber, locationsToAdd);/* w ww.ja v a2 s.c om*/ }
From source file:com.antsdb.saltedfish.util.UberUtil.java
@SuppressWarnings("unchecked") public static <T> T toObject(Class<T> klass, Object val) { if (val == null) { return null; }//from w w w . j a v a2s. com if (klass.isInstance(val)) { return (T) val; } if (val instanceof byte[]) { if (((byte[]) val).length == 0) { return null; } val = new String((byte[]) val, Charsets.UTF_8); } if (klass == String.class) { return (T) String.valueOf(val); } if (val instanceof String) { String text = (String) val; if (klass == String.class) { return (T) text; } if (text.length() == 0) { return null; } if (klass == Integer.class) { return (T) new Integer(text); } else if (klass == Long.class) { return (T) new Long(text); } else if (klass == BigDecimal.class) { return (T) new BigDecimal(text); } else if (klass == Timestamp.class) { return (T) Timestamp.valueOf(text); } else if (klass == Date.class) { return (T) Date.valueOf(text); } else if (klass == Boolean.class) { return (T) new Boolean(text); } else if (klass == Double.class) { return (T) new Double(text); } } if (val instanceof BigDecimal) { if (klass == Long.class) { Long n = ((BigDecimal) val).longValueExact(); return (T) n; } else if (klass == Integer.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) n; } else if (klass == Double.class) { Double n = ((BigDecimal) val).doubleValue(); return (T) n; } else if (klass == Boolean.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) (Boolean) (n != 0); } } if (val instanceof Integer) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Integer) val); } else if (klass == Long.class) { return (T) Long.valueOf((Integer) val); } else if (klass == Boolean.class) { Integer n = (Integer) val; return (T) (Boolean) (n != 0); } } if (val instanceof Long) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Long) val); } else if (klass == Boolean.class) { Long n = (Long) val; return (T) (Boolean) (n != 0); } } if (val instanceof Boolean) { if (klass == Long.class) { return (T) Long.valueOf((Boolean) val ? 1 : 0); } } throw new IllegalArgumentException("class: " + val.getClass()); }