本文整理匯總了Java中org.apache.commons.lang.math.NumberUtils.toLong方法的典型用法代碼示例。如果您正苦於以下問題:Java NumberUtils.toLong方法的具體用法?Java NumberUtils.toLong怎麽用?Java NumberUtils.toLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.math.NumberUtils
的用法示例。
在下文中一共展示了NumberUtils.toLong方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAnswersFromRequest
import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
* Get answer options from <code>HttpRequest</code>
*
* @param request
* @param isForSaving
* whether the blank options will be preserved or not
*
*/
private TreeSet<ScratchieAnswer> getAnswersFromRequest(HttpServletRequest request, boolean isForSaving) {
Map<String, String> paramMap = splitRequestParameter(request, ScratchieConstants.ATTR_ANSWER_LIST);
Integer correctAnswerIndex = (paramMap.get(ScratchieConstants.ATTR_ANSWER_CORRECT) == null) ? null
: NumberUtils.toInt(paramMap.get(ScratchieConstants.ATTR_ANSWER_CORRECT));
int count = NumberUtils.toInt(paramMap.get(ScratchieConstants.ATTR_ANSWER_COUNT));
TreeSet<ScratchieAnswer> answerList = new TreeSet<ScratchieAnswer>(new ScratchieAnswerComparator());
for (int i = 0; i < count; i++) {
String answerDescription = paramMap.get(ScratchieConstants.ATTR_ANSWER_DESCRIPTION_PREFIX + i);
if ((answerDescription == null) && isForSaving) {
continue;
}
ScratchieAnswer answer = new ScratchieAnswer();
String uidStr = paramMap.get(ScratchieConstants.ATTR_ANSWER_UID_PREFIX + i);
if (uidStr != null) {
Long uid = NumberUtils.toLong(uidStr);
answer.setUid(uid);
}
String orderIdStr = paramMap.get(ScratchieConstants.ATTR_ANSWER_ORDER_ID_PREFIX + i);
Integer orderId = NumberUtils.toInt(orderIdStr);
answer.setOrderId(orderId);
answer.setDescription(answerDescription);
if ((correctAnswerIndex != null) && correctAnswerIndex.equals(orderId)) {
answer.setCorrect(true);
}
answerList.add(answer);
}
return answerList;
}
示例2: getSplits
import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static InputSplit[] getSplits(final JobConf conf, final int numSplits, int dummy) {
final Path[] tablePaths = FileInputFormat.getInputPaths(conf);
long splitSize = NumberUtils.toLong(conf.get(MonarchUtils.SPLIT_SIZE_KEY), DEFAULT_SPLIT_SIZE);
final String regionName = conf.get(MonarchUtils.REGION) + MonarchUtils.META_TABLE_SFX;
MPredicateHolder ph = new MPredicateHolder(-1, BasicTypes.STRING,
CompareOp.REGEX, ".*"+MonarchUtils.KEY_BLOCKS_SFX);
MonarchGetAllFunction func = new MonarchGetAllFunction();
final AmpoolClient aClient = MonarchUtils.getConnectionFromConf(conf);
Execution exec = FunctionService.onServer(((GemFireCacheImpl)(aClient.getGeodeCache())).getDefaultPool())
.withArgs(new Object[]{regionName, ph});
ResultCollector rc = exec.execute(func);
/** TODO: refactor below code.. change below required in case the function is changed to return in some way **/
List<String[]> output = (List<String[]>)((List) rc.getResult()).get(0);
if (output.isEmpty()) {
logger.error("No entries found in region= {} with key_prefix= %-{}",
regionName, MonarchUtils.KEY_BLOCKS_SFX);
return new MonarchSplit[0];
}
List<MonarchSplit> list = new ArrayList<>(output.size());
String prefix;
long numberOfBlocks;
for (final String[] arr : output) {
prefix = arr[0].substring(0, arr[0].length() - 6);
numberOfBlocks = Long.valueOf(arr[1]);
if (numberOfBlocks > splitSize) {
Collections.addAll(list, MonarchSplit.getInputSplits(tablePaths[0], prefix, splitSize, numberOfBlocks));
} else {
list.add(new MonarchSplit(tablePaths[0], 0, numberOfBlocks, null, prefix));
}
}
return list.toArray(new MonarchSplit[list.size()]);
}
示例3: doFilter
import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
final HttpServletRequest request = (HttpServletRequest) req;
final HttpServletResponse response = (HttpServletResponse) res;
boolean isCSPReportRequest = request.getRequestURI().startsWith("/reports/cspv");
if ("POST".equals(request.getMethod()) && !isCSPReportRequest) {
String csrfToken = request.getParameter("_csrf");
String csrfInCookie = HttpUtils.getStateParam(CSRF_COOKIE, request);
Long time = NumberUtils.toLong(request.getParameter("_time"), 0);
String timekey = request.getParameter("_timekey");
if (timekey != null) {
Long timeInSession = (Long) request.getSession().getAttribute(timekey);
request.getSession().setAttribute(timekey, System.currentTimeMillis());
if (!time.equals(timeInSession)) {
logger.warn("Time token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL());
// response.sendError(403, "Time token mismatch.");
response.sendRedirect(request.getRequestURI());
return;
}
}
if (csrfToken == null) {
csrfToken = request.getHeader("X-CSRF-TOKEN");
if (csrfToken == null) {
csrfToken = request.getHeader("X-XSRF-TOKEN");
}
}
if (csrfToken == null || StringUtils.isBlank(csrfInCookie) || !csrfToken.equals(csrfInCookie)) {
logger.warn("CSRF token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL());
response.sendError(403, "CSRF token mismatch.");
return;
}
}
chain.doFilter(request, response);
}