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.autonomy.nonaci.indexing.impl.AbstractExportCommand.java
public int getMaxId() { return NumberUtils.toInt(get(PARAM_MAX_ID)); }
From source file:com.blackducksoftware.integration.jira.task.PluginConfigurationDetails.java
public HubServerConfigBuilder createHubServerConfigBuilder() { final HubServerConfigBuilder hubConfigBuilder = new HubServerConfigBuilder(); hubConfigBuilder.setHubUrl(hubUrl);//from ww w. j a v a2s . com hubConfigBuilder.setUsername(hubUsername); hubConfigBuilder.setPassword(hubPasswordEncrypted); hubConfigBuilder.setPasswordLength(NumberUtils.toInt(hubPasswordLength)); hubConfigBuilder.setTimeout(hubTimeoutString); hubConfigBuilder.setProxyHost(hubProxyHost); hubConfigBuilder.setProxyPort(hubProxyPort); hubConfigBuilder.setIgnoredProxyHosts(hubProxyNoHost); hubConfigBuilder.setProxyUsername(hubProxyUser); hubConfigBuilder.setProxyPassword(hubProxyPassEncrypted); hubConfigBuilder.setProxyPasswordLength(NumberUtils.toInt(hubProxyPassLength)); return hubConfigBuilder; }
From source file:com.mirth.connect.connectors.ws.WebServiceReceiver.java
@Override public void onStart() throws ConnectorTaskException { String channelId = getChannelId(); String channelName = getChannel().getName(); String host = replacer.replaceValues(connectorProperties.getListenerConnectorProperties().getHost(), channelId, channelName);//from w w w .j a v a 2 s.c om int port = NumberUtils.toInt(replacer.replaceValues( connectorProperties.getListenerConnectorProperties().getPort(), channelId, channelName)); logger.debug("starting Web Service HTTP server on port: " + port); java.util.logging.Logger.getLogger("javax.enterprise.resource.webservices.jaxws.server") .setLevel(java.util.logging.Level.OFF); try { configuration.configureReceiver(this); server.bind(new InetSocketAddress(host, port), DEFAULT_BACKLOG); } catch (Exception e) { throw new ConnectorTaskException("Error creating HTTP Server.", e); } // TODO: Make a max connections property for this int processingThreads = connectorProperties.getSourceConnectorProperties().getProcessingThreads(); if (processingThreads < 1) { processingThreads = 1; } // Allow more than the channel processing threads so WDSL requests can be accepted even if all processing threads are busy executor = Executors.newFixedThreadPool(processingThreads + 4); server.setExecutor(executor); server.start(); AcceptMessage acceptMessageWebService = null; try { MirthContextFactory contextFactory = contextFactoryController.getContextFactory(getResourceIds()); Class<?> clazz = Class.forName( replacer.replaceValues(connectorProperties.getClassName(), channelId, channelName), true, contextFactory.getApplicationClassLoader()); if (clazz.getSuperclass().equals(AcceptMessage.class)) { Constructor<?>[] constructors = clazz.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) { Class<?>[] parameters = constructors[i].getParameterTypes(); if ((parameters.length == 1) && parameters[0].equals(this.getClass())) { acceptMessageWebService = (AcceptMessage) constructors[i] .newInstance(new Object[] { this }); } } if (acceptMessageWebService == null) { logger.error( "Custom web service class must implement the constructor: public AcceptMessage(WebServiceReceiver webServiceReceiver)"); } } else { logger.error("Custom web service class must extend com.mirth.connect.connectors.ws.AcceptMessage"); } } catch (Exception e) { logger.error("Custom web service class initialization failed", e); } if (acceptMessageWebService == null) { logger.error("Custom web service class initialization failed, using DefaultAcceptMessage"); acceptMessageWebService = new DefaultAcceptMessage(this); } webServiceEndpoint = Endpoint.create(connectorProperties.getSoapBinding().getValue(), acceptMessageWebService); Binding binding = webServiceEndpoint.getBinding(); List<Handler> handlerChain = new LinkedList<Handler>(); handlerChain.add(new LoggingSOAPHandler(this)); binding.setHandlerChain(handlerChain); String serviceName = replacer.replaceValues(connectorProperties.getServiceName(), channelId, channelName); HttpContext context = server.createContext("/services/" + serviceName); // Set a security authenticator if needed if (authenticatorProvider != null) { context.setAuthenticator(createAuthenticator()); } webServiceEndpoint.publish(context); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.IDLE)); }
From source file:com.blackducksoftware.integration.jira.config.HubConfigController.java
@Path("/read") @GET//from w w w .j av a 2 s. c o m @Produces(MediaType.APPLICATION_JSON) public Response get(@Context final HttpServletRequest request) { final PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); final Response response = checkUserPermissions(request, settings); if (response != null) { return response; } final Object obj = transactionTemplate.execute(new TransactionCallback() { @Override public Object doInTransaction() { final String hubUrl = getValue(settings, HubConfigKeys.CONFIG_HUB_URL); logger.debug(String.format("Returning hub details for %s", hubUrl)); final String username = getValue(settings, HubConfigKeys.CONFIG_HUB_USER); final String password = getValue(settings, HubConfigKeys.CONFIG_HUB_PASS); final String passwordLength = getValue(settings, HubConfigKeys.CONFIG_HUB_PASS_LENGTH); final String timeout = getValue(settings, HubConfigKeys.CONFIG_HUB_TIMEOUT); final String proxyHost = getValue(settings, HubConfigKeys.CONFIG_PROXY_HOST); final String proxyPort = getValue(settings, HubConfigKeys.CONFIG_PROXY_PORT); final String noProxyHosts = getValue(settings, HubConfigKeys.CONFIG_PROXY_NO_HOST); final String proxyUser = getValue(settings, HubConfigKeys.CONFIG_PROXY_USER); final String proxyPassword = getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS); final String proxyPasswordLength = getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS_LENGTH); final HubServerConfigSerializable config = new HubServerConfigSerializable(); final HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder(); serverConfigBuilder.setHubUrl(hubUrl); serverConfigBuilder.setTimeout(timeout); serverConfigBuilder.setUsername(username); serverConfigBuilder.setPassword(password); serverConfigBuilder.setPasswordLength(NumberUtils.toInt(passwordLength)); serverConfigBuilder.setProxyHost(proxyHost); serverConfigBuilder.setProxyPort(proxyPort); serverConfigBuilder.setIgnoredProxyHosts(noProxyHosts); serverConfigBuilder.setProxyUsername(proxyUser); serverConfigBuilder.setProxyPassword(proxyPassword); serverConfigBuilder.setProxyPasswordLength(NumberUtils.toInt(proxyPasswordLength)); setConfigFromResult(config, serverConfigBuilder.createValidator()); config.setHubUrl(hubUrl); config.setUsername(username); if (StringUtils.isNotBlank(password)) { final int passwordLengthInt = getIntFromObject(passwordLength); if (passwordLengthInt > 0) { config.setPasswordLength(passwordLengthInt); config.setPassword(config.getMaskedPassword()); } } config.setTimeout(timeout); config.setHubProxyHost(proxyHost); config.setHubProxyPort(proxyPort); config.setHubNoProxyHosts(noProxyHosts); config.setHubProxyUser(proxyUser); if (StringUtils.isNotBlank(proxyPassword)) { final int hubProxyPasswordLength = getIntFromObject(proxyPasswordLength); if (hubProxyPasswordLength > 0) { config.setHubProxyPasswordLength(hubProxyPasswordLength); config.setHubProxyPassword(config.getMaskedProxyPassword()); } } return config; } }); return Response.ok(obj).build(); }
From source file:io.gromit.geolite2.geonames.SubdivisionFinder.java
/** * Read countries./*from w w w . j a v a2 s . c o m*/ * * @param subdivisionOneLocationUrl the subdivision one location url * @return the time zone finder */ public SubdivisionFinder readLevelOne(String subdivisionOneLocationUrl) { ZipInputStream zipis = null; try { zipis = new ZipInputStream(new URL(subdivisionOneLocationUrl).openStream(), Charset.forName("UTF-8")); ZipEntry zipEntry = zipis.getNextEntry(); logger.info("reading " + zipEntry.getName()); if (crc1 == zipEntry.getCrc()) { logger.info("skipp, same CRC"); return this; } CsvParserSettings settings = new CsvParserSettings(); settings.setSkipEmptyLines(true); settings.trimValues(true); CsvFormat format = new CsvFormat(); format.setDelimiter('\t'); format.setLineSeparator("\n"); format.setCharToEscapeQuoteEscaping('\0'); format.setQuote('\0'); settings.setFormat(format); CsvParser parser = new CsvParser(settings); List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8")); for (String[] entry : lines) { Subdivision subdivision = new Subdivision(); subdivision.setId(entry[0]); subdivision.setName(entry[1]); subdivision.setGeonameId(NumberUtils.toInt(entry[2])); idOneMap.put(subdivision.getId(), subdivision); geonameIdMap.put(subdivision.getGeonameId(), subdivision); } logger.info("loaded " + lines.size() + " subdivisions level 1"); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { try { zipis.close(); } catch (Exception e) { } ; } return this; }
From source file:com.autonomy.nonaci.indexing.impl.AbstractExportCommand.java
public int getMatchId() { return NumberUtils.toInt(get(PARAM_MATCH_ID)); }
From source file:com.mirth.connect.connectors.tcp.TcpReceiver.java
@Override public void onDeploy() throws ConnectorTaskException { connectorProperties = (TcpReceiverProperties) getConnectorProperties(); if (connectorProperties.isDataTypeBinary() && isProcessBatch()) { throw new ConnectorTaskException("Batch processing is not supported for binary data."); }//w w w . java 2 s . c o m // load the default configuration String configurationClass = configurationController.getProperty(connectorProperties.getProtocol(), "tcpConfigurationClass"); try { configuration = (TcpConfiguration) Class.forName(configurationClass).newInstance(); } catch (Throwable t) { logger.trace("could not find custom configuration class, using default"); configuration = new DefaultTcpConfiguration(); } try { configuration.configureConnectorDeploy(this); } catch (Exception e) { throw new ConnectorTaskException(e); } maxConnections = NumberUtils.toInt(connectorProperties.getMaxConnections()); timeout = NumberUtils.toInt(connectorProperties.getReceiveTimeout()); bufferSize = NumberUtils.toInt(connectorProperties.getBufferSize()); reconnectInterval = NumberUtils.toInt(connectorProperties.getReconnectInterval()); ExtensionController extensionController = ControllerFactory.getFactory().createExtensionController(); String pluginPointName = (String) connectorProperties.getTransmissionModeProperties().getPluginPointName(); if (pluginPointName.equals("Basic")) { transmissionModeProvider = new BasicModeProvider(); } else { transmissionModeProvider = (TransmissionModeProvider) extensionController.getTransmissionModeProviders() .get(pluginPointName); } if (transmissionModeProvider == null) { throw new ConnectorTaskException("Unable to find transmission mode plugin: " + pluginPointName); } dataTypeServerPlugin = extensionController.getDataTypePlugins().get(getInboundDataType().getType()); if (dataTypeServerPlugin == null) { throw new ConnectorTaskException("Unable to find data type plugin: " + getInboundDataType().getType()); } disposing = new AtomicBoolean(false); eventController.dispatchEvent(new ConnectorCountEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.IDLE, null, maxConnections)); }
From source file:com.mirth.connect.connectors.dimse.DICOMDispatcher.java
@Override public Response send(ConnectorProperties connectorProperties, ConnectorMessage connectorMessage) { DICOMDispatcherProperties dicomDispatcherProperties = (DICOMDispatcherProperties) connectorProperties; String info = "Host: " + dicomDispatcherProperties.getHost(); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.WRITING, info)); String responseData = null;/*from ww w. j av a 2s.com*/ String responseError = null; String responseStatusMessage = null; Status responseStatus = Status.QUEUED; File tempFile = null; MirthDcmSnd dcmSnd = new MirthDcmSnd(configuration); try { tempFile = File.createTempFile("temp", "tmp"); FileUtils.writeByteArrayToFile(tempFile, getAttachmentHandlerProvider() .reAttachMessage(dicomDispatcherProperties.getTemplate(), connectorMessage, null, true)); dcmSnd.setCalledAET("DCMRCV"); dcmSnd.setRemoteHost(dicomDispatcherProperties.getHost()); dcmSnd.setRemotePort(NumberUtils.toInt(dicomDispatcherProperties.getPort())); if ((dicomDispatcherProperties.getApplicationEntity() != null) && !dicomDispatcherProperties.getApplicationEntity().equals("")) { dcmSnd.setCalledAET(dicomDispatcherProperties.getApplicationEntity()); } if ((dicomDispatcherProperties.getLocalApplicationEntity() != null) && !dicomDispatcherProperties.getLocalApplicationEntity().equals("")) { dcmSnd.setCalling(dicomDispatcherProperties.getLocalApplicationEntity()); } if ((dicomDispatcherProperties.getLocalHost() != null) && !dicomDispatcherProperties.getLocalHost().equals("")) { dcmSnd.setLocalHost(dicomDispatcherProperties.getLocalHost()); dcmSnd.setLocalPort(NumberUtils.toInt(dicomDispatcherProperties.getLocalPort())); } dcmSnd.addFile(tempFile); //TODO Allow variables int value = NumberUtils.toInt(dicomDispatcherProperties.getAcceptTo()); if (value != 5) dcmSnd.setAcceptTimeout(value); value = NumberUtils.toInt(dicomDispatcherProperties.getAsync()); if (value > 0) dcmSnd.setMaxOpsInvoked(value); value = NumberUtils.toInt(dicomDispatcherProperties.getBufSize()); if (value != 1) dcmSnd.setTranscoderBufferSize(value); value = NumberUtils.toInt(dicomDispatcherProperties.getConnectTo()); if (value > 0) dcmSnd.setConnectTimeout(value); if (dicomDispatcherProperties.getPriority().equals("med")) dcmSnd.setPriority(0); else if (dicomDispatcherProperties.getPriority().equals("low")) dcmSnd.setPriority(1); else if (dicomDispatcherProperties.getPriority().equals("high")) dcmSnd.setPriority(2); if (dicomDispatcherProperties.getUsername() != null && !dicomDispatcherProperties.getUsername().equals("")) { String username = dicomDispatcherProperties.getUsername(); UserIdentity userId; if (dicomDispatcherProperties.getPasscode() != null && !dicomDispatcherProperties.getPasscode().equals("")) { String passcode = dicomDispatcherProperties.getPasscode(); userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray()); } else { userId = new UserIdentity.Username(username); } userId.setPositiveResponseRequested(dicomDispatcherProperties.isUidnegrsp()); dcmSnd.setUserIdentity(userId); } dcmSnd.setPackPDV(dicomDispatcherProperties.isPdv1()); value = NumberUtils.toInt(dicomDispatcherProperties.getRcvpdulen()); if (value != 16) dcmSnd.setMaxPDULengthReceive(value); value = NumberUtils.toInt(dicomDispatcherProperties.getReaper()); if (value != 10) dcmSnd.setAssociationReaperPeriod(value); value = NumberUtils.toInt(dicomDispatcherProperties.getReleaseTo()); if (value != 5) dcmSnd.setReleaseTimeout(value); value = NumberUtils.toInt(dicomDispatcherProperties.getRspTo()); if (value != 60) dcmSnd.setDimseRspTimeout(value); value = NumberUtils.toInt(dicomDispatcherProperties.getShutdownDelay()); if (value != 1000) dcmSnd.setShutdownDelay(value); value = NumberUtils.toInt(dicomDispatcherProperties.getSndpdulen()); if (value != 16) dcmSnd.setMaxPDULengthSend(value); value = NumberUtils.toInt(dicomDispatcherProperties.getSoCloseDelay()); if (value != 50) dcmSnd.setSocketCloseDelay(value); value = NumberUtils.toInt(dicomDispatcherProperties.getSorcvbuf()); if (value > 0) dcmSnd.setReceiveBufferSize(value); value = NumberUtils.toInt(dicomDispatcherProperties.getSosndbuf()); if (value > 0) dcmSnd.setSendBufferSize(value); dcmSnd.setStorageCommitment(dicomDispatcherProperties.isStgcmt()); dcmSnd.setTcpNoDelay(!dicomDispatcherProperties.isTcpDelay()); configuration.configureDcmSnd(dcmSnd, this, dicomDispatcherProperties); dcmSnd.setOfferDefaultTransferSyntaxInSeparatePresentationContext(dicomDispatcherProperties.isTs1()); dcmSnd.configureTransferCapability(); dcmSnd.start(); dcmSnd.open(); dcmSnd.send(); if (dcmSnd.isStorageCommitment() && !dcmSnd.commit()) { logger.error("Failed to send Storage Commitment request."); } dcmSnd.close(); responseStatusMessage = "DICOM message successfully sent"; responseStatus = Status.SENT; } catch (Exception e) { responseStatusMessage = ErrorMessageBuilder.buildErrorResponse(e.getMessage(), e); responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(), e.getMessage(), null); eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), connectorMessage.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(), connectorProperties.getName(), e.getMessage(), null)); } finally { dcmSnd.stop(); if (tempFile != null) { tempFile.delete(); } eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.IDLE)); } return new Response(responseStatus, responseData, responseStatusMessage, responseError); }
From source file:com.blackducksoftware.integration.hub.bamboo.config.HubConfigController.java
@GET @Produces(MediaType.APPLICATION_JSON)// www . j av a 2s .c o m public Response get(@Context final HttpServletRequest request) { final PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); final Response response = checkUserPermissions(request, settings); if (response != null) { return response; } final Object obj = transactionTemplate.execute(new TransactionCallback() { @Override public Object doInTransaction() { final String hubUrl = getValue(settings, HubConfigKeys.CONFIG_HUB_URL); final String username = getValue(settings, HubConfigKeys.CONFIG_HUB_USER); final String password = getValue(settings, HubConfigKeys.CONFIG_HUB_PASS); final String passwordLength = getValue(settings, HubConfigKeys.CONFIG_HUB_PASS_LENGTH); final String timeout = getValue(settings, HubConfigKeys.CONFIG_HUB_TIMEOUT); final String proxyHost = getValue(settings, HubConfigKeys.CONFIG_PROXY_HOST); final String proxyPort = getValue(settings, HubConfigKeys.CONFIG_PROXY_PORT); final String noProxyHosts = getValue(settings, HubConfigKeys.CONFIG_PROXY_NO_HOST); final String proxyUser = getValue(settings, HubConfigKeys.CONFIG_PROXY_USER); final String proxyPassword = getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS); final String proxyPasswordLength = getValue(settings, HubConfigKeys.CONFIG_PROXY_PASS_LENGTH); final String hubWorkspaceCheckString = getValue(settings, HubConfigKeys.CONFIG_HUB_WORKSPACE_CHECK); Boolean hubWorkspaceCheck = true; if (StringUtils.isNotBlank(hubWorkspaceCheckString)) { hubWorkspaceCheck = Boolean.valueOf(hubWorkspaceCheckString); } final HubServerConfigSerializable config = new HubServerConfigSerializable(); final HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder(); serverConfigBuilder.setHubUrl(hubUrl); serverConfigBuilder.setTimeout(timeout); serverConfigBuilder.setUsername(username); serverConfigBuilder.setPassword(password); serverConfigBuilder.setPasswordLength(NumberUtils.toInt(passwordLength)); serverConfigBuilder.setProxyHost(proxyHost); serverConfigBuilder.setProxyPort(proxyPort); serverConfigBuilder.setIgnoredProxyHosts(noProxyHosts); serverConfigBuilder.setProxyUsername(proxyUser); serverConfigBuilder.setProxyPassword(proxyPassword); serverConfigBuilder.setProxyPasswordLength(NumberUtils.toInt(proxyPasswordLength)); setConfigFromResult(config, serverConfigBuilder.createValidator()); config.setHubUrl(hubUrl); config.setUsername(username); if (StringUtils.isNotBlank(password)) { final int passwordLengthInt = getIntFromObject(passwordLength); if (passwordLengthInt > 0) { config.setPasswordLength(passwordLengthInt); config.setPassword(config.getMaskedPassword()); } } config.setTimeout(timeout); config.setHubProxyHost(proxyHost); config.setHubProxyPort(proxyPort); config.setHubNoProxyHosts(noProxyHosts); config.setHubProxyUser(proxyUser); if (StringUtils.isNotBlank(proxyPassword)) { final int hubProxyPasswordLength = getIntFromObject(proxyPasswordLength); if (hubProxyPasswordLength > 0) { config.setHubProxyPasswordLength(hubProxyPasswordLength); config.setHubProxyPassword(config.getMaskedProxyPassword()); } } config.setHubWorkspaceCheck(hubWorkspaceCheck); checkAtlassianConfigInstalled(config); return config; } }); return Response.ok(obj).build(); }
From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java
@FXML public void updateMath1995() { if (logger.isDebugEnabled()) { logger.debug("[UPD 1995]"); }/*from ww w .j av a 2 s . co m*/ if (dao == null) { throw new IllegalArgumentException( "dao has not been set; call setRecenteredDAO() before calling this method"); } String recenteredScore_s = txtMathScoreRecentered.getText(); if (StringUtils.isNumeric(recenteredScore_s)) { Integer scoreRecentered = NumberUtils.toInt(recenteredScore_s); if (withinRange(scoreRecentered)) { if (needsRound(scoreRecentered)) { scoreRecentered = round(scoreRecentered); txtMathScoreRecentered.setText(String.valueOf(scoreRecentered)); } resetErrMsgs(); Integer score1995 = dao.lookup1995VerbalScore(scoreRecentered); txtMathScore1995.setText(String.valueOf(score1995)); } else { errMsgMathRecentered.setVisible(true); } } else { errMsgMathRecentered.setVisible(true); } }