本文整理汇总了Java中org.apache.commons.lang.math.NumberUtils类的典型用法代码示例。如果您正苦于以下问题:Java NumberUtils类的具体用法?Java NumberUtils怎么用?Java NumberUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberUtils类属于org.apache.commons.lang.math包,在下文中一共展示了NumberUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstruction
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Ajax call, will add one more input line for new survey item instruction.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward newInstruction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
int count = NumberUtils.stringToInt(request.getParameter(AuthoringAction.INSTRUCTION_ITEM_COUNT), 0);
List instructionList = new ArrayList(++count);
for (int idx = 0; idx < count; idx++) {
String item = request.getParameter(AuthoringAction.INSTRUCTION_ITEM_DESC_PREFIX + idx);
if (item == null) {
instructionList.add("");
} else {
instructionList.add(item);
}
}
request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST, instructionList);
return mapping.findForward(SurveyConstants.SUCCESS);
}
示例2: organization
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
@Override
public int organization(String[] organizationIds, int id) {
int result = 0;
// 删除旧记录
UpmsUserOrganizationExample upmsUserOrganizationExample = new UpmsUserOrganizationExample();
upmsUserOrganizationExample.createCriteria()
.andUserIdEqualTo(id);
upmsUserOrganizationMapper.deleteByExample(upmsUserOrganizationExample);
// 增加新记录
if (null != organizationIds) {
for (String organizationId : organizationIds) {
if (StringUtils.isBlank(organizationId)) {
continue;
}
UpmsUserOrganization upmsUserOrganization = new UpmsUserOrganization();
upmsUserOrganization.setUserId(id);
upmsUserOrganization.setOrganizationId(NumberUtils.toInt(organizationId));
result = upmsUserOrganizationMapper.insertSelective(upmsUserOrganization);
}
}
return result;
}
示例3: generateToken
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
private JWTToken generateToken(Map<String, Object> claims, Date notBefore) {
byte[] secret = DEFAULT_JWT_SECRET;
if (!ArrayUtils.isEmpty(this.jwtSecret)) {
secret = this.jwtSecret;
}
int sessionExpireMinutes = DEFAULT_JWT_SESSION_TIMEOUT_MINUTE;
if (NumberUtils.isDigits(this.jwtTimeOut)) {
sessionExpireMinutes = Integer.parseInt(this.jwtTimeOut);
}
LocalDateTime expiration = LocalDateTime.now().plusMinutes(sessionExpireMinutes);
return new JWTToken(Jwts.builder()
.setClaims(claims)
.setNotBefore(notBefore)
.setExpiration(Date.from(expiration.atZone(ZoneId.systemDefault()).toInstant()))
.signWith(SignatureAlgorithm.HS512, secret)
.compact());
}
示例4: getPermValue
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Get the maximum value of a numerical perm setting
* @param player - the player to check
* @param perm - the start of the perm, e.g., bskyblock.maxhomes
* @param permValue - the default value - the result may be higher or lower than this
* @return
*/
public static int getPermValue(Player player, String perm, int permValue) {
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(perm + ".")) {
// Get the max value should there be more than one
if (perms.getPermission().contains(perm + ".*")) {
return permValue;
} else {
String[] spl = perms.getPermission().split(perm + ".");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
permValue = Math.max(permValue, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (permValue < 1) {
permValue = 1;
}
}
return permValue;
}
示例5: executeNumberScript
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* 执行返回数字类型的脚本
* @param script
* @return
*/
private DetectResult.Metric executeNumberScript(Script script,int step) {
if (script != null && script.isValid()){
try {
String cmd = "";
if (script.getScriptType() == ScriptType.SHELL){
cmd = "sh " + script.getPath();
}
if (script.getScriptType() == ScriptType.PYTHON){
cmd = "python " + script.getPath();
}
CommandUtilForUnix.ExecuteResult executeResult = CommandUtilForUnix.execWithReadTimeLimit(cmd,false,5);
String value = executeResult.msg.trim();
if (NumberUtils.isNumber(value)){
return new DetectResult.Metric(script.getMetric(),value, CounterType.valueOf(script.getCounterType()), script.getTags(),step);
}
} catch (Exception e) {
log.error("脚本执行异常",e);
}
}
return null;
}
示例6: getGlobalVariables
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
private Collection<? extends FalconReportObject> getGlobalVariables() throws SQLException, ClassNotFoundException {
Set<FalconReportObject> reportObjectSet = new HashSet<>();
String sql = "SHOW /*!50001 GLOBAL */ VARIABLES";
PreparedStatement pstmt = connection.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
String metric = rs.getString(1);
String value = rs.getString(2);
if (NumberUtils.isNumber(value)){
//收集值为数字的结果
FalconReportObject falconReportObject = new FalconReportObject();
MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
falconReportObject.setCounterType(CounterType.GAUGE);
//时间戳会统一上报
// falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
falconReportObject.setMetric(metric);
falconReportObject.setValue(value);
falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
reportObjectSet.add(falconReportObject);
}
}
rs.close();
pstmt.close();
return reportObjectSet;
}
示例7: getGlobalStatus
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
private Collection<? extends FalconReportObject> getGlobalStatus() throws SQLException, ClassNotFoundException {
Set<FalconReportObject> reportObjectSet = new HashSet<>();
String sql = "SHOW /*!50001 GLOBAL */ STATUS";
PreparedStatement pstmt = connection.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
String value = rs.getString(2);
if (NumberUtils.isNumber(value)){
String metric = rs.getString(1);
FalconReportObject falconReportObject = new FalconReportObject();
MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
falconReportObject.setCounterType(CounterType.GAUGE);
//时间戳会统一上报
// falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
falconReportObject.setMetric(metric);
falconReportObject.setValue(value);
falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
reportObjectSet.add(falconReportObject);
}
}
rs.close();
pstmt.close();
return reportObjectSet;
}
示例8: role
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
@Override
public int role(String[] roleIds, int id) {
int result = 0;
// 删除旧记录
UpmsUserRoleExample upmsUserRoleExample = new UpmsUserRoleExample();
upmsUserRoleExample.createCriteria()
.andUserIdEqualTo(id);
upmsUserRoleMapper.deleteByExample(upmsUserRoleExample);
// 增加新记录
if (null != roleIds) {
for (String roleId : roleIds) {
if (StringUtils.isBlank(roleId)) {
continue;
}
UpmsUserRole upmsUserRole = new UpmsUserRole();
upmsUserRole.setUserId(id);
upmsUserRole.setRoleId(NumberUtils.toInt(roleId));
result = upmsUserRoleMapper.insertSelective(upmsUserRole);
}
}
return result;
}
示例9: editItemInit
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Display edit page for existed survey item.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
QuestionForm itemForm = (QuestionForm) form;
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
int itemIdx = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ITEM_INDEX), -1);
SurveyQuestion item = null;
if (itemIdx != -1) {
SortedSet<SurveyQuestion> surveyList = getSurveyItemList(sessionMap);
List<SurveyQuestion> rList = new ArrayList<SurveyQuestion>(surveyList);
item = rList.get(itemIdx);
if (item != null) {
populateItemToForm(itemIdx, item, itemForm, request);
}
}
if (itemForm.getItemType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) {
return mapping.findForward(SurveyConstants.FORWARD_OPEN_QUESTION);
} else {
return mapping.findForward(SurveyConstants.FORWARD_CHOICE_QUESTION);
}
}
示例10: removeInstruction
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Ajax call, remove the given line of instruction of survey item.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward removeInstruction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
int count = NumberUtils.stringToInt(request.getParameter(AuthoringAction.INSTRUCTION_ITEM_COUNT), 0);
int removeIdx = NumberUtils.stringToInt(request.getParameter("removeIdx"), -1);
List instructionList = new ArrayList(count - 1);
for (int idx = 0; idx < count; idx++) {
String item = request.getParameter(AuthoringAction.INSTRUCTION_ITEM_DESC_PREFIX + idx);
if (idx == removeIdx) {
continue;
}
if (item == null) {
instructionList.add("");
} else {
instructionList.add(item);
}
}
request.setAttribute(SurveyConstants.ATTR_INSTRUCTION_LIST, instructionList);
return mapping.findForward(SurveyConstants.SUCCESS);
}
示例11: getUnitsFromRequest
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Get units from <code>HttpRequest</code>
*
* @param request
*/
private TreeSet<AssessmentUnit> getUnitsFromRequest(HttpServletRequest request, boolean isForSaving) {
Map<String, String> paramMap = splitRequestParameter(request, AssessmentConstants.ATTR_UNIT_LIST);
int count = NumberUtils.toInt(paramMap.get(AssessmentConstants.ATTR_UNIT_COUNT));
TreeSet<AssessmentUnit> unitList = new TreeSet<AssessmentUnit>(new SequencableComparator());
for (int i = 0; i < count; i++) {
String unitStr = paramMap.get(AssessmentConstants.ATTR_UNIT_UNIT_PREFIX + i);
if (StringUtils.isBlank(unitStr) && isForSaving) {
continue;
}
AssessmentUnit unit = new AssessmentUnit();
String sequenceId = paramMap.get(AssessmentConstants.ATTR_UNIT_SEQUENCE_ID_PREFIX + i);
unit.setSequenceId(NumberUtils.toInt(sequenceId));
unit.setUnit(unitStr);
float multiplier = Float.valueOf(paramMap.get(AssessmentConstants.ATTR_UNIT_MULTIPLIER_PREFIX + i));
unit.setMultiplier(multiplier);
unitList.add(unit);
}
return unitList;
}
示例12: preview
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Preview uploaded entryId.
*/
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws JSONException, IOException {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, KalturaConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
.getAttribute(sessionMapID);
int itemIdx = NumberUtils.stringToInt(request.getParameter(KalturaConstants.PARAM_ITEM_INDEX), -1);
if (itemIdx != -1) {
SortedSet<KalturaItem> itemList = getItemList(sessionMap);
List<KalturaItem> rList = new ArrayList<KalturaItem>(itemList);
KalturaItem item = rList.get(itemIdx);
request.setAttribute(KalturaConstants.ATTR_ITEM, item);
}
return mapping.findForward(KalturaConstants.PREVIEW);
}
示例13: removeItem
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Remove resource item from HttpSession list and update page display. As
* authoring rule, all persist only happen when user submit whole page. So
* this remove is just impact HttpSession values.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward removeItem(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, ResourceConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
int itemIdx = NumberUtils.stringToInt(request.getParameter(ResourceConstants.PARAM_ITEM_INDEX), -1);
if (itemIdx != -1) {
SortedSet<ResourceItem> resourceList = getResourceItemList(sessionMap);
List<ResourceItem> rList = new ArrayList<ResourceItem>(resourceList);
ResourceItem item = rList.remove(itemIdx);
resourceList.clear();
resourceList.addAll(rList);
// add to delList
List delList = getDeletedResourceItemList(sessionMap);
delList.add(item);
}
request.setAttribute(ResourceConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return mapping.findForward(ResourceConstants.SUCCESS);
}
示例14: getResourceItem
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Return resoruce item according to ToolAccessMode.
*
* @param request
* @param sessionMap
* @param mode
* @return
*/
private ResourceItem getResourceItem(HttpServletRequest request, SessionMap<String, Object> sessionMap,
String mode) {
ResourceItem item = null;
if (ResourceConstants.MODE_AUTHOR_SESSION.equals(mode)) {
int itemIdx = NumberUtils.stringToInt(request.getParameter(ResourceConstants.PARAM_ITEM_INDEX), 0);
// authoring: does not save item yet, so only has ItemList from session and identity by Index
List<ResourceItem> resourceList = new ArrayList<ResourceItem>(getResourceItemList(sessionMap));
item = resourceList.get(itemIdx);
} else {
Long itemUid = NumberUtils.createLong(request.getParameter(ResourceConstants.PARAM_RESOURCE_ITEM_UID));
// get back the resource and item list and display them on page
IResourceService service = getResourceService();
item = service.getResourceItemByUid(itemUid);
}
return item;
}
示例15: editItemInit
import org.apache.commons.lang.math.NumberUtils; //导入依赖的package包/类
/**
* Display edit page for existed commonCartridge item.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
private ActionForward editItemInit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(sessionMapID);
int itemIdx = NumberUtils.stringToInt(request.getParameter(CommonCartridgeConstants.PARAM_ITEM_INDEX), -1);
CommonCartridgeItem item = null;
if (itemIdx != -1) {
SortedSet<CommonCartridgeItem> commonCartridgeList = getCommonCartridgeItemList(sessionMap);
List<CommonCartridgeItem> rList = new ArrayList<CommonCartridgeItem>(commonCartridgeList);
item = rList.get(itemIdx);
if (item != null) {
populateItemToForm(itemIdx, item, (CommonCartridgeItemForm) form, request);
}
}
return findForward(item == null ? -1 : item.getType(), mapping);
}