List of usage examples for org.apache.commons.lang.math NumberUtils toFloat
public static float toFloat(String str)
Convert a String to a float, returning 0.0f if the conversion fails.
If the string str is null, 0.0f is returned.
NumberUtils.toFloat(null) = 0.0f NumberUtils.toFloat("") = 0.0f NumberUtils.toFloat("1.5") = 1.5f From source file:com.ms.app.web.commons.tools.CurrencyFormattor.java
/** * //w w w. j a v a 2 s.com * * @param yuan ?( 10.0010) * @return */ public static int convert2fen(String yuan) { return (int) (NumberUtils.toFloat(yuan) * 100); }
From source file:com.zb.app.external.wechat.request.WeixinLocationRequest.java
public WeixinLocationRequest(Map<String, String> datas) { super(datas); locationX = NumberUtils.toFloat(datas.get("Location_X")); locationY = NumberUtils.toFloat(datas.get("Location_Y")); scale = NumberUtils.toFloat(datas.get("Scale")); label = datas.get("Label"); }
From source file:com.zb.app.external.wechat.request.WeixinEventLocationRequest.java
public WeixinEventLocationRequest(Map<String, String> datas) { super(datas); latitude = NumberUtils.toFloat(datas.get("Latitude")); longitude = NumberUtils.toFloat(datas.get("Longitude")); precision = NumberUtils.toFloat(datas.get("Precision")); }
From source file:com.adaptris.core.services.jdbc.FloatStatementParameter.java
Float toFloat(Object value) throws ServiceException { if (isBlank((String) value) && convertNull()) { return Float.valueOf(NumberUtils.toFloat((String) value)); } else {/*from w w w . ja v a2 s . c om*/ return Float.valueOf((String) value); } }
From source file:com.edgenius.wiki.render.macro.RatingMacro.java
public void execute(StringBuffer buffer, MacroParameter params) throws MalformedMacroException { buffer.append("<div class='macroRating'"); //default value float score = 0; int full = 5; String shape = "star"; String size = null;//from ww w . jav a 2 s.c o m Map<String, String> pm = params.getParams(); if (pm != null) { String wajax = RichTagUtil.buildWajaxAttributeString(this.getClass().getName(), pm); buffer.append(" wajax=\"").append(wajax).append("\""); String scoreStr = pm.get("score"); int sep = scoreStr.indexOf("/"); if (sep != -1) { score = NumberUtils.toFloat(scoreStr.substring(0, sep)); full = NumberUtils.toInt(scoreStr.substring(sep + 1), full); } //TODO: only one shape support shape = pm.get("shape"); if (!"star".equalsIgnoreCase(shape)) { shape = "star"; } shape.toLowerCase(); String sizeStr = pm.get("size"); if (!StringUtils.isBlank(sizeStr)) { size = sizeStr; } } buffer.append(">"); RenderContext context = params.getRenderContext(); for (int idx = 1; idx <= full; idx++) { String imgName; if (idx > score) { if (idx < score + 1) { //half imgName = shape + "half.png"; } else { //blank imgName = shape + "blank.png"; } } else { //full imgName = shape + ".png"; } String[] attr = null; if (size != null) { attr = new String[] { NameConstants.WIDTH, size, NameConstants.HEIGHT, size }; } buffer.append(context.buildSkinImageTag("render/rating/" + imgName, attr)); } buffer.append("</div>"); }
From source file:com.hangum.tadpole.commons.util.ServletUserAgent.java
public void detectBrowser(String userAgentStr) { if (null != userAgentStr) { try {/*from ww w . ja v a 2 s .com*/ if (userAgentStr.contains("Edge/")) { browser_Type = BROWSER_TYPE.EDGE; fullVersion = userAgentStr.substring(userAgentStr.indexOf("Edge/") + 5); // fullVersion = fullVersion;//.substring(0, fullVersion.indexOf(";")).trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } else if (userAgentStr.contains("MSIE ")) { browser_Type = BROWSER_TYPE.IE; fullVersion = userAgentStr.substring(userAgentStr.indexOf("MSIE ") + 5); fullVersion = fullVersion.substring(0, fullVersion.indexOf(";")).trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } else if (userAgentStr.contains("Trident")) { browser_Type = BROWSER_TYPE.IE; // Internet Explorer 11 // Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko // Internet Explorer 10 // Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) if (userAgentStr.contains("Trident/6.0")) { fullVersion = "10"; majorVersion = 10; } else { fullVersion = userAgentStr.substring(userAgentStr.indexOf("rv:")); fullVersion = fullVersion.substring(3, fullVersion.indexOf(")")).trim(); majorVersion = (int) NumberUtils.toFloat(fullVersion); } } else if (userAgentStr.contains("Chrome/")) { browser_Type = BROWSER_TYPE.CHROME; fullVersion = userAgentStr.substring(userAgentStr.indexOf("Chrome/") + 7); fullVersion = fullVersion.substring(0, fullVersion.indexOf(" ")).trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } else if (userAgentStr.contains("Firefox/")) { browser_Type = BROWSER_TYPE.FIREFOX; fullVersion = userAgentStr.substring(userAgentStr.indexOf("Firefox/") + 8); fullVersion = fullVersion.substring(0, (fullVersion.indexOf(" ") > 0 ? fullVersion.indexOf(" ") : fullVersion.length())) .trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } else if (userAgentStr.contains("Opera ") || userAgentStr.contains("Opera/")) { browser_Type = BROWSER_TYPE.OPERA; fullVersion = userAgentStr.substring(userAgentStr.indexOf("Opera ") + 6); fullVersion = fullVersion.substring(0, (fullVersion.indexOf(" ") > 0 ? fullVersion.indexOf(" ") : fullVersion.length())) .trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } else if (userAgentStr.contains("Safari/")) { browser_Type = BROWSER_TYPE.SAFARI; fullVersion = userAgentStr.substring(userAgentStr.indexOf("Version/") + 8); fullVersion = fullVersion.substring(0, (fullVersion.indexOf(" ") > 0 ? fullVersion.indexOf(" ") : fullVersion.length())) .trim(); majorVersion = Integer.parseInt(fullVersion.substring(0, fullVersion.indexOf("."))); } } catch (Exception nfe) { fullVersion = "0"; majorVersion = 0; } } }
From source file:com.netsteadfast.greenstep.bsc.action.RegionMapRelationKpisAction.java
private void fillRelationKpis(BscStructTreeObj treeObj) throws Exception { List<VisionVO> visions = treeObj.getVisions(); for (VisionVO vision : visions) { for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { boolean isFound = false; for (Map<String, Object> founds : this.relationKpis) { if (kpi.getId().equals(founds.get("id"))) { isFound = true; }/*from w w w. j a va 2s . c om*/ } if (isFound) { continue; } Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("id", kpi.getId()); paramMap.put("name", kpi.getName()); paramMap.put("score", NumberUtils.toFloat(BscReportSupportUtils.parse2(kpi.getScore()))); paramMap.put("bgColor", kpi.getBgColor()); paramMap.put("fontColor", kpi.getFontColor()); paramMap.put("target", kpi.getTarget()); paramMap.put("min", kpi.getMin()); this.relationKpis.add(paramMap); } } } } }
From source file:com.easemob.dataexport.utils.ConversionUtils.java
public static float getFloat(Object obj) { if (obj instanceof Float) { return (Float) obj; }// ww w . j a v a2 s . c om if (obj instanceof Number) { return ((Number) obj).floatValue(); } if (obj instanceof String) { return NumberUtils.toFloat((String) obj); } if (obj instanceof Date) { return ((Date) obj).getTime(); } if (obj instanceof byte[]) { return getFloat((byte[]) obj); } if (obj instanceof ByteBuffer) { return getFloat((ByteBuffer) obj); } return 0; }
From source file:com.gcrm.action.crm.ListAccountAction.java
protected SearchCondition getSearchCondition(Map<String, String> fieldTypeMap, int scope, User loginUser) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); StringBuilder condition = new StringBuilder(""); // SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_SIMPLE_FORMAT); if (StringUtils.isEmpty(assignTo)) { condition.append("assigned_to").append(" in ( ").append(String.valueOf(loginUser.getId())).append(" )"); }/* w w w . jav a2s .c o m*/ if (super.getFilters() != null && super.getFilters().trim().length() > 0) { advancedSearch(condition); } else { HashMap parameters = (HashMap) request.getParameterMap(); Iterator iterator = parameters.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String[] value = ((String[]) parameters.get(key)); // TODO:? // String val = new String(value[0].getBytes("iso8859-1")); String val = value[0]; if (value == null || StringUtils.isEmpty(value[0])) { continue; } if (!BaseListAction.GRID_FIELD_SET.contains(key)) { if (StringUtils.equals(key, "mallbdLevels")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("mallbd_level").append(" in ("); for (int i = 0; i < value.length; i++) { condition.append("'").append(value[i]).append("'"); if (i < (value.length - 1)) { condition.append(","); } } condition.append(")"); } else if (StringUtils.equals(key, "advertLevels")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("advert_level").append(" in ("); for (int i = 0; i < value.length; i++) { condition.append("'").append(value[i]).append("'"); if (i < (value.length - 1)) { condition.append(","); } } condition.append(")"); } else if (StringUtils.equals(key, "intentNames")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("accountIntent").append(" in (").append(StringUtils.join(value, ",")) .append(" )"); } else if (StringUtils.equals(key, "visitNames")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("accountVisit").append(" in (").append(StringUtils.join(value, ",")) .append(" )"); } else if (StringUtils.equals(key, "accountTypes")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("account_type").append(" in (").append(StringUtils.join(value, ",")) .append(" )"); } else if (StringUtils.equals(key, "assignTo")) { if (StringUtils.equalsIgnoreCase("all", val)) { continue; } if (condition.length() != 0) { condition.append(" AND "); } String assignedToStr = null; if (StringUtils.equalsIgnoreCase("self", val)) { // assignedToStr = String.valueOf(loginUser.getId()); } else if (StringUtils.equals(val, "underling")) { // List<Integer> userIdList = new ArrayList<Integer>(); String hql = "from User where report_to = " + loginUser.getId(); underlingUsers = userService.findByHQL(hql); if (underlingUsers == null || underlingUsers.isEmpty()) { return null; } for (User u : underlingUsers) { userIdList.add(u.getId()); } assignedToStr = StringUtils.join(userIdList, ","); } else if (StringUtils.equals(val, "selfAndunderling")) { // ? List<Integer> userIdList = new ArrayList<Integer>(); String hql = "from User where report_to = " + loginUser.getId(); underlingUsers = userService.findByHQL(hql); for (User u : underlingUsers) { userIdList.add(u.getId()); } userIdList.add(loginUser.getId()); assignedToStr = StringUtils.join(userIdList, ","); } else if (NumberUtils.toInt(val) != 0) { // ? assignedToStr = val; } if (assignedToStr != null) { condition.append("assigned_to").append(" in ( ").append(assignedToStr).append(" )"); } } else if (StringUtils.equals(key, "detailAddress")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("(province").append(" like '%").append(val).append("%'"); condition.append(" or ").append("city").append(" like '%").append(val).append("%'"); condition.append(" or ").append("district").append(" like '%").append(val).append("%'"); condition.append(" or ").append("address").append(" like '%").append(val).append("%')"); } else if (StringUtils.equals(key, "account.province")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("(province").append(" like '%").append(val).append("%')"); } else if (StringUtils.equals(key, "account.city")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("(city").append(" like '%").append(val).append("%')"); } else if (StringUtils.equals(key, "account.district")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("(district").append(" like '%").append(val).append("%')"); } else if (StringUtils.equals(key, "startAssignDate")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("updated_on").append(" >= '").append(val).append("' "); } else if (StringUtils.equals(key, "endAssignDate")) { if (condition.length() != 0) { condition.append(" AND "); } condition.append("updated_on").append(" <= '").append(val).append("' "); } else { if (condition.length() != 0) { condition.append(" AND "); } if (NumberUtils.toFloat(val) != 0.0f) { condition.append(key).append(" = ").append(val); } else { if (StringUtils.contains(val, ">")) { int index = val.indexOf(">"); String v = val.substring(index + 1); condition.append(key).append(" > ").append(v.trim()); } else if (StringUtils.contains(val, "<")) { int index = val.indexOf("<"); String v = val.substring(index + 1); condition.append(key).append(" < ").append(v.trim()); } else { condition.append(key).append(" like '%").append(val).append("%'"); } } } } } } // if (scope == Role.OWNER_OR_DISABLED) { // if (condition.length() != 0) { // condition.append(" AND "); // } // condition.append("owner = ").append(loginUser.getId()); // } int pageNo = super.getPage(); if (pageNo == 0) { pageNo = 1; } int pageSize = super.getRows(); if (pageSize == 0) { pageSize = 1; } super.setSidx("assigned_date"); super.setSord("desc"); SearchCondition searchCondition = new SearchCondition(pageNo, pageSize, super.getSidx(), super.getSord(), condition.toString()); return searchCondition; }
From source file:org.carewebframework.vista.plugin.patientgoals.service.GoalService.java
/** * Convert raw data into patient goals list. * * <pre>// www. j ava 2 s .c om * (0) IEN [0] ^ GSET [1] ^ CREATED BY [2] ^ CREATED DATE [3] ^ LAST MODIFIED [4] ^ FACILITY [5] ^ PROVIDER [6] ^ * START DATE [7] ^ FOLLOWUP DATE [8] ^ STATUS [9] ^ GOAL NUMBER [10] * (1) TYPE1 ^ TYPE2 ^ TYPE3... * (2) GOAL NAME [0] * (3) GOAL REASON [0] * (4) "REVIEW" [0] ^ REVIEW DATE [1] ^ NOTE [2] (will be 0 or more rows of these) * (5) "STEP" [0] ^ FACILITY [1] ^ STEP IEN [2] ^ STEP NUMBER [3] ^ CREATED BY [4] ^ CREATED DATE [5] ^ * TYPE [6] ^ START DATE [7] ^ FOLLOWUP DATE [8] ^ MODIFIED BY [9] ^ LAST MODIFIED [10] ^ STATUS [11] ^ * PROVIDER [13] (will be 0 or more rows of these) * (6) STEP TEXT [0] (only if #5 is present) * For example: * 0: 1^GOAL SET^3150521^ADAM,ADAM^3150521.21114^DEMO IHS CLINIC^ADAM,ADAM^3150521^3150530^A;ACTIVE^1 * 1: PHYSICAL ACTIVITY * 2: TEST * 3: * 4: REVIEW^3150522^PROGRESS NOTE REVIEWED * 5: STEP^7819;DEMO IHS CLINIC^1^1^ADAM,ADAM^3150521^TOBACCO^3150521^3150627^ADAM,ADAM^3150521.211237^A;ACTIVE^ADAM,ADAM * 6: TEST STEP * 7: 2^GOAL SET^3150521^ADAM,ADAM^3150521.212321^DEMO IHS CLINIC^ADAM,ADAM^3150521^3150530^S;GOAL STOPPED^2 * 8: MEDICATIONS^OTHER^WELLNESS AND SAFETY * 9: TEST2 * 10:TEST * </pre> */ @Override protected List<Goal> processData(IQueryContext context, String data) { List<Goal> results = new ArrayList<>(); List<String> list = StrUtil.toList(data, "\r"); Goal goal = null; Step step = null; int state = 0; for (String line : list) { String[] pcs = StrUtil.split(line, StrUtil.U, 1); switch (state) { case 4: // Review if ("REVIEW".equals(pcs[0])) { goal.getReviews().add(new Review(FMDate.fromString(pcs[1]), pcs[2])); break; } Collections.sort(goal.getReviews()); // Note that fall through is intended here. case 5: // Step if ("STEP".equals(pcs[0])) { state = 6; step = new Step(goal); goal.getSteps().add(step); step.setFacility(pcs[1]); step.setIEN(pcs[2]); step.setNumber(NumberUtils.toFloat(pcs[3])); step.setCreatedBy(pcs[4]); step.setCreatedDate(FMDate.fromString(pcs[5])); step.getTypes().add(getGoalType(pcs[6])); step.setStartDate(FMDate.fromString(pcs[7])); step.setFollowupDate(FMDate.fromString(pcs[8])); step.setUpdatedBy(pcs[9]); step.setLastUpdated(FMDate.fromString(pcs[10])); step.setStatus(toEnum(pcs[11], GoalStatus.class)); step.setProvider(pcs[12]); break; } // Note that fall through is intended here. case 0: // New goal if (goal != null) { results.add(goal); } step = null; goal = new Goal(); goal.setPatient((Patient) context.getParam("patient")); goal.setIEN(pcs[0]); goal.setDeclined("GOAL NOT SET".equals(pcs[1])); goal.setCreatedDate(FMDate.fromString(pcs[2])); goal.setCreatedBy(pcs[3]); goal.setLastUpdated(FMDate.fromString(pcs[4])); goal.setFacility(pcs[5]); goal.setProvider(pcs[6]); goal.setStartDate(FMDate.fromString(pcs[7])); goal.setFollowupDate(FMDate.fromString(pcs[8])); goal.setStatus(toEnum(pcs[9], GoalStatus.class)); goal.setNumber(NumberUtils.toFloat(pcs[10])); state = 1; break; case 1: // Types for (int i = 0; i < pcs.length; i++) { goal.getTypes().add(getGoalType(pcs[i])); } state = 2; break; case 2: // Goal name goal.setName(pcs[0]); state = 3; break; case 3: // Goal reason goal.setReason(pcs[0]); state = 4; break; case 6: // Step text step.setName(pcs[0]); state = 5; break; } } if (goal != null) { results.add(goal); } return results; }