Java Code Examples for org.apache.commons.lang3.math.NumberUtils.toInt()

The following are Jave code examples for showing how to use toInt() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sipsoup   File: ToIntFunction.java   View Source Code Vote up 6 votes
@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());
}
 
Example 2
Project: sipsoup   File: NumberHandler.java   View Source Code Vote up 6 votes
@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;
        }
    };
}
 
Example 3
Project: convertigo-eclipse   File: ApplicationComponentEditor.java   View Source Code Vote up 6 votes
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());
	});
}
 
Example 4
Project: easyweb   File: ValidateCodeServlet.java   View Source Code Vote up 5 votes
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();

}
 
Example 5
Project: pnc-repressurized   File: ProgWidgetWait.java   View Source Code Vote up 5 votes
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;
}
 
Example 6
Project: incubator-servicecomb-java-chassis   File: SwaggerUtils.java   View Source Code Vote up 5 votes
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);
  }
}
 
Example 7
Project: framework   File: ValidateCodeServlet.java   View Source Code Vote up 5 votes
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();

	}
 
Example 8
Project: smockin   File: RuleEngineImpl.java   View Source Code Vote up 5 votes
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);
        }

    }
 
Example 9
Project: vscrawler   File: VSCrawler.java   View Source Code Vote up 5 votes
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;
    }
}
 
Example 10
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 4 votes
public int getEventPoolMinIdlePerEvent() {
    return NumberUtils.toInt(
            featureMap.get(KEY_EVENT_POOL_MIN_IDLE_PER_EVENT),
            DEFAULT_VAL_EVENT_POOL_MIN_IDLE_PER_EVENT
    );
}
 
Example 11
Project: tauren   File: ConfigFileReader.java   View Source Code Vote up 4 votes
public static int getMaxTotal() {
    return NumberUtils.toInt(prop.getProperty(Constants.DB_MAX_TOTAL_FIELD), Constants.DEFAULT_MAX_TOTAL_VALUE);
}
 
Example 12
Project: tauren   File: ConfigFileReader.java   View Source Code Vote up 4 votes
public static int getMaxIdle() {
    return NumberUtils.toInt(prop.getProperty(Constants.DB_MAX_IDLE_FIELD), Constants.DEFAULT_MAX_IDLE_VALUE);
}
 
Example 13
Project: tauren   File: ConfigFileReader.java   View Source Code Vote up 4 votes
public static int getMinIdle() {
    return NumberUtils.toInt(prop.getProperty(Constants.DB_MIN_IDLE_FIELD), Constants.DEFAULT_MIN_IDLE_VALUE);
}
 
Example 14
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
/**
 * 将10进制的String安全的转化为int,当str为空或非数字字符串时,返回0
 */
public static int toInt(String str) {
	return NumberUtils.toInt(str, 0);
}
 
Example 15
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 4 votes
public int getEventPoolMaxTotalPerEvent() {
    return NumberUtils.toInt(
            featureMap.get(KEY_EVENT_POOL_MAX_TOTAL_PER_EVENT),
            DEFAULT_VAL_EVENT_POOL_MAX_TOTAL_PER_EVENT
    );
}
 
Example 16
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 4 votes
public int getEventPoolMaxTotal() {
    return NumberUtils.toInt(
            featureMap.get(KEY_EVENT_POOL_MAX_TOTAL),
            getEventPoolMaxTotalPerEvent() * Event.Type.values().length
    );
}
 
Example 17
Project: vscrawler   File: DefaultUserResource.java   View Source Code Vote up 4 votes
@Override
public void configChange(VSCrawlerContext vsCrawlerContext, Properties newProperties) {
    String property = newProperties.getProperty(String.format(VSCrawlerConstant.USER_RESOURCE_USERINFO, vsCrawlerContext.getCrawlerName()));
    hasConfig = property != null;
    if (property == null) {
        crawlerThreadNumber = NumberUtils
                .toInt(newProperties.getProperty(String.format(VSCrawlerConstant.VSCRAWLER_THREAD_NUMBER, vsCrawlerContext.getCrawlerName())));
        return;
    }

    if (property.equals(userAccountString)) {
        return;
    }

    // load new user account
    List<String> allUser = userSplitter.splitToList(property);
    int newUserNum = 0;
    for (String userStr : allUser) {
        User user = new User();
        List<String> strings = userItemSplitter.splitToList(userStr);
        if (strings.size() < 2) {
            log.warn("can log load user info from str:{}", userStr);
            continue;
        }
        user.setUserID(strings.get(0));
        user.setPassword(strings.get(1));
        if (strings.size() >= 3) {
            String status = strings.get(2);
            if (StringUtils.equalsIgnoreCase(status, "false")) {
                vsCrawlerContext.getAutoEventRegistry().findEventDeclaring(UserStateChangeEvent.class)
                        .userStatusChange(vsCrawlerContext, user, UserStatus.UNKNOWN, UserStatus.FORBID);
                continue;
            }
        }

        user.setUserStatus(UserStatus.INIT);
        userCache.add(user);
        newUserNum++;
    }
    log.info("load {} new user data", newUserNum);

}
 
Example 18
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 2 votes
/**
 * 获取服务器端口
 *
 * @return 服务器端口
 */
public int getServerPort() {
    return NumberUtils.toInt(featureMap.get(KEY_SERVER_PORT), 0);
}
 
Example 19
Project: InComb   File: RssItem.java   View Source Code Vote up 0 votes
public void setImageWidth(final String imageWidth) { this.imageWidth = NumberUtils.toInt(imageWidth); 	} 
Example 20
Project: InComb   File: RssItem.java   View Source Code Vote up 0 votes
public void setImageHeight(final String imageHeight) { this.imageHeight = NumberUtils.toInt(imageHeight); }