List of usage examples for org.apache.commons.lang3.math NumberUtils createLong
public static Long createLong(final String str)
Convert a String
to a Long
; since 3.1 it handles hex (0Xhhhh) and octal (0ddd) notations.
From source file:io.cloudslang.content.utils.NumberUtilities.java
/** * Given a long integer string if it's a valid long (see isValidLong) it converts it into a long integer otherwise it throws an exception * * @param longStr the long integer to convert * @return the long integer value of the longStr * @throws IllegalArgumentException if the passed long integer string is not a valid long value */// www. j a v a 2 s. c om public static long toLong(@Nullable final String longStr) { if (!isValidLong(longStr)) { throw new IllegalArgumentException( longStr + ExceptionValues.EXCEPTION_DELIMITER + ExceptionValues.INVALID_LONG_VALUE); } final String stripedLong = StringUtils.strip(longStr); return NumberUtils.createLong(stripedLong); }
From source file:de.joerghoh.cq5.healthcheck.impl.providers.MBeanStatusProvider.java
/** * compare helper method to compare the different types of attribute values * supported types: ** long ** integer ** boolean ** string * /* ww w.j av a 2 s . c om*/ * @param comparisonOperation * @param comparisonValue * @param jmxValueObj * @return */ private boolean compareAttributeValue(final String comparisonOperation, final String comparisonValue, Object jmxValueObj) { boolean match = false; if (jmxValueObj instanceof Long) { // first check for plain value final long jmxLongValue = Long.parseLong(jmxValueObj.toString()); final long comparisonLongValue = NumberUtils.createLong(comparisonValue); if (comparisonOperation.equals(">")) { match = (jmxLongValue > comparisonLongValue); } else if (comparisonOperation.equals("==")) { match = (jmxLongValue == comparisonLongValue); } else if (comparisonOperation.equals("!=")) { match = (jmxLongValue != comparisonLongValue); } else if (comparisonOperation.equals("<")) { match = (jmxLongValue < comparisonLongValue); } else { log.warn("Can not compare long values {} and {}", jmxLongValue, comparisonLongValue); throw new RuntimeException(); } } else if (jmxValueObj instanceof Integer) { final int jmxIntValue = Integer.parseInt(jmxValueObj.toString()); final int comparisonIntValue = NumberUtils.createInteger(comparisonValue); if (comparisonOperation.equals(">")) { match = (jmxIntValue > comparisonIntValue); } else if (comparisonOperation.equals("==")) { match = (jmxIntValue == comparisonIntValue); } else if (comparisonOperation.equals("!=")) { match = (jmxIntValue != comparisonIntValue); } else if (comparisonOperation.equals("<")) { match = (jmxIntValue < comparisonIntValue); } else { log.warn("Can not compare int values {} and {}", jmxIntValue, comparisonIntValue); throw new RuntimeException(); } } else if (jmxValueObj instanceof long[]) { // second check for array final long[] jmxLongArrayValue = (long[]) jmxValueObj; final long comparisonLongValue = NumberUtils.createLong(comparisonValue); if (comparisonOperation.equals(">")) { match = (NumberUtils.max(jmxLongArrayValue) > comparisonLongValue); } else if (comparisonOperation.equals("==")) { // TODO maybe it makes more sense for == to compare all array // values? match = ArrayUtils.contains(jmxLongArrayValue, comparisonLongValue); } else if (comparisonOperation.equals("<")) { match = (NumberUtils.min(jmxLongArrayValue) < comparisonLongValue); } else { log.warn("Can not compare long array values {} and {}", jmxLongArrayValue, comparisonLongValue); throw new RuntimeException(); } } else if (jmxValueObj instanceof String) { // third check for String // values log.info("type comparison: string"); final String jmxStringValue = jmxValueObj.toString(); if (comparisonOperation.equals("equals")) { match = (comparisonValue.equals(jmxStringValue)); } else if (comparisonOperation.equals("notequals")) { match = (!comparisonValue.equals(jmxStringValue)); } else { log.warn("Can not compare String values {} and {}", jmxStringValue, comparisonValue); throw new RuntimeException(); } } else if (jmxValueObj instanceof Boolean) { final boolean jmxBooleanValue = (Boolean) jmxValueObj; final boolean comparisonBooleanValue = Boolean.parseBoolean(comparisonValue); if (comparisonOperation.equals("equals")) { match = (comparisonBooleanValue == jmxBooleanValue); } else if (comparisonOperation.equals("==")) { match = (comparisonBooleanValue == jmxBooleanValue); } else if (comparisonOperation.equals("notequals")) { match = (comparisonBooleanValue != jmxBooleanValue); } else { log.warn("Can not compare boolean values {} and {}", jmxBooleanValue, comparisonBooleanValue); throw new RuntimeException(); } } else { log.warn("Can not compare jmx attribute value {} with {}", jmxValueObj, comparisonValue); log.warn("jmxValueObj type = " + jmxValueObj.getClass().getName()); throw new RuntimeException(); } return match; }
From source file:de.micromata.genome.gwiki.plugin.vfolder_1_0.GWikiVFolderUtils.java
public static GWikiVFolderCachedFileInfos readCache(GWikiVFolderNode node) { GWikiVFolderCachedFileInfos ret = new GWikiVFolderCachedFileInfos(); if (node.getFileSystem().exists(VFOLDERCACHEFILE) == false) { return ret; }//from www. j ava2s. co m String content = node.getFileSystem().readTextFile(VFOLDERCACHEFILE); List<String> lines = Converter.parseStringTokens(content, "\n", false); for (String line : lines) { int idx = line.indexOf(':'); if (idx == -1) { continue; } String localName = line.substring(0, idx); String rest = line.substring(idx + 1); Map<String, String> atts = PipeValueList.decode(rest); GWikiProps props = new GWikiSettingsProps(); props.setMap(atts); // TODO set meta template GWikiElementInfo ei = new GWikiElementInfo(props, null); ret.addElement(localName, ei); } if (node.getFileSystem().exists(VFOLDERSTATUSFILE) == true) { String tc = node.getFileSystem().readTextFile(VFOLDERSTATUSFILE); Map<String, String> m = PipeValueList.decode(tc); if (StringUtils.isNumeric(m.get("fsmodcounter")) == true) { ret.setLastFsModifiedCounter(NumberUtils.createLong(m.get("fsmodcounter"))); } } return ret; }
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * Long/*from ww w .j a va 2 s . co m*/ * * @param o * @param defaultValue * @return */ public static long toLong(String o, Long defaultValue) { if (isBlank(o)) return defaultValue;// nullnull try { return NumberUtils.createLong(o); } catch (NumberFormatException e) { if (defaultValue == null)// null throw e; return defaultValue; } }
From source file:fi.foyt.fni.materials.MaterialController.java
public Material findMaterialByCompletePath(String completePath) { String path = RequestUtils.stripTrailingSlash(completePath); String materialPath = RequestUtils.stripPrecedingSlash(path.substring(MATERIALS_PATH.length() + 1)); PermaLink permaLink = permaLinkDAO.findByPath(materialPath); if (permaLink != null) { return permaLink.getMaterial(); }//from w w w . j av a 2 s .c o m String[] pathElements = materialPath.split("/"); if (pathElements.length >= 2) { String userIdPart = pathElements[0]; if (!NumberUtils.isNumber(userIdPart)) { return null; } Long userId = NumberUtils.createLong(userIdPart); if (userId == null) { return null; } User owner = userDAO.findById(userId); if (owner == null) { return null; } Folder parentFolder = null; for (int i = 1, l = pathElements.length - 1; i < l; i++) { String pathElement = pathElements[i]; if (parentFolder != null) parentFolder = (Folder) materialDAO.findByParentFolderAndUrlName(parentFolder, pathElement); else parentFolder = (Folder) materialDAO.findByRootFolderAndUrlName(owner, pathElement); } if (parentFolder != null) return materialDAO.findByParentFolderAndUrlName(parentFolder, pathElements[pathElements.length - 1]); else return materialDAO.findByRootFolderAndUrlName(owner, pathElements[pathElements.length - 1]); } return null; }
From source file:org.tightblog.ui.security.MultiFactorAuthenticationProvider.java
private static boolean isValidLong(String code) { try {// w ww. j ava2 s.c om NumberUtils.createLong(code); } catch (NumberFormatException e) { return false; } return true; }
From source file:system.controllers.UserApp.java
@Transactional(readOnly = false) public static Result saveUserState() { DynamicForm requestData = Form.form().bindFromRequest(); Long userId = NumberUtils.createLong(requestData.get("userId")); String isEnableStr = defaultIfNotContain(requestData.get("disableState"), new String[] { "0", "1" }, null); String isComplainStr = defaultIfNotContain(requestData.get("complainState"), new String[] { "0", "1" }, null);/*from w w w . j a v a 2s.c o m*/ String isOnlineStr = defaultIfNotContain(requestData.get("onlineState"), new String[] { "0", "1" }, null); isComplainStr = "0"; isOnlineStr = "0"; Boolean isEnable = BooleanUtils.toBooleanObject(isEnableStr, "1", "0", null); Boolean isComplain = BooleanUtils.toBooleanObject(isComplainStr, "1", "0", null); Boolean isOnline = BooleanUtils.toBooleanObject(isOnlineStr, "1", "0", null); String onlineServiceStr = requestData.get("onlineService"); // ? String onlineTranslationStr = requestData.get("onlineTranslation"); // boolean isOnlineService = Boolean.FALSE; boolean isOnlineTranslation = Boolean.FALSE; if (StringUtils.equals("1", onlineServiceStr)) { isOnlineService = Boolean.TRUE; } if (StringUtils.equals("1", onlineTranslationStr)) { isOnlineTranslation = Boolean.TRUE; } ObjectNode result = Json.newObject(); if (null == userId || null == isEnable || null == isOnline || null == isComplain) { result.put("success", false); } else { try { UserService.saveUserState(userId, isEnable, isComplain, isOnline); ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false); Expert expert = Expert.getExpertByUserId(userId); List<String> skillsTagsList = new ArrayList<String>(); try { if (expert != null && StringUtils.isNotEmpty(expert.skillsTags)) { if (expert.skillsTags != null) { skillsTagsList = objectMapper.readValue(expert.skillsTags, List.class); } } } catch (Exception e) { e.printStackTrace(); skillsTagsList = new ArrayList<String>(); } String ss1 = "?"; if (!isOnlineService) { if (expert != null && expert.skillsTags != null && expert.skillsTags.contains("\"" + ss1 + "\"")) { Iterator<String> ite = skillsTagsList.iterator(); while (ite.hasNext()) { String item = ite.next(); if (StringUtils.equals(item, ss1)) { ite.remove(); } } } } else { if (expert != null && expert.skillsTags != null && !expert.skillsTags.contains("\"" + ss1 + "\"")) { skillsTagsList.add(ss1); } else if (expert != null && expert.skillsTags == null) { skillsTagsList.add(ss1); } } String ss2 = ""; if (!isOnlineTranslation) { if (expert != null && expert.skillsTags != null && expert.skillsTags.contains("\"" + ss2 + "\"")) { Iterator<String> ite = skillsTagsList.iterator(); while (ite.hasNext()) { String item = ite.next(); if (StringUtils.equals(item, ss2)) { ite.remove(); } } } } else { if (expert != null && expert.skillsTags != null && !expert.skillsTags.contains("\"" + ss2 + "\"")) { skillsTagsList.add(ss2); } else if (expert != null && expert.skillsTags == null) { skillsTagsList.add(ss2); } } expert.skillsTags = objectMapper.writeValueAsString(skillsTagsList); if (isEnable == true) { expert.saveOrUpate(); } result.put("success", true); } catch (Exception e) { ExtForm extForm = new ExtForm(); extForm.setSuccess(false); extForm.setMsg("?" + e.getMessage()); if (Logger.isErrorEnabled()) { Logger.error("?????", e); } return ok(play.libs.Json.toJson(extForm)); } } return ok(result); }
From source file:system.controllers.UserApp.java
@Transactional(readOnly = false) public static Result top() { DynamicForm requestData = Form.form().bindFromRequest(); Long userId = NumberUtils.createLong(requestData.get("userId")); Long industryId = NumberUtils.createLong(requestData.get("industryId")); ObjectNode result = Json.newObject(); if (null == userId || null == industryId) { result.put("success", false); } else {// w ww . j a v a2 s . c om Expert expert = Expert.findByUserId(userId); if (null == expert) { result.put("success", false); result.put("errorCode", 1); result.put("errorMsg", "??"); } else { if (expert.isTop != null && expert.isTop && expert.topIndustry != null) { result.put("success", false); result.put("errorCode", 1); result.put("errorMsg", "??"); return ok(result); } List<SkillTag> skillTagList = SkillTag.listCategoriesOfExpert(userId); if (CollectionUtils.isEmpty(skillTagList)) { result.put("success", false); result.put("errorCode", 1); result.put("errorMsg", ""); return ok(result); } for (SkillTag st : skillTagList) { Long skillTagId = st.id; if (skillTagId - industryId == 0) { TopService.topExpert(userId, industryId); // Cache.remove(Constants.CACHE_EXPERT_TOPS); // result.put("success", true); break; } } if (result.get("success") == null) { result.put("success", false); result.put("errorCode", 1); result.put("errorMsg", ""); } } } return ok(result); }
From source file:system.controllers.UserApp.java
@Transactional(readOnly = false) public static Result untop() { DynamicForm requestData = Form.form().bindFromRequest(); Long userId = NumberUtils.createLong(requestData.get("userId")); ObjectNode result = Json.newObject(); if (null == userId) { result.put("success", false); } else {//from w w w . ja v a 2 s .co m TopService.unTopExpert(userId); // Cache.remove(Constants.CACHE_EXPERT_TOPS); // result.put("success", true); } return ok(result); }