本文整理汇总了Java中org.apache.commons.lang3.math.NumberUtils.toInt方法的典型用法代码示例。如果您正苦于以下问题:Java NumberUtils.toInt方法的具体用法?Java NumberUtils.toInt怎么用?Java NumberUtils.toInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.math.NumberUtils
的用法示例。
在下文中一共展示了NumberUtils.toInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
@Override
public Object call(Element element, List<SyntaxNode> params) {
Preconditions.checkArgument(params.size() > 0, getName() + " at last has one parameter");
Object calc = params.get(0).calc(element);
if (calc instanceof Integer) {
return calc;
}
if (calc == null) {
return null;
}
if (params.size() > 1) {
Object defaultValue = params.get(1).calc(element);
Preconditions.checkArgument(defaultValue != null && defaultValue instanceof Integer,
getName() + " parameter 2 must to be a integer now is:" + defaultValue);
return NumberUtils.toInt(calc.toString(), (Integer) defaultValue);
}
return NumberUtils.toInt(calc.toString());
}
示例2: parseToken
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
@Override
public SyntaxNode parseToken(final String tokenStr) {
return new SyntaxNode() {
@Override
public Object calc(Element element) {
if (StringUtils.contains(tokenStr, ".")) {
return NumberUtils.toDouble(tokenStr);
} else {
return NumberUtils.toInt(tokenStr);
}
}
@Override
public Class judeResultType() {
return Double.class;
}
};
}
示例3: updateBrowserSize
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private void updateBrowserSize() {
int width = NumberUtils.toInt(deviceWidth.getText(), -1);
int height = NumberUtils.toInt(deviceHeight.getText(), -1);
width = zoomFactor.swt(width, dpiFactorX);
height = zoomFactor.swt(height, dpiFactorY);
browserGD.horizontalAlignment = width < 0 ? GridData.FILL : GridData.CENTER;
browserGD.verticalAlignment = height < 0 ? GridData.FILL : GridData.CENTER;
browserScroll.setMinWidth(browserGD.widthHint = browserGD.minimumWidth = width);
browserScroll.setMinHeight(browserGD.heightHint = browserGD.minimumHeight = height);
c8oBrowser.getParent().layout();
C8oBrowser.run(() -> {
browser.executeJavaScript("try {_c8o_remove_all_overlay()} catch(e){}");
browser.setZoomLevel(zoomFactor.zoomLevel());
});
}
示例4: createImage
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private void createImage(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
/*
* 得到参数高,宽,都为数字时,则使用设置高宽,否则使用默认值
*/
String width = request.getParameter("width");
String height = request.getParameter("height");
if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
w = NumberUtils.toInt(width);
h = NumberUtils.toInt(height);
}
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
/*
* 生成背景
*/
createBackground(g);
/*
* 生成字符
*/
String s = createCharacter(g);
request.getSession().setAttribute(VALIDATE_CODE, s);
g.dispose();
OutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
out.close();
}
示例5: DroneAIWait
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private DroneAIWait(ProgWidgetString widget) {
String time = widget.string;
int multiplier = 1;
if (time.endsWith("s") || time.endsWith("S")) {
multiplier = 20;
time = time.substring(0, time.length() - 1);
} else if (time.endsWith("m") || time.endsWith("M")) {
multiplier = 1200;
time = time.substring(0, time.length() - 1);
}
maxTicks = NumberUtils.toInt(time) * multiplier;
}
示例6: correctResponses
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public static void correctResponses(Operation operation) {
int okCode = Status.OK.getStatusCode();
String strOkCode = String.valueOf(okCode);
Response okResponse = null;
for (Entry<String, Response> responseEntry : operation.getResponses().entrySet()) {
Response response = responseEntry.getValue();
if (StringUtils.isEmpty(response.getDescription())) {
response.setDescription("response of " + responseEntry.getKey());
}
if (operation.getResponses().get(strOkCode) != null) {
continue;
}
int statusCode = NumberUtils.toInt(responseEntry.getKey());
if ("default".equals(responseEntry.getKey())) {
statusCode = okCode;
}
if (Family.SUCCESSFUL.equals(Family.familyOf(statusCode))) {
okResponse = response;
}
}
if (okResponse != null) {
operation.addResponse(strOkCode, okResponse);
}
}
示例7: createImage
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
/*
* 得到参数高,宽,都为数字时,则使用设置高宽,否则使用默认值
*/
String width = request.getParameter("width");
String height = request.getParameter("height");
if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
w = NumberUtils.toInt(width);
h = NumberUtils.toInt(height);
}
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
/*
* 生成背景
*/
createBackground(g);
/*
* 生成字符
*/
String s = createCharacter(g);
request.getSession().setAttribute(VALIDATE_CODE, s);
g.dispose();
OutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
out.close();
}
示例8: extractInboundValue
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
String extractInboundValue(final RuleMatchingTypeEnum matchingType, final String fieldName, final Request req) {
switch (matchingType) {
case REQUEST_HEADER:
return req.headers(fieldName);
case REQUEST_PARAM:
return req.queryParams(fieldName);
case REQUEST_BODY:
return req.body();
case PATH_VARIABLE:
return req.params(fieldName);
case PATH_VARIABLE_WILD:
final int argPosition = NumberUtils.toInt(fieldName, -1);
if (argPosition == -1
|| req.splat().length < argPosition) {
throw new IllegalArgumentException("Unable to perform wildcard matching on the mocked endpoint '" + req.pathInfo() + "'. Path variable arg count does not align.");
}
return req.splat()[(argPosition - 1)];
case REQUEST_BODY_JSON_ANY:
final Map<String, ?> json = GeneralUtils.deserialiseJSON(req.body());
return (json != null)?(String)json.get(fieldName):null;
default:
throw new IllegalArgumentException("Unsupported Rule Matching Type : " + matchingType);
}
}
示例9: config
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private void config(Properties properties) {
// 事件循环是单线程的,所以设计上来说,不会有并发问题
int newThreadNumber = NumberUtils.toInt(properties.getProperty(String.format(VSCrawlerConstant.VSCRAWLER_THREAD_NUMBER, vsCrawlerContext.getCrawlerName())), -1);
if (newThreadNumber < 0) {
return;
}
if (newThreadNumber != threadNumber) {
log.info("爬虫线程数目变更,由:{} 变化为:{}", threadNumber, newThreadNumber);
threadPool.setCorePoolSize(newThreadNumber);
threadPool.setMaximumPoolSize(newThreadNumber);
threadNumber = newThreadNumber;
}
}
示例10: getEventPoolMinIdlePerEvent
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public int getEventPoolMinIdlePerEvent() {
return NumberUtils.toInt(
featureMap.get(KEY_EVENT_POOL_MIN_IDLE_PER_EVENT),
DEFAULT_VAL_EVENT_POOL_MIN_IDLE_PER_EVENT
);
}
示例11: getMaxTotal
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public static int getMaxTotal() {
return NumberUtils.toInt(prop.getProperty(Constants.DB_MAX_TOTAL_FIELD), Constants.DEFAULT_MAX_TOTAL_VALUE);
}
示例12: getMaxIdle
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public static int getMaxIdle() {
return NumberUtils.toInt(prop.getProperty(Constants.DB_MAX_IDLE_FIELD), Constants.DEFAULT_MAX_IDLE_VALUE);
}
示例13: getMinIdle
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public static int getMinIdle() {
return NumberUtils.toInt(prop.getProperty(Constants.DB_MIN_IDLE_FIELD), Constants.DEFAULT_MIN_IDLE_VALUE);
}
示例14: toInt
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
* 将10进制的String安全的转化为int,当str为空或非数字字符串时,返回0
*/
public static int toInt(String str) {
return NumberUtils.toInt(str, 0);
}
示例15: getEventPoolMaxTotalPerEvent
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public int getEventPoolMaxTotalPerEvent() {
return NumberUtils.toInt(
featureMap.get(KEY_EVENT_POOL_MAX_TOTAL_PER_EVENT),
DEFAULT_VAL_EVENT_POOL_MAX_TOTAL_PER_EVENT
);
}