List of usage examples for org.apache.commons.lang3.math NumberUtils toInt
public static int toInt(final String str)
Convert a String
to an int
, returning zero
if the conversion fails.
If the string is null
, zero
is returned.
NumberUtils.toInt(null) = 0 NumberUtils.toInt("") = 0 NumberUtils.toInt("1") = 1
From source file:com.blackducksoftware.integration.hub.teamcity.agent.scan.HubBuildProcess.java
private HubServerConfig getHubServerConfig(final IntLogger logger, final CIEnvironmentVariables commonVariables) { final HubServerConfigBuilder configBuilder = new HubServerConfigBuilder(); // read the credentials and proxy info using the existing objects. final String serverUrl = commonVariables.getValue(HubConstantValues.HUB_URL); final String timeout = commonVariables.getValue(HubConstantValues.HUB_CONNECTION_TIMEOUT); final String username = commonVariables.getValue(HubConstantValues.HUB_USERNAME); final String password = commonVariables.getValue(HubConstantValues.HUB_PASSWORD); final String passwordLength = commonVariables.getValue(HubConstantValues.HUB_PASSWORD_LENGTH); final String alwaysTrustServerCertificate = commonVariables .getValue(HubConstantValues.HUB_TRUST_SERVER_CERT); final String proxyHost = commonVariables.getValue(HubConstantValues.HUB_PROXY_HOST); final String proxyPort = commonVariables.getValue(HubConstantValues.HUB_PROXY_PORT); final String ignoredProxyHosts = commonVariables.getValue(HubConstantValues.HUB_NO_PROXY_HOSTS); final String proxyUsername = commonVariables.getValue(HubConstantValues.HUB_PROXY_USER); final String proxyPassword = commonVariables.getValue(HubConstantValues.HUB_PROXY_PASS); final String proxyPasswordLength = commonVariables.getValue(HubConstantValues.HUB_PROXY_PASS_LENGTH); configBuilder.setHubUrl(serverUrl);//from w w w . ja va 2 s. c om configBuilder.setUsername(username); configBuilder.setPassword(password); configBuilder.setPasswordLength(NumberUtils.toInt(passwordLength)); configBuilder.setTimeout(timeout); configBuilder.setAlwaysTrustServerCertificate(Boolean.valueOf(alwaysTrustServerCertificate)); configBuilder.setProxyHost(proxyHost); configBuilder.setProxyPort(proxyPort); configBuilder.setIgnoredProxyHosts(ignoredProxyHosts); configBuilder.setProxyUsername(proxyUsername); configBuilder.setProxyPassword(proxyPassword); configBuilder.setProxyPasswordLength(NumberUtils.toInt(proxyPasswordLength)); try { return configBuilder.build(); } catch (final IllegalStateException e) { logger.error(e.getMessage(), e); } return null; }
From source file:br.com.autonomiccs.cloudTraces.main.GoogleTracesToCloudTracesParser.java
private static GoogleTrace createGoogleTrace(String line) { Matcher matcher = patternMatchGoogleTracesGroups.matcher(line); if (!matcher.matches()) { throw new GoogleTracesToCloudTracesException( String.format("The trace [%s] does not meet the expected pattern.", line)); }// w w w.j ava 2 s . c om GoogleTrace googleTrace = new GoogleTrace(); times.add(NumberUtils.toInt(matcher.group(1))); googleTrace.setTime(NumberUtils.toInt(matcher.group(1))); googleTrace.setJobId(NumberUtils.toInt(matcher.group(2))); googleTrace.setTaskId(NumberUtils.toInt(matcher.group(3))); googleTrace.setJobType(NumberUtils.toInt(matcher.group(4))); String[] normalizedCpuAndMemory = matcher.group(5).split(" "); googleTrace.setNormalizedTaskCores(NumberUtils.toDouble(normalizedCpuAndMemory[0])); googleTrace.setNormalizedTaskMemory(NumberUtils.toDouble(normalizedCpuAndMemory[1])); return googleTrace; }
From source file:com.kegare.caveworld.client.config.GuiVeinsEntry.java
@Override protected void actionPerformed(GuiButton button) { if (button.enabled) { switch (button.id) { case 0:/*from w w w . j a va2 s . com*/ if (editMode) { if (Strings.isNullOrEmpty(blockField.getText()) || NumberUtils.toInt(countField.getText()) <= 0 || NumberUtils.toInt(weightField.getText()) <= 0 || NumberUtils.toInt(rateField.getText()) <= 0) { return; } veinList.selected.setBlock( new BlockEntry(blockField.getText(), NumberUtils.toInt(blockMetaField.getText()))); veinList.selected.setGenBlockCount( NumberUtils.toInt(countField.getText(), veinList.selected.getGenBlockCount())); veinList.selected.setGenWeight( NumberUtils.toInt(weightField.getText(), veinList.selected.getGenWeight())); veinList.selected .setGenRate(NumberUtils.toInt(rateField.getText(), veinList.selected.getGenRate())); veinList.selected.setGenMinHeight( NumberUtils.toInt(minHeightField.getText(), veinList.selected.getGenMinHeight())); veinList.selected.setGenMaxHeight( NumberUtils.toInt(maxHeightField.getText(), veinList.selected.getGenMaxHeight())); veinList.selected.setGenTargetBlock( new BlockEntry(targetField.getText(), NumberUtils.toInt(targetMetaField.getText()))); List<Integer> ids = Lists.newArrayList(); for (String str : Splitter.on(',').trimResults().omitEmptyStrings() .split(biomesField.getText())) { if (NumberUtils.isNumber(str)) { ids.add(Integer.parseInt(str)); } } Collections.sort(ids); veinList.selected.setGenBiomes(Ints.toArray(ids)); hoverCache.remove(veinList.selected); actionPerformed(cancelButton); veinList.scrollToSelected(); } else { boolean flag = CaveworldAPI.getCaveVeins().size() != veinList.veins.size(); CaveworldAPI.clearCaveVeins(); if (flag) { try { FileUtils.forceDelete(new File(Config.veinsCfg.toString())); Config.veinsCfg.load(); } catch (IOException e) { e.printStackTrace(); } } for (ICaveVein vein : veinList.veins) { CaveworldAPI.addCaveVein(vein); } if (Config.veinsCfg.hasChanged()) { Config.veinsCfg.save(); } actionPerformed(cancelButton); } break; case 1: if (editMode) { actionPerformed(cancelButton); } else { editMode = true; initGui(); veinList.scrollToSelected(); blockField.setText( GameData.getBlockRegistry().getNameForObject(veinList.selected.getBlock().getBlock())); blockMetaField.setText(Integer.toString(veinList.selected.getBlock().getMetadata())); countField.setText(Integer.toString(veinList.selected.getGenBlockCount())); weightField.setText(Integer.toString(veinList.selected.getGenWeight())); rateField.setText(Integer.toString(veinList.selected.getGenRate())); minHeightField.setText(Integer.toString(veinList.selected.getGenMinHeight())); maxHeightField.setText(Integer.toString(veinList.selected.getGenMaxHeight())); targetField.setText(GameData.getBlockRegistry() .getNameForObject(veinList.selected.getGenTargetBlock().getBlock())); targetMetaField.setText(Integer.toString(veinList.selected.getGenTargetBlock().getMetadata())); biomesField.setText(Ints.join(", ", veinList.selected.getGenBiomes())); } break; case 2: if (editMode) { editMode = false; initGui(); } else { mc.displayGuiScreen(parentScreen); } break; case 3: mc.displayGuiScreen(new GuiSelectBlock(this)); break; case 4: if (veinList.veins.remove(veinList.selected)) { int i = veinList.contents.indexOf(veinList.selected); veinList.contents.remove(i); veinList.selected = veinList.contents.get(i, veinList.contents.get(--i, null)); } break; case 5: for (Object entry : veinList.veins.toArray()) { veinList.selected = (ICaveVein) entry; actionPerformed(removeButton); } break; case 6: CaveConfigGui.detailInfo = detailInfo.isChecked(); break; case 7: CaveConfigGui.instantFilter = instantFilter.isChecked(); break; } } }
From source file:com.mirth.connect.connectors.jdbc.DatabaseReceiverQuery.java
private void initSelectConnection() throws SQLException { closeSelectConnection();/*from w ww. j a v a2s . c om*/ String channelId = connector.getChannelId(); String channelName = connector.getChannel().getName(); String url = replacer.replaceValues(connectorProperties.getUrl(), channelId, channelName); String username = replacer.replaceValues(connectorProperties.getUsername(), channelId, channelName); String password = replacer.replaceValues(connectorProperties.getPassword(), channelId, channelName); if (customDriver != null) { selectConnection = customDriver.connect(url, username, password); } else { selectConnection = DriverManager.getConnection(url, username, password); } selectConnection.setAutoCommit(true); /* * Before preparing the select statement, we extract the Apache velocity variables from the * statement into selectParams and replace them with ? placeholders. Prior to executing the * select statement, we use selectParams along with a TemplateValueReplacer to determine * what values to set on the prepared statement (see JdbcUtils.getParameters()). */ selectParams.clear(); selectStatement = selectConnection .prepareStatement(JdbcUtils.extractParameters(connectorProperties.getSelect(), selectParams)); if (!connectorProperties.isCacheResults()) { selectStatement.setFetchSize(NumberUtils .toInt(replacer.replaceValues(connectorProperties.getFetchSize(), channelId, channelName))); } }
From source file:com.enation.app.shop.core.action.api.MemberApiAction.java
/** * //w ww.j a va2s.c o m */ public String register() { if (this.validcode(validcode, "memberreg") == 0) { this.showErrorJson("??!"); return this.JSON_MESSAGE; } if (!"agree".equals(license)) { this.showErrorJson("??????!"); return this.JSON_MESSAGE; } Member member = new Member(); HttpServletRequest request = ThreadContextHolder.getHttpRequest(); String registerip = request.getRemoteAddr(); if (StringUtil.isEmpty(username)) { this.showErrorJson("????"); return this.JSON_MESSAGE; } if (username.length() < 4 || username.length() > 20) { this.showErrorJson("??4-20?"); return this.JSON_MESSAGE; } if (username.contains("@")) { this.showErrorJson("????@?"); return this.JSON_MESSAGE; } if (StringUtil.isEmpty(email)) { this.showErrorJson("??"); return this.JSON_MESSAGE; } if (!StringUtil.validEmail(email)) { this.showErrorJson("???"); return this.JSON_MESSAGE; } if (StringUtil.isEmpty(password)) { this.showErrorJson("???"); return this.JSON_MESSAGE; } if (memberManager.checkname(username) > 0) { this.showErrorJson("??????!"); return this.JSON_MESSAGE; } if (memberManager.checkemail(email) > 0) { this.showErrorJson("??!"); return this.JSON_MESSAGE; } member.setMobile(""); member.setUname(username); member.setPassword(password); member.setEmail(email); member.setRegisterip(registerip); if (!StringUtil.isEmpty(friendid)) { Member parentMember = this.memberManager.get(NumberUtils.toInt(friendid)); if (parentMember != null) { member.setParentid(parentMember.getMember_id()); } } else { // ??? ??? String reg_Recomm = request.getParameter("reg_Recomm"); if (!StringUtil.isEmpty(reg_Recomm) && reg_Recomm.trim().equals(email.trim())) { this.showErrorJson("????!"); return this.JSON_MESSAGE; } if (!StringUtil.isEmpty(reg_Recomm) && StringUtil.validEmail(reg_Recomm)) { Member parentMember = this.memberManager.getMemberByEmail(reg_Recomm); if (parentMember == null) { this.showErrorJson("???!"); return this.JSON_MESSAGE; } else { member.setParentid(parentMember.getMember_id()); } } } int result = memberManager.register(member); if (result == 1) { // ? this.memberManager.login(username, password); //String forward = request.getParameter("forward"); String mailurl = "http://mail." + StringUtils.split(member.getEmail(), "@")[1]; /*if (forward != null && !forward.equals("")) { String message = request.getParameter("message"); this.setMsg(message); } else { this.setMsg("?"); }*/ this.json = JsonMessageUtil.getStringJson("mailurl", mailurl); } else { this.showErrorJson("??[" + member.getUname() + "]!"); } return this.JSON_MESSAGE; }
From source file:com.blackducksoftware.integration.hub.bamboo.config.HubConfigController.java
private HubServerConfigBuilder setConfigBuilderFromSerializableConfig(final HubServerConfigSerializable config, final PluginSettings settings) { final HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder(); serverConfigBuilder.setHubUrl(config.getHubUrl()); serverConfigBuilder.setTimeout(config.getTimeout()); serverConfigBuilder.setUsername(config.getUsername()); if (StringUtils.isBlank(config.getPassword())) { serverConfigBuilder.setPassword(null); serverConfigBuilder.setPasswordLength(0); } else if (StringUtils.isNotBlank(config.getPassword()) && !config.isPasswordMasked()) { serverConfigBuilder.setPassword(config.getPassword()); serverConfigBuilder.setPasswordLength(0); } else {//w w w . j a va 2s .c o m serverConfigBuilder.setPassword(getValue(settings, HubConfigKeys.CONFIG_HUB_PASS)); serverConfigBuilder .setPasswordLength(NumberUtils.toInt(getValue(settings, HubConfigKeys.CONFIG_HUB_PASS_LENGTH))); } serverConfigBuilder.setProxyHost(config.getHubProxyHost()); serverConfigBuilder.setProxyPort(config.getHubProxyPort()); serverConfigBuilder.setIgnoredProxyHosts(config.getHubNoProxyHosts()); serverConfigBuilder.setProxyUsername(config.getHubProxyUser()); if (StringUtils.isBlank(config.getHubProxyPassword())) { serverConfigBuilder.setProxyPassword(null); serverConfigBuilder.setProxyPasswordLength(0); } else if (StringUtils.isNotBlank(config.getHubProxyPassword()) && !config.isProxyPasswordMasked()) { // only update the stored password if it is not the masked // password used for display serverConfigBuilder.setProxyPassword(config.getHubProxyPassword()); serverConfigBuilder.setProxyPasswordLength(0); } else { serverConfigBuilder.setProxyPassword(getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS)); serverConfigBuilder.setProxyPasswordLength( NumberUtils.toInt(getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS_LENGTH))); } return serverConfigBuilder; }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.items.MythicDropBuilder.java
private List<String> randomVariableReplace(List<String> list) { List<String> newList = new ArrayList<>(); for (String s : list) { Matcher matcher = PERCENTAGE_PATTERN.matcher(s); while (matcher.find()) { String check = matcher.group(); String replacedCheck = StringUtils.replace(StringUtils.replace(check, "%rand", ""), "%", ""); List<String> split = Splitter.on(DASH_PATTERN).omitEmptyStrings().trimResults() .splitToList(replacedCheck); LOGGER.debug(String.format("%s | %s | %s", s, check, split.toString())); int first = NumberUtils.toInt(split.get(0)); int second = NumberUtils.toInt(split.get(1)); int min = Math.min(first, second); int max = Math.max(first, second); int random = (int) Math.round((Math.random() * (max - min) + min)); newList.add(s.replace(check, String.valueOf(random))); }//from ww w .jav a 2s. co m if (s.contains("%rand")) { continue; } newList.add(s); } return newList; }
From source file:com.blackducksoftware.integration.maven.goal.BuildBOMGoal.java
public int getHubTimeout() { final String deprecatedProperty = getDeprecatedProperty("hub-timeout"); if (StringUtils.isNotBlank(deprecatedProperty)) { return NumberUtils.toInt(deprecatedProperty); }//from w w w. j a v a 2 s .c o m return hubTimeout; }
From source file:com.mirth.connect.client.ui.panels.connectors.QueueSettingsPanel.java
private void queueNeverRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queueNeverRadioActionPerformed regenerateTemplateCheckbox.setEnabled(false); rotateCheckbox.setEnabled(false);/* w ww .j a v a 2 s .c om*/ if (NumberUtils.toInt(retryCountField.getText()) == 0) { retryIntervalField.setEnabled(false); retryIntervalLabel.setEnabled(false); } else { retryIntervalField.setEnabled(true); retryIntervalLabel.setEnabled(true); } retryCountLabel.setEnabled(true); retryCountField.setEnabled(true); channelSetup.saveDestinationPanel(); MessageStorageMode messageStorageMode = channelSetup.getMessageStorageMode(); channelSetup.updateQueueWarning(messageStorageMode); updateQueueWarning(messageStorageMode); }
From source file:com.kegare.caveworld.plugin.mceconomy.GuiShopEntry.java
@Override public void handleMouseInput() { super.handleMouseInput(); if (damageField.isFocused()) { int i = Mouse.getDWheel(); if (i < 0) { damageField.setText(Integer.toString(Math.max(NumberUtils.toInt(damageField.getText()) - 1, 0))); } else if (i > 0) { damageField.setText(/* w w w .java2s . c o m*/ Integer.toString(Math.min(NumberUtils.toInt(damageField.getText()) + 1, Short.MAX_VALUE))); } } else if (stackField.isFocused()) { int i = Mouse.getDWheel(); if (i < 0) { stackField.setText(Integer.toString(Math.max(NumberUtils.toInt(stackField.getText()) - 1, 0))); } else if (i > 0) { stackField.setText(Integer.toString(Math.min(NumberUtils.toInt(stackField.getText()) + 1, 64))); } } else if (costField.isFocused()) { int i = Mouse.getDWheel(); if (i < 0) { costField.setText(Integer.toString(Math.max(NumberUtils.toInt(costField.getText()) - 1, 0))); } else if (i > 0) { costField.setText(Integer.toString( Math.min(NumberUtils.toInt(costField.getText()) + 1, MCEconomyPlugin.Player_MP_MAX))); } } }