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.granita.contacticloudsync.syncadapter.AccountSettings.java
public AccountSettings(Context context, Account account) { this.context = context; this.account = account; accountManager = AccountManager.get(context); synchronized (AccountSettings.class) { int version = 0; try {//from www. j a v a2s.c o m version = Integer.parseInt(accountManager.getUserData(account, KEY_SETTINGS_VERSION)); } catch (NumberFormatException e) { } Constants.log.info("AccountSettings version: v" + version + ", should be: " + version); if (version < CURRENT_VERSION) { showNotification(Constants.NOTIFICATION_ACCOUNT_SETTINGS_UPDATED, context.getString(R.string.settings_version_update_title), context.getString(R.string.settings_version_update_description)); update(version); } // check whether Android version has changed String lastAndroidVersionInt = accountManager.getUserData(account, KEY_LAST_ANDROID_VERSION); if (lastAndroidVersionInt != null && NumberUtils.toInt(lastAndroidVersionInt) < Build.VERSION.SDK_INT) { // notify user showNotification(Constants.NOTIFICATION_ANDROID_VERSION_UPDATED, context.getString(R.string.settings_android_update_title), context.getString(R.string.settings_android_update_description)); } accountManager.setUserData(account, KEY_LAST_ANDROID_VERSION, String.valueOf(Build.VERSION.SDK_INT)); } }
From source file:com.blackducksoftware.integration.hub.builder.HubScanJobConfigBuilder.java
@Override public ValidationResults<HubScanJobFieldEnum, HubScanJobConfig> buildResults() { final ValidationResults<HubScanJobFieldEnum, HubScanJobConfig> result = assertValid(); final ImmutableList<String> immutableScanTargetPaths = new ImmutableList.Builder<String>() .addAll(scanTargetPaths).build(); result.setConstructedObject(new HubScanJobConfig(projectName, version, phase, distribution, workingDirectory, NumberUtils.toInt(scanMemory), shouldGenerateRiskReport, NumberUtils.toInt(maxWaitTimeForBomUpdate), immutableScanTargetPaths, dryRun)); return result; }
From source file:com.blackducksoftware.integration.hub.builder.HubProxyInfoBuilder.java
@Override public ValidationResults<GlobalFieldKey, HubProxyInfo> buildResults() { final ValidationResults<GlobalFieldKey, HubProxyInfo> result = assertValid(); HubProxyInfo proxyInfo;//from w w w. j ava 2 s .c om final int proxyPort = NumberUtils.toInt(port); if (StringUtils.isNotBlank(password) && StringUtils.isNotBlank(username)) { final HubCredentialsBuilder credBuilder = new HubCredentialsBuilder(); credBuilder.setUsername(username); credBuilder.setPassword(password); credBuilder.setPasswordLength(passwordLength); final ValidationResults<GlobalFieldKey, HubCredentials> credResult = credBuilder.buildResults(); proxyInfo = new HubProxyInfo(host, proxyPort, credResult.getConstructedObject(), ignoredProxyHosts); } else { // password is blank or already encrypted so we just pass in the // values given to us proxyInfo = new HubProxyInfo(host, proxyPort, null, ignoredProxyHosts); } result.setConstructedObject(proxyInfo); return result; }
From source file:com.mirth.connect.connectors.jms.JmsClient.java
public JmsClient(final Connector connector, JmsReceiverProperties connectorProperties, String connectorName) { this.connector = connector; this.connectorProperties = connectorProperties; this.connectorName = connectorName; this.intervalMillis = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getReconnectIntervalMillis(), connector.getChannelId(), connector.getChannel().getName())); if (connectorProperties instanceof SourceConnectorPropertiesInterface) { resourceIds = ((SourceConnectorPropertiesInterface) connectorProperties).getSourceConnectorProperties() .getResourceIds().keySet(); } else if (connectorProperties instanceof DestinationConnectorPropertiesInterface) { resourceIds = ((DestinationConnectorPropertiesInterface) connectorProperties) .getDestinationConnectorProperties().getResourceIds().keySet(); }//from w ww . j a v a 2s.co m }
From source file:com.cognifide.aet.job.common.modifiers.login.LoginModifierConfig.java
public LoginModifierConfig(Map<String, String> params) throws ParametersException { this.loginPage = params.get(LOGIN_PAGE_PARAM); this.login = getParameter(params, LOGIN_PARAM, DEFAULT_LOGIN); this.password = getParameter(params, PASSWORD_PARAM, DEFAULT_PASSWORD); this.loginInputSelector = getParameter(params, LOGIN_INPUT_SELECTOR_PARAM, DEFAULT_LOGIN_INPUT_SELECTOR); this.passwordInputSelector = getParameter(params, PASSWORD_INPUT_SELECTOR_PARAM, DEFAULT_PASSWORD_INPUT_SELECTOR); this.submitButtonSelector = getParameter(params, SUBMIT_BUTTON_SELECTOR_PARAM, DEFAULT_SUBMIT_BUTTON_SELECTOR); this.loginTokenKey = getParameter(params, LOGIN_TOKEN_KEY_PARAM, DEFAULT_LOGIN_TOKEN); this.forceLogin = BooleanUtils.toBoolean(params.get(FORCE_LOGIN)); this.delayBeforeLoginCheckOrReattempt = NumberUtils .toInt(getParameter(params, LOGIN_CHECK_TIMEOUT_PARAM, DEFAULT_CHECK_TIMEOUT_PARAM)); this.retrialNumber = NumberUtils.toInt(getParameter(params, RETRIAL_NUMBER_PARAM, DEFAULT_RETRIAL_NUMBER)); ParametersValidator.checkNotBlank(loginPage, "`login-page` parameter is mandatory"); ParametersValidator.checkRange(delayBeforeLoginCheckOrReattempt, 0, 10000, "Timeout duration should be greater than 0 and " + "less than 10 seconds"); ParametersValidator.checkRange(retrialNumber, 1, Integer.MAX_VALUE, "Retrial number has to be at least 1"); }
From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java
@FXML public void updateVerbalRecentered() { if (logger.isDebugEnabled()) { logger.debug("[UPD V RECENTERED]"); }// ww w .j ava 2s . c o m if (dao == null) { throw new IllegalArgumentException( "dao has not been set; call setRecenteredDAO() before calling this method"); } String score1995_s = txtVerbalScore1995.getText(); if (StringUtils.isNumeric(score1995_s)) { Integer score1995 = NumberUtils.toInt(score1995_s); if (withinRange(score1995)) { if (needsRound(score1995)) { score1995 = round(score1995); txtVerbalScore1995.setText(String.valueOf(score1995)); } resetErrMsgs(); Integer scoreRecentered = dao.lookupRecenteredVerbalScore(score1995); txtVerbalScoreRecentered.setText(String.valueOf(scoreRecentered)); } else { errMsgVerbal1995.setVisible(true); } } else { errMsgVerbal1995.setVisible(true); } }
From source file:com.xpn.xwiki.web.EditForm.java
public int getObjectNumbers(String prefix) { String nb = getRequest().getParameter(prefix + "_nb"); return NumberUtils.toInt(nb); }
From source file:com.moviejukebox.plugin.poster.MovieMeterPosterPlugin.java
@Override public IImage getPosterUrl(String id) { if (!StringUtils.isNumeric(id)) { return Image.UNKNOWN; }//from w w w .jav a2 s.com String posterURL = Movie.UNKNOWN; FilmInfo filmInfo; try { filmInfo = api.getFilm(NumberUtils.toInt(id)); if (filmInfo.getPosters() == null || filmInfo.getPosters().getLarge() == null) { LOG.debug("No MovieMeter Poster URL for movie: {}", id); } else { posterURL = filmInfo.getPosters().getLarge(); } } catch (MovieMeterException ex) { LOG.error("Failed retreiving MovieMeter Poster URL for movie: {}", id); LOG.error(SystemTools.getStackTrace(ex)); } if (StringTools.isValidString(posterURL)) { return new Image(posterURL); } return Image.UNKNOWN; }
From source file:com.lehealth.common.sdk.CCPRestSDK.java
/** * ???/* www. j ava 2s . c om*/ * * @param to * ? ??????????100 * @param templateId * ? ?Id * @param datas * ?? ???{??} * @return */ public JSONObject sendTemplateSMS(String to, String templateId, String[] datas, String domain, String appId, String sid, String token) { JSONObject errorInfo = this.accountValidate(domain, appId, sid, token); if (errorInfo != null) { return errorInfo; } if (StringUtils.isBlank(to) || StringUtils.isBlank(appId) || StringUtils.isBlank(templateId)) { throw new IllegalArgumentException("?:" + (StringUtils.isBlank(to) ? " ?? " : "") + (StringUtils.isBlank(templateId) ? " ?Id " : "") + ""); } String timestamp = DateFormatUtils.format(new Date(), Constant.dateFormat_yyyymmddhhmmss); String acountName = sid; String sig = sid + token + timestamp; String acountType = "Accounts"; String signature = DigestUtils.md5Hex(sig); String url = getBaseUrl(domain).append("/" + acountType + "/").append(acountName) .append("/" + TemplateSMS + "?sig=").append(signature).toString(); String src = acountName + ":" + timestamp; String auth = Base64.encodeBase64String(src.getBytes()); Map<String, String> header = new HashMap<String, String>(); header.put("Accept", "application/json"); header.put("Content-Type", "application/json;charset=utf-8"); header.put("Authorization", auth); JSONObject json = new JSONObject(); json.accumulate("appId", appId); json.accumulate("to", to); json.accumulate("templateId", templateId); if (datas != null) { JSONArray Jarray = new JSONArray(); for (String s : datas) { Jarray.add(s); } json.accumulate("datas", Jarray); } String requestBody = json.toString(); DefaultHttpClient httpclient = null; HttpPost postMethod = null; try { httpclient = new CcopHttpClient().registerSSL(domain, NumberUtils.toInt(SERVER_PORT), "TLS", "https"); postMethod = new HttpPost(url); if (header != null && !header.isEmpty()) { for (Entry<String, String> e : header.entrySet()) { postMethod.setHeader(e.getKey(), e.getValue()); } } postMethod.setConfig(PoolConnectionManager.requestConfig); BasicHttpEntity requestEntity = new BasicHttpEntity(); requestEntity.setContent(new ByteArrayInputStream(requestBody.getBytes("UTF-8"))); requestEntity.setContentLength(requestBody.getBytes("UTF-8").length); postMethod.setEntity(requestEntity); HttpResponse response = httpclient.execute(postMethod); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity, "UTF-8"); EntityUtils.consume(entity); return JSONObject.fromObject(result); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (postMethod != null) { postMethod.releaseConnection(); } if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } return getMyError("999999", ""); }
From source file:com.mirth.connect.donkey.model.channel.PollConnectorProperties.java
@Override public void migrate3_3_0(DonkeyElement element) { DonkeyElement pollingFrequencyElement = element.getChildElement("pollingFrequency"); int pollingFrequency = NumberUtils.toInt(pollingFrequencyElement.getTextContent()); if (pollingFrequency <= 0) { pollingFrequency = 5000;//from ww w . jav a 2 s .com } else if (pollingFrequency >= 86400000) { pollingFrequency = 86399999; } pollingFrequencyElement.setTextContent(String.valueOf(pollingFrequency)); DonkeyElement pollingType = element.getChildElement("pollingType"); boolean isInterval = pollingType.getTextContent().equals("interval"); pollingType.setTextContent(isInterval ? "INTERVAL" : "TIME"); element.addChildElementIfNotExists("pollOnStart", isInterval ? "true" : "false"); element.addChildElementIfNotExists("cronJobs"); DonkeyElement advancedProperties = element.addChildElementIfNotExists("pollConnectorPropertiesAdvanced"); if (advancedProperties != null) { advancedProperties.addChildElementIfNotExists("weekly", "true"); DonkeyElement activeDays = advancedProperties.addChildElementIfNotExists("inactiveDays"); if (activeDays != null) { for (int counter = 0; counter < 8; ++counter) { activeDays.addChildElement("boolean", "false"); } } advancedProperties.addChildElementIfNotExists("dayOfMonth", "1"); advancedProperties.addChildElementIfNotExists("allDay", "true"); advancedProperties.addChildElementIfNotExists("startingHour", "8"); advancedProperties.addChildElementIfNotExists("startingMinute", "0"); advancedProperties.addChildElementIfNotExists("endingHour", "17"); advancedProperties.addChildElementIfNotExists("endingMinute", "0"); } }