List of usage examples for org.apache.commons.lang.math NumberUtils createBigDecimal
public static BigDecimal createBigDecimal(String str)
Convert a String to a BigDecimal.
Returns null if the string is null.
From source file:MainClass.java
public static void main(String[] args) { //Create a BigDecimal from a String BigDecimal bDecimal = NumberUtils.createBigDecimal("123456789"); System.out.println(bDecimal); }
From source file:MathUtilsTrial.java
public static void main(String[] args) { // Create a BigDecimal from a String BigDecimal bDecimal = NumberUtils.createBigDecimal("123456789"); }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * //from w w w . ja v a2s. c o m * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }
From source file:backup.BillPrint.java
@RequestMapping(value = "/module/billing/billprint.htm", method = RequestMethod.GET) public String billPrintView(@RequestParam("patientId") Integer patientId, @RequestParam(value = "refDocId", required = false) Integer refDocId, @RequestParam(value = "billId", required = false) Integer billId, @RequestParam(value = "orderId", required = false) Integer orderId, @RequestParam(value = "date", required = false) String dStr, HttpServletRequest request, Model model) throws Exception { Patient patient = Context.getPatientService().getPatient(patientId); MedisunService ms = Context.getService(MedisunService.class); PatientSearch patientSearch = ms.getPatientSerachByID(patientId); model.addAttribute("patientSearch", patientSearch); BigDecimal paidAmount = NumberUtils.createBigDecimal(request.getParameter("paid")); model.addAttribute("paid", paidAmount); DiaPatientServiceBill dpsb = ms.getDiaPatientServiceBillId(billId); model.addAttribute("dpsb", dpsb); DocDetail docInfo = ms.getDocInfoById(refDocId); model.addAttribute("docInfo", docInfo); List<BillableService> diaBillOrderList = ms.getDiaBillingOrderandPatientId(orderId, patientId); model.addAttribute("billOrderList", diaBillOrderList); List<DiaPatientServiceBillItem> diaBillItemList = ms.getDiaBillItemByBillId(billId); model.addAttribute("diaBillItemList", diaBillItemList); List<DiaLabSampleid> diaSam = ms.getSampleIdByBillId(billId); model.addAttribute("diaSam", diaSam); PersonAttribute phone = patient.getAttribute("Phone Number"); if (phone != null) { model.addAttribute("phone", phone.getValue()); }/*from w ww .ja va 2 s . co m*/ //////// Barcode Print Set<Integer> labConceptIds = getLabConceptIds(); Set<Integer> radiologyConceptIds = getRadiologyConceptIds(); Integer medicalExaminationClassId = GlobalPropertyUtil .getInteger(HospitalCoreConstants.PROPERTY_MEDICAL_EXAMINATION, 9); ConceptClass medicalExaminationClass = Context.getConceptService() .getConceptClass(medicalExaminationClassId); List<Integer> cId = new ArrayList<Integer>(); List<String> cn = new ArrayList<String>(); for (DiaPatientServiceBillItem item : dpsb.getBillItems()) { Concept concept = Context.getConceptService().getConcept(item.getService().getConceptId()); // If item is a medical examination set if (concept.getConceptClass().equals(medicalExaminationClass)) { Collection<ConceptSet> conceptSets = concept.getConceptSets(); if (conceptSets != null && conceptSets.size() > 0) { for (ConceptSet con : conceptSets) { if (labConceptIds.contains(con.getConcept().getConceptId())) { cId.add(con.getId()); cn.add(con.getConcept().getName().getName()); } else if (radiologyConceptIds.contains(con.getConcept().getConceptId())) { } } } } else { if (labConceptIds.contains(concept.getConceptId())) { cId.add(concept.getId()); cn.add(concept.getName().getName()); } else if (radiologyConceptIds.contains(concept.getConceptId())) { } } } model.addAttribute("con", cId); model.addAttribute("cn", cn); List<String> a = new ArrayList<String>(); for (int i = 0; i < diaSam.size(); i++) { a.add(diaSam.get(i).getSampleId()); } List<Integer> conceptId = new ArrayList<Integer>(); for (int i = 0; i < cId.size(); i++) { conceptId.add(cId.get(i)); } Map<String, String> map = new HashMap(); List<TestModel> tmn = new ArrayList<TestModel>(); for (int i = 0; i < cn.size(); i++) { TestModel tm = new TestModel(); tm.setName(cn.get(i)); tm.setSampleId(a.get(i)); tm.setConceptId(conceptId.get(i)); tmn.add(tm); } model.addAttribute("tmn", tmn); //////////////////// End Barcode Print //////////////// model.addAttribute("patient", patient); Date birthday = patient.getBirthdate(); model.addAttribute("age", PatientUtils.estimateAge(birthday)); model.addAttribute("billId", billId); User user = Context.getAuthenticatedUser(); model.addAttribute("billOfficer", user); return "module/billing/private/printBill"; }
From source file:com.opengamma.web.position.WebPositionsResource.java
private FlexiBean createSearchResultData(PagingRequest pr, String identifier, String minQuantityStr, String maxQuantityStr, List<String> positionIdStrs, List<String> tradeIdStrs) { minQuantityStr = StringUtils.defaultString(minQuantityStr).replace(",", ""); maxQuantityStr = StringUtils.defaultString(maxQuantityStr).replace(",", ""); FlexiBean out = createRootData();/*from ww w .ja v a 2 s. com*/ PositionSearchRequest searchRequest = new PositionSearchRequest(); searchRequest.setPagingRequest(pr); searchRequest.setSecurityIdValue(StringUtils.trimToNull(identifier)); if (NumberUtils.isNumber(minQuantityStr)) { searchRequest.setMinQuantity(NumberUtils.createBigDecimal(minQuantityStr)); } if (NumberUtils.isNumber(maxQuantityStr)) { searchRequest.setMaxQuantity(NumberUtils.createBigDecimal(maxQuantityStr)); } for (String positionIdStr : positionIdStrs) { searchRequest.addPositionObjectId(ObjectId.parse(positionIdStr)); } for (String tradeIdStr : tradeIdStrs) { searchRequest.addPositionObjectId(ObjectId.parse(tradeIdStr)); } out.put("searchRequest", searchRequest); if (data().getUriInfo().getQueryParameters().size() > 0) { PositionSearchResult searchResult = data().getPositionMaster().search(searchRequest); out.put("searchResult", searchResult); out.put("paging", new WebPaging(searchResult.getPaging(), data().getUriInfo())); } return out; }
From source file:com.impetus.kundera.validation.rules.AttributeConstraintRule.java
/** * Checks whether a given value is a valid minimum decimal digit when compared to given value * or not/*from ww w.ja v a 2s .com*/ * * @param validationObject * @param annotate * @return */ private boolean validateMinDecimal(Object validationObject, Annotation annotate) { if (validationObject != null) { try { if (checkvalidDeciDigitTypes(validationObject.getClass())) { BigDecimal minValue = NumberUtils.createBigDecimal(((DecimalMin) annotate).value()); BigDecimal actualValue = NumberUtils.createBigDecimal(toString(validationObject)); int res = actualValue.compareTo(minValue); if (res < 0) { throwValidationException(((DecimalMin) annotate).message()); } } } catch (NumberFormatException nfe) { throw new RuleValidationException(nfe.getMessage()); } } return true; }
From source file:com.impetus.kundera.validation.rules.AttributeConstraintRule.java
/** * Checks whether a given value is a valid maximum decimal digit when compared to given value * or not/*from ww w . j a va 2s .c o m*/ * * @param validationObject * @param annotate * @return */ private boolean validateMaxDecimal(Object validationObject, Annotation annotate) { if (validationObject != null) { try { if (checkvalidDeciDigitTypes(validationObject.getClass())) { BigDecimal maxValue = NumberUtils.createBigDecimal(((DecimalMax) annotate).value()); BigDecimal actualValue = NumberUtils.createBigDecimal(toString(validationObject)); int res = actualValue.compareTo(maxValue); if (res > 0) { throwValidationException(((DecimalMax) annotate).message()); } } } catch (NumberFormatException nfe) { throw new RuleValidationException(nfe.getMessage()); } } return true; }
From source file:com.mmj.app.common.core.lang.CollectionUtils.java
/** * Number value = sum(new Long(0),array,"value"); *//* w ww . jav a2 s . c o m*/ public static <T extends Number> T sum(T rawValue, List<?> array, String property) { for (Object obj : array) { String propertyValue = null; try { propertyValue = BeanUtils.getProperty(obj, property); } catch (Exception e) { e.printStackTrace(); } if (NumberUtils.isNumber(propertyValue) == false) { continue; } if (rawValue instanceof Integer) { rawValue = (T) new Integer(((Integer) rawValue) + NumberUtils.createInteger(propertyValue)); } else if (rawValue instanceof Long) { rawValue = (T) new Long(((Long) rawValue) + NumberUtils.createLong(propertyValue)); } else if (rawValue instanceof Float) { rawValue = (T) new Float(((Float) rawValue) + NumberUtils.createFloat(propertyValue)); } else if (rawValue instanceof Double) { rawValue = (T) new Double(((Double) rawValue) + NumberUtils.createDouble(propertyValue)); } else if (rawValue instanceof BigInteger) { rawValue = (T) NumberUtils.createBigInteger(propertyValue).add((BigInteger) rawValue); } else if (rawValue instanceof BigDecimal) { rawValue = (T) NumberUtils.createBigDecimal(propertyValue).add((BigDecimal) rawValue); } } return rawValue; }
From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java
public static <T extends Number, E extends Object> T sum(T rawValue, List<E> array, ObjectConvert<E, ? extends Object> convert) { for (E obj : array) { String propertyValue = null; try {//from w w w.j av a 2 s .com Object value = convert.convert(obj); if (value == null) { continue; } else { propertyValue = value.toString(); } } catch (Exception e) { e.printStackTrace(); } if (NumberUtils.isNumber(propertyValue) == false) { continue; } if (rawValue instanceof Integer) { rawValue = (T) new Integer(((Integer) rawValue) + NumberUtils.createInteger(propertyValue)); } else if (rawValue instanceof Long) { rawValue = (T) new Long(((Long) rawValue) + NumberUtils.createLong(propertyValue)); } else if (rawValue instanceof Float) { rawValue = (T) new Float(((Float) rawValue) + NumberUtils.createFloat(propertyValue)); } else if (rawValue instanceof Double) { rawValue = (T) new Double(((Double) rawValue) + NumberUtils.createDouble(propertyValue)); } else if (rawValue instanceof BigInteger) { rawValue = (T) NumberUtils.createBigInteger(propertyValue).add((BigInteger) rawValue); } else if (rawValue instanceof BigDecimal) { rawValue = (T) NumberUtils.createBigDecimal(propertyValue).add((BigDecimal) rawValue); } } return rawValue; }
From source file:org.locationtech.udig.ui.NumberCellEditor.java
private Number convertToNumber() { if (cls == Integer.class) { return NumberUtils.createInteger(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Long.class) { return NumberUtils.createLong(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == BigInteger.class) { return NumberUtils.createBigInteger(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == BigDecimal.class) { return NumberUtils.createBigDecimal(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Double.class) { return NumberUtils.createDouble(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Float.class) { return NumberUtils.createFloat(StringUtils.isNotEmpty(text.getText()) ? text.getText() : null); } else if (cls == Short.class) { if (StringUtils.isNotEmpty(text.getText())) { return Short.valueOf(text.getText()); } else {/* www . j av a 2 s .c o m*/ return null; } } return null; }