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:io.wcm.config.core.impl.ParameterOverrideProviderBridge.java
private String toJsonValue(String value, Class type) { if (type.isArray()) { return "[" + toJsonValue(value, type.getComponentType()) + "]"; } else if (type == String.class) { return JSONObject.quote(value); } else if (type == int.class) { return Integer.toString(NumberUtils.toInt(value)); } else if (type == long.class) { return Long.toString(NumberUtils.toLong(value)); } else if (type == double.class) { return Double.toString(NumberUtils.toDouble(value)); } else if (type == boolean.class) { return Boolean.toString(BooleanUtils.toBoolean(value)); } else {/* ww w . j ava 2s. c o m*/ throw new IllegalArgumentException("Illegal value type: " + type.getName()); } }
From source file:gov.nih.nci.caintegrator.application.arraydata.AffymetrixSnpPlatformLoader.java
private int getIntegerValue(String[] fields, String header) { String value = getAnnotationValue(fields, header); if (!NumberUtils.isNumber(value)) { return -1; }/*from w w w. j a va2s .c o m*/ return NumberUtils.toInt(value); }
From source file:com.blackducksoftware.integration.jira.task.PluginConfigurationDetails.java
public int getIntervalMinutes() { return NumberUtils.toInt(intervalString); }
From source file:net.malisis.doors.gui.VanishingDiamondGui.java
@Subscribe public void onConfigChanged(ComponentEvent.ValueChange event) { Pair<ForgeDirection, DataType> data = (Pair<ForgeDirection, DataType>) event.getComponent().getData(); int time = event.getComponent() instanceof UITextField ? NumberUtils.toInt((String) event.getNewValue()) : 0;//from w w w .j a v a 2 s .c o m boolean checked = event.getComponent() instanceof UICheckBox ? (boolean) event.getNewValue() : false; VanishingDiamondFrameMessage.sendConfiguration(tileEntity, data.getLeft(), data.getRight(), time, checked); }
From source file:io.gromit.geolite2.geonames.CountryFinder.java
/** * Read countries./*from ww w .j ava 2s .c om*/ * * @param countriesLocationUrl the countries location url * @return the country finder */ private CountryFinder readCountries(String countriesLocationUrl) { ZipInputStream zipis = null; try { zipis = new ZipInputStream(new URL(countriesLocationUrl).openStream(), Charset.forName("UTF-8")); ZipEntry zipEntry = zipis.getNextEntry(); logger.info("reading " + zipEntry.getName()); if (crc == 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) { Country country = new Country(); country.setIso(entry[0]); country.setIso3(entry[1]); country.setName(entry[2]); country.setCapital(entry[3]); country.setContinent(entry[4]); country.setCurrencyCode(entry[5]); country.setCurrencyName(entry[6]); country.setPhone(entry[7]); country.setLanguage(StringUtils.substringBefore(entry[8], ",")); country.setGeonameId(NumberUtils.toInt(entry[9])); geonameMap.put(country.getGeonameId(), country); isoMap.put(country.getIso(), country); } } catch (Exception e) { throw new RuntimeException(e); } finally { try { zipis.close(); } catch (Exception e) { } ; } logger.info("loaded " + geonameMap.size() + " countries"); return this; }
From source file:net.malisis.blocks.vanishingoption.VanishingOptionsGui.java
@Subscribe public void onConfigChanged(ComponentEvent.ValueChange event) { Pair<EnumFacing, DataType> data = (Pair<EnumFacing, DataType>) event.getComponent().getData(); int time = event.getComponent() instanceof UITextField ? NumberUtils.toInt((String) event.getNewValue()) : 0;/* w ww . j a va2s .co m*/ boolean checked = event.getComponent() instanceof UICheckBox ? (boolean) event.getNewValue() : false; vanishingOptions.set(data.getLeft(), data.getRight(), time, checked); VanishingDiamondFrameMessage.sendConfiguration(tileEntity, data.getLeft(), data.getRight(), time, checked); updateGui(); }
From source file:com.mirth.connect.connectors.tcp.TcpDispatcher.java
@Override public void onDeploy() throws ConnectorTaskException { connectorProperties = (TcpDispatcherProperties) getConnectorProperties(); String pluginPointName = (String) connectorProperties.getTransmissionModeProperties().getPluginPointName(); if (pluginPointName.equals("Basic")) { transmissionModeProvider = new BasicModeProvider(); } else {/*from ww w .ja v a2 s.c o m*/ transmissionModeProvider = (TransmissionModeProvider) ControllerFactory.getFactory() .createExtensionController().getTransmissionModeProviders().get(pluginPointName); } if (transmissionModeProvider == null) { throw new ConnectorTaskException("Unable to find transmission mode plugin: " + pluginPointName); } // 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); } connectedSockets = new ConcurrentHashMap<String, Socket>(); timeoutThreads = new ConcurrentHashMap<String, Thread>(); sendTimeout = NumberUtils.toInt(connectorProperties.getSendTimeout()); responseTimeout = NumberUtils.toInt(connectorProperties.getResponseTimeout()); bufferSize = NumberUtils.toInt(connectorProperties.getBufferSize()); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.IDLE)); }
From source file:com.bekwam.examples.javafx.oldscores.ScoresDialogController.java
@FXML public void updateMathRecentered() { if (logger.isDebugEnabled()) { logger.debug("[UPD M RECENTERED]"); }/*from www . j av a 2s. c o m*/ if (dao == null) { throw new IllegalArgumentException( "dao has not been set; call setRecenteredDAO() before calling this method"); } String score1995_s = txtMathScore1995.getText(); if (StringUtils.isNumeric(score1995_s)) { Integer score1995 = NumberUtils.toInt(score1995_s); if (withinRange(score1995)) { if (needsRound(score1995)) { score1995 = round(score1995); txtMathScore1995.setText(String.valueOf(score1995)); } resetErrMsgs(); Integer scoreRecentered = dao.lookupRecenteredMathScore(score1995); txtMathScoreRecentered.setText(String.valueOf(scoreRecentered)); } else { errMsgMath1995.setVisible(true); } } else { errMsgMath1995.setVisible(true); } }
From source file:com.blackducksoftware.integration.hub.builder.HubScanJobConfigBuilder.java
private void validateScanMemory(final ValidationResults<HubScanJobFieldEnum, HubScanJobConfig> result, final Integer defaultScanMemory) { if (shouldUseDefaultValues() && defaultScanMemory != null) { final int scanMemoryInt = NumberUtils.toInt(scanMemory); if (scanMemoryInt < MINIMUM_MEMORY_IN_MEGABYTES && defaultScanMemory != null) { scanMemory = String.valueOf(defaultScanMemory); }//from www. ja v a 2 s . co m return; } if (StringUtils.isBlank(scanMemory)) { result.addResult(HubScanJobFieldEnum.SCANMEMORY, new ValidationResult(ValidationResultEnum.ERROR, "No scan memory was specified.")); return; } int scanMemoryInt = 0; try { scanMemoryInt = stringToInteger(scanMemory); } catch (final IllegalArgumentException e) { result.addResult(HubScanJobFieldEnum.SCANMEMORY, new ValidationResult(ValidationResultEnum.ERROR, e.getMessage(), e)); return; } if (scanMemoryInt < MINIMUM_MEMORY_IN_MEGABYTES) { result.addResult(HubScanJobFieldEnum.SCANMEMORY, new ValidationResult(ValidationResultEnum.ERROR, "The minimum amount of memory for the scan is " + MINIMUM_MEMORY_IN_MEGABYTES + " MB.")); } else { result.addResult(HubScanJobFieldEnum.SCANMEMORY, new ValidationResult(ValidationResultEnum.OK, "")); } }
From source file:gov.va.chir.tagline.dao.FileDao.java
public static Collection<Document> loadLabeledLines(final File file, boolean hasHeader) throws IOException { final Map<String, Map<Integer, Line>> docMap = new HashMap<String, Map<Integer, Line>>(); // Assumes tab-delimited columns. May not be sorted. // Column labels may be on first line // Col 0 = NoteID // Col 1 = LineID // Col 2 = Class // Col 3 = Text final int POS_DOC_ID = 0; final int POS_LINE_ID = 1; final int POS_CLASS = 2; final int POS_TEXT = 3; final List<String> contents = FileUtils.readLines(file); for (int i = (hasHeader ? 1 : 0); i < contents.size(); i++) { final String l = contents.get(i); final String[] array = l.split("\t"); if (!docMap.containsKey(array[POS_DOC_ID])) { docMap.put(array[POS_DOC_ID], new TreeMap<Integer, Line>()); }//from ww w .j a v a 2 s .com int lineId = NumberUtils.toInt(array[POS_LINE_ID]); final Line line = new Line(lineId, (array.length == POS_TEXT ? "" : array[POS_TEXT]), // blank lines have no content array[POS_CLASS]); docMap.get(array[POS_DOC_ID]).put(lineId, line); } final Collection<Document> docs = new ArrayList<Document>(); for (String docId : docMap.keySet()) { docs.add(new Document(docId, new ArrayList<Line>(docMap.get(docId).values()))); } return docs; }