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.omertron.tvrageapi.model.EpisodeNumber.java
public void setAbsolute(String absolute) { this.absolute = NumberUtils.toInt(absolute, 0); }
From source file:com.formkiq.core.webflow.dialect.LayoutFieldClassAttrProcessor.java
@Override protected String getTargetAttributeValue(final Arguments args, final Element element, final String attributeName) { Configuration configuration = args.getConfiguration(); IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); FormJSONSection section = findVariable(configuration, parser, args, "${section}"); String attributeValue = element.getAttributeValue(attributeName); FormJSONField field = findVariable(configuration, parser, args, attributeValue); String layoutWidth = field.getLayout().get("width"); int width = NumberUtils.toInt(layoutWidth, DEFAULT_CLASS_WIDTH); String layout = "col-xs-" + width; if (SIGNATURE.equals(field.getType()) || BUTTON.equals(field.getType())) { int occurs = getOccurrences(section, field); layout = "col-xs-" + (DEFAULT_CLASS_WIDTH / occurs); }/*from www . j av a 2s. co m*/ return layout; }
From source file:com.moviejukebox.plugin.TVRagePlugin.java
@Override public boolean scan(Movie movie) { ShowInfo showInfo = new ShowInfo(); List<ShowInfo> showList = null; // Note: The ID might be a vanity ID (A String rather than an Integer) String id = movie.getId(TVRAGE_PLUGIN_ID); int tvrageID = NumberUtils.toInt(id, 0); // Try and search using the ID if (tvrageID > 0) { LOG.debug("Searching using TVRage ID '{}'", tvrageID); showInfo = getShowInfo(tvrageID); }/*from w w w . j a va 2s . c o m*/ // Try using the vanity ID if (!showInfo.isValid() && (tvrageID == 0 && isValidString(id))) { LOG.debug("Searching using Vanity URL '{}'", id); showList = getShowList(id); } // Try using the title if ((showList == null || showList.isEmpty()) && (isValidString(movie.getTitle()))) { LOG.debug("Searching using title '{}'", movie.getTitle()); showList = getShowList(movie.getTitle()); } // If we have some shows, try to find the one that matches our show title if (showList != null && !showList.isEmpty()) { for (ShowInfo si : showList) { if (movie.getTitle().equalsIgnoreCase(si.getShowName())) { showInfo = si; break; } } } // Update the show specific information if (!showInfo.isValid() || showInfo.getShowID() == 0) { LOG.debug("Show '{}' not found", movie.getBaseName()); return false; } id = String.valueOf(showInfo.getShowID()); movie.setId(TVRAGE_PLUGIN_ID, id); try { showInfo = tvRage.getShowInfo(id); } catch (TVRageException ex) { LOG.info("Failed to get TVRage information for '{}' - error: {}", movie.getBaseName(), ex.getMessage(), ex); return false; } if (OverrideTools.checkOverwritePlot(movie, TVRAGE_PLUGIN_ID)) { movie.setPlot(showInfo.getSummary(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteOutline(movie, TVRAGE_PLUGIN_ID)) { movie.setOutline(showInfo.getSummary(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteGenres(movie, TVRAGE_PLUGIN_ID)) { movie.setGenres(showInfo.getGenres(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteYear(movie, TVRAGE_PLUGIN_ID)) { movie.setYear(String.valueOf(showInfo.getStarted()), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteCompany(movie, TVRAGE_PLUGIN_ID)) { CountryDetail cd = showInfo.getNetwork().get(0); movie.setCompany(cd.getDetail(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteCountry(movie, TVRAGE_PLUGIN_ID)) { movie.setCountries(showInfo.getCountry(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteRuntime(movie, TVRAGE_PLUGIN_ID)) { movie.setRuntime(movie.getRuntime(), TVRAGE_PLUGIN_ID); } if (OverrideTools.checkOverwriteReleaseDate(movie, TVRAGE_PLUGIN_ID)) { movie.setReleaseDate(DateTimeTools.convertDateToString(showInfo.getStartDate()), TVRAGE_PLUGIN_ID); } scanTVShowTitles(movie); return true; }
From source file:de.bmarwell.j9kwsolver.util.ResponseUtils.java
/** * @param response the response sent by the server. * @return the number of credits assigned by the server for solving. *//* w w w.ja v a 2 s.c o m*/ private static int parseCredits(final String response) { int credits = 0; if (StringUtils.isEmpty(response)) { return credits; } String[] splitresponse = StringUtils.splitPreserveAllTokens(response, '|'); if (splitresponse.length != 2) { LOG.error("Response doesn't contain two items: {}.", ToStringBuilder.reflectionToString(splitresponse)); return credits; } // TODO: Enum for numbered field. String stringCredits = splitresponse[1]; if (NumberUtils.isDigits(stringCredits)) { credits = NumberUtils.toInt(stringCredits, 0); LOG.debug("Found reward: {} credits.", credits); } return credits; }
From source file:io.wcm.caravan.pipeline.impl.operators.ResponseHandlingOperator.java
@Override public Subscriber<? super CaravanHttpResponse> call(Subscriber<? super JsonPipelineOutput> subscriber) { return new Subscriber<CaravanHttpResponse>() { @Override/* www . jav a 2s .c o m*/ public void onCompleted() { subscriber.onCompleted(); } @Override public void onError(Throwable e) { Exceptions.throwIfFatal(e); int statusCode = 500; if (e instanceof IllegalResponseRuntimeException) { statusCode = ((IllegalResponseRuntimeException) e).getResponseStatusCode(); } JsonPipelineInputException jsonPipelineInputException = new JsonPipelineInputException(statusCode, "Failed to GET " + request.getUrl(), e).setReason(e.getMessage()); subscriber.onError(jsonPipelineInputException); } @Override public void onNext(CaravanHttpResponse response) { try (Body body = response.body()) { final int statusCode = response.status(); log.debug("received {} response ({}) with from {},\n{}", statusCode, response.reason(), request.getUrl(), request.getCorrelationId()); if (statusCode == HttpServletResponse.SC_OK) { JsonNode payload = JacksonFunctions.stringToNode(body.asString()); int maxAge = NumberUtils.toInt(response.getCacheControl().get("max-age"), -1); JsonPipelineOutput model = new JsonPipelineOutputImpl(payload, ImmutableList.of(request)) .withMaxAge(maxAge); subscriber.onNext(model); } else { String msg = "Request for " + request.getUrl() + " failed with HTTP status code: " + statusCode + " (" + response.reason() + ")" + ", " + request.getCorrelationId(); if (statusCode / 100 == 4) { log.info(msg); } else { log.warn(msg); } JsonPipelineInputException pipelineInputException = new JsonPipelineInputException( statusCode, msg).setReason(response.reason()); subscriber.onError(pipelineInputException); } } catch (IOException ex) { JsonPipelineInputException pipelineInputException = new JsonPipelineInputException(500, "Failed to read JSON response from " + request.getUrl(), ex) .setReason(response.reason()); subscriber.onError(pipelineInputException); } } }; }
From source file:com.omertron.tvrageapi.model.EpisodeNumber.java
public void setEpisode(String episode) { this.episode = NumberUtils.toInt(episode, 0); }
From source file:com.mirth.connect.connectors.jdbc.DatabaseReceiverQuery.java
private void initConnection() throws ConnectorTaskException { int attempts = 0; String channelId = connector.getChannelId(); String channelName = connector.getChannel().getName(); int maxRetryCount = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getRetryCount(), channelId, channelName), 0); int retryInterval = NumberUtils .toInt(replacer.replaceValues(connectorProperties.getRetryInterval(), channelId, channelName), 0); boolean done = false; while (!done) { try {/* w w w . j a v a 2 s .com*/ initSelectConnection(); if (connectorProperties.getUpdateMode() != DatabaseReceiverProperties.UPDATE_NEVER) { initUpdateConnection(); } done = true; } catch (SQLException e) { // close all of the connections/statements in case some of them did initialize successfully closeSelectConnection(); closeUpdateConnection(); if (attempts++ < maxRetryCount) { logger.error("An error occurred while initializing the connection, retrying after " + retryInterval + " ms...", e); // Wait the specified amount of time before retrying try { Thread.sleep(retryInterval); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); throw new ConnectorTaskException( "Thread interrupted while trying to initialize database connection", e); } } else { throw new ConnectorTaskException("Failed to initialize database connection", e); } } } }
From source file:com.autonomy.nonaci.indexing.impl.IndexCommandImpl.java
public int getPriority() { return NumberUtils.toInt(parameters.get(PARAM_PRIORITY), -1); }
From source file:com.esri.geoevent.test.performance.ui.ProducerController.java
@Override protected void saveState() { Protocol selectedProtocol = protocol.getValue(); int portNumber = NumberUtils.toInt(port.getText(), DEFAULT_COMMAND_PORT); int serverPortNumber = NumberUtils.toInt(serverPort.getText(), DEFAULT_SERVER_PORT); Preferences preferences = Preferences.userNodeForPackage(ProducerController.class); preferences.put("protocol", selectedProtocol.toString()); preferences.put("port", String.valueOf(portNumber)); preferences.put("serverPort", String.valueOf(serverPortNumber)); }
From source file:com.ddp.SimpleREST.java
private void getListHierarchy(RoutingContext routingContext) { HttpServerResponse response = routingContext.response(); Consumer<Integer> errorHandler = i -> response.setStatusCode(i).end(); Consumer<String> responseHandler = s -> response.putHeader("content-type", "application/json").end(s); int pageNum = NumberUtils.toInt(routingContext.request().getParam("pageNum"), 0); int pageSize = NumberUtils.toInt(routingContext.request().getParam("pageSize"), 20); Long sourceID = NumberUtils.toLong(routingContext.request().getParam("sourceID"), 0); Long entityID = NumberUtils.toLong(routingContext.request().getParam("entityID"), 0); dataBrowse.handleListHierarchy(errorHandler, responseHandler, pageNum, pageSize, sourceID, entityID); }