List of usage examples for org.apache.commons.lang3.math NumberUtils toInt
public static int toInt(final String str, final int defaultValue)
Convert a String
to an int
, returning a default value if the conversion fails.
If the string is null
, the default value is returned.
NumberUtils.toInt(null, 1) = 1 NumberUtils.toInt("", 1) = 1 NumberUtils.toInt("1", 0) = 1
From source file:com.jkoolcloud.tnt4j.streams.parsers.AbstractSyslogParser.java
@Override public void setProperty(String name, String value) { super.setProperty(name, value); if (SyslogParserProperties.PROP_SUPPRESS_LEVEL.equalsIgnoreCase(name)) { suppressionLevel = NumberUtils.toInt(value, DEFAULT_SUPPRESSION_LEVEL); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "ActivityParser.setting", name, value); } else if (SyslogParserProperties.PROP_SUPPRESS_CACHE_SIZE.equalsIgnoreCase(name)) { cacheSize = NumberUtils.toLong(value, DEFAULT_MAX_CACHE_SIZE); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "ActivityParser.setting", name, value); } else if (SyslogParserProperties.PROP_SUPPRESS_CACHE_EXPIRE.equalsIgnoreCase(name)) { cacheExpireDuration = NumberUtils.toLong(value, DEFAULT_CACHE_EXPIRE_DURATION); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "ActivityParser.setting", name, value); } else if (SyslogParserProperties.PROP_SUPPRESS_IGNORED_FIELDS.equalsIgnoreCase(name)) { if (StringUtils.isNotEmpty(value)) { ignoredFields = Arrays.asList(Utils.splitValue(value)); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "ActivityParser.setting", name, value); }//from w w w . j av a2s . c o m } else if (SyslogParserProperties.PROP_FLATTEN_STRUCTURED_DATA.equalsIgnoreCase(name)) { flattenStructuredData = Utils.toBoolean(value); logger().log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "ActivityParser.setting", name, value); } }
From source file:com.formkiq.core.service.generator.docx4j.WorkflowOutputWordDocx.java
/** * Find Field.//from w ww. ja v a 2 s.c om * @param archive {@link ArchiveDTO} * @param field {@link WorkflowOutputFormField} * @return {@link String} */ private Optional<FormJSONField> findField(final ArchiveDTO archive, final WorkflowOutputFormField field) { String formUUID = extractLabelAndValue(field.getForm()).getRight(); String id = extractLabelAndValue(field.getField()).getRight(); FormJSON form = archive.getForm(formUUID); if (form != null) { return FormFinder.findField(form, NumberUtils.toInt(id, -1)); } return Optional.empty(); }
From source file:com.dominion.salud.mpr.configuration.MPRJpaConfiguration.java
public DataSource JDBCDataSource() { ComboPooledDataSource dataSource = new ComboPooledDataSource(); try {/*ww w . j a v a2s . com*/ dataSource.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName")); dataSource.setJdbcUrl(environment.getRequiredProperty("jdbc.url")); dataSource.setUser(environment.getRequiredProperty("jdbc.username")); dataSource.setPassword(environment.getRequiredProperty("jdbc.password")); //Configuracion Opcional dataSource.setMinPoolSize( StringUtils.isNotBlank(environment.getRequiredProperty("jdbc.minPoolSize")) ? NumberUtils .toInt(environment.getRequiredProperty("jdbc.minPoolSize"), MPRConstantes.MIN_POOL_SIZE) : MPRConstantes.MIN_POOL_SIZE); dataSource.setMaxPoolSize( StringUtils.isNotBlank(environment.getRequiredProperty("jdbc.maxPoolSize")) ? NumberUtils .toInt(environment.getRequiredProperty("jdbc.maxPoolSize"), MPRConstantes.MAX_POOL_SIZE) : MPRConstantes.MAX_POOL_SIZE); dataSource.setCheckoutTimeout( StringUtils.isNotBlank(environment.getRequiredProperty("jdbc.checkoutTimeout")) ? NumberUtils.toInt(environment.getRequiredProperty("jdbc.checkoutTimeout"), MPRConstantes.CHECKOUT_TIMEOUT) : MPRConstantes.CHECKOUT_TIMEOUT); dataSource.setIdleConnectionTestPeriod( StringUtils.isNotBlank(environment.getRequiredProperty("jdbc.idleConnectionTestPeriod")) ? NumberUtils.toInt(environment.getRequiredProperty("jdbc.idleConnectionTestPeriod"), MPRConstantes.IDLE_CONNECTION_TEST_PERIOD) : MPRConstantes.IDLE_CONNECTION_TEST_PERIOD); dataSource.setPreferredTestQuery( StringUtils.isNotBlank(environment.getRequiredProperty("jdbc.preferredTestQuery")) ? environment.getRequiredProperty("jdbc.preferredTestQuery") : MPRConstantes.PREFERRED_TEST_QUERY); //Autoconfiguracion dataSource.setAcquireIncrement(1); dataSource.setInitialPoolSize(3); dataSource.setIdleConnectionTestPeriod(900); dataSource.setMaxIdleTimeExcessConnections(1800); dataSource.setTestConnectionOnCheckin(true); } catch (IllegalStateException | PropertyVetoException e) { } return dataSource; }
From source file:io.wcm.sling.commons.request.RequestParam.java
/** * Returns a request parameter as integer. * @param request Request./*from w w w . java 2 s .co m*/ * @param param Parameter name. * @param defaultValue Default value. * @return Parameter value or default value if it does not exist or is not a number. */ public static int getInt(ServletRequest request, String param, int defaultValue) { String value = request.getParameter(param); return NumberUtils.toInt(value, defaultValue); }
From source file:com.dominion.salud.nomenclator.configuration.NOMENCLATORJpaConfiguration.java
public DataSource JDBCDataSource() { ComboPooledDataSource dataSource = new ComboPooledDataSource(); try {// ww w .j av a2 s . co m dataSource.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName")); dataSource.setJdbcUrl(environment.getRequiredProperty("jdbc.url")); dataSource.setUser(environment.getRequiredProperty("jdbc.username")); dataSource.setPassword(environment.getRequiredProperty("jdbc.password")); //Opcionales dataSource.setInitialPoolSize(StringUtils.isNotBlank(environment.getProperty("jdbc.initialPoolSize")) ? NumberUtils.toInt(environment.getProperty("jdbc.initialPoolSize"), 5) : 5); dataSource.setAcquireIncrement(StringUtils.isNotBlank(environment.getProperty("jdbc.acquireIncrement")) ? NumberUtils.toInt(environment.getProperty("jdbc.acquireIncrement"), 5) : 5); dataSource.setMinPoolSize(StringUtils.isNotBlank(environment.getProperty("jdbc.minPoolSize")) ? NumberUtils.toInt(environment.getProperty("jdbc.minPoolSize"), 5) : 5); dataSource.setMaxPoolSize(StringUtils.isNotBlank(environment.getProperty("jdbc.maxPoolSize")) ? NumberUtils.toInt(environment.getProperty("jdbc.maxPoolSize"), 25) : 25); dataSource.setAcquireRetryAttempts( StringUtils.isNotBlank(environment.getProperty("jdbc.acquireRetryAttempts")) ? NumberUtils.toInt(environment.getProperty("jdbc.acquireRetryAttempts"), 10) : 10); dataSource .setAcquireRetryDelay(StringUtils.isNotBlank(environment.getProperty("jdbc.acquireRetryDelay")) ? NumberUtils.toInt(environment.getProperty("jdbc.acquireRetryDelay"), 500) : 500); dataSource.setCheckoutTimeout(StringUtils.isNotBlank(environment.getProperty("jdbc.checkoutTimeout")) ? NumberUtils.toInt(environment.getProperty("jdbc.checkoutTimeout"), 5000) : 5000); logger.info(" jdbc.driverClassName: " + dataSource.getDriverClass()); logger.info(" jdbc.url: " + dataSource.getJdbcUrl()); logger.info(" jdbc.username: " + dataSource.getUser()); logger.info(" [Configuracion opcional]"); logger.info(" jdbc.initialPoolSize: " + dataSource.getInitialPoolSize()); logger.info(" jdbc.acquireIncrement: " + dataSource.getAcquireIncrement()); logger.info(" jdbc.minPoolSize: " + dataSource.getMinPoolSize()); logger.info(" jdbc.maxPoolSize: " + dataSource.getMaxPoolSize()); logger.info(" jdbc.acquireRetryAttempts: " + dataSource.getAcquireRetryAttempts()); logger.info(" jdbc.acquireRetryDelay: " + dataSource.getAcquireRetryDelay()); logger.info(" jdbc.checkoutTimeout: " + dataSource.getCheckoutTimeout()); } catch (IllegalStateException | PropertyVetoException e) { logger.error("No se ha podido establecer la conexion a base de datos: " + e.toString()); } return dataSource; }
From source file:com.tealcube.minecraft.bukkit.config.MasterConfiguration.java
public int getInt(String key, int fallback) { if (settingMap == null || !settingMap.containsKey(key)) { return fallback; }// ww w . j a va2s .com Object val = settingMap.get(key); if (val instanceof Integer) { return (Integer) val; } if (val instanceof String) { return NumberUtils.toInt((String) val, fallback); } return fallback; }
From source file:com.paladin.mvc.RequestContext.java
public int param(String name, int def_value) { return NumberUtils.toInt(param(name), def_value); }
From source file:ddf.catalog.impl.operations.QueryOperations.java
private static Integer determineAndRetrieveMaxPageSize() { return NumberUtils.toInt(System.getProperty(MAX_PAGE_SIZE_PROPERTY), DEFAULT_MAX_PAGE_SIZE); }
From source file:com.paladin.mvc.RequestContext.java
public byte param(String name, byte def_value) { return (byte) NumberUtils.toInt(param(name), def_value); }
From source file:com.mirth.connect.client.ui.panels.connectors.PollingSettingsPanel.java
public void fillProperties(PollConnectorPropertiesInterface propertiesInterface) { PollConnectorProperties properties = null; if (propertiesInterface != null) { properties = propertiesInterface.getPollConnectorProperties(); } else {//from w ww .j a va2 s . c o m properties = new PollConnectorProperties(); } String selectedPollingType = (String) scheduleTypeComboBox.getSelectedItem(); properties.setPollOnStart(yesStartPollRadioButton.isSelected()); if (selectedPollingType.equals(PollingType.INTERVAL.getDisplayName())) { properties.setPollingType(PollingType.INTERVAL); String type = (String) pollingFrequencyTypeComboBox.getSelectedItem(); int frequency = NumberUtils.toInt(pollingFrequencyField.getText(), 0); if (type.equals(POLLING_FREQUENCY_HOURS)) { frequency *= 3600000; } else if (type.equals(POLLING_FREQUENCY_MINUTES)) { frequency *= 60000; } else if (type.equals(POLLING_FREQUENCY_SECONDS)) { frequency *= 1000; } properties.setPollingFrequency(frequency); } else if (selectedPollingType.equals(PollingType.TIME.getDisplayName())) { properties.setPollingType(PollingType.TIME); try { SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa"); DateFormatter timeFormatter = new DateFormatter(timeDateFormat); Date timeDate = (Date) timeFormatter.stringToValue(pollingTimePicker.getDate()); Calendar timeCalendar = Calendar.getInstance(); timeCalendar.setTime(timeDate); properties.setPollingHour(timeCalendar.get(Calendar.HOUR_OF_DAY)); properties.setPollingMinute(timeCalendar.get(Calendar.MINUTE)); } catch (ParseException e) { // Do nothing since they could be manually entering in the time... } } else if (selectedPollingType.equals(PollingType.CRON.getDisplayName())) { properties.setPollingType(PollingType.CRON); List<CronProperty> cronJobs = new ArrayList<CronProperty>(); for (int rowCount = 0; rowCount < cronJobsTable.getRowCount(); rowCount++) { String description = (String) cronJobsTable.getValueAt(rowCount, 1); String expression = (String) cronJobsTable.getValueAt(rowCount, 0); if (StringUtils.isNotBlank(expression)) { cronJobs.add(new CronProperty(description, expression)); } } properties.setCronJobs(cronJobs); } properties.setPollConnectorPropertiesAdvanced(cachedAdvancedConnectorProperties); selectedPollingType = null; if (properties != null) { nextFireTimeProperties = properties.clone(); } }