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.mirth.connect.connectors.jdbc.DatabaseReceiverScript.java
@SuppressWarnings("unchecked") @Override//w w w . j a v a 2 s . c om public Object poll() throws DatabaseReceiverException, InterruptedException { Object finalResult = null; 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 && !connector.isTerminated()) { try { Object result = JavaScriptUtil.execute(new SelectTask(getContextFactory())); if (result instanceof NativeJavaObject) { Object unwrappedResult = ((NativeJavaObject) result).unwrap(); if (unwrappedResult instanceof ResultSet) { finalResult = (ResultSet) unwrappedResult; } else if (unwrappedResult instanceof List) { finalResult = (List<Map<String, Object>>) unwrappedResult; } else { throw new DatabaseReceiverException("Unrecognized value returned from script in channel \"" + ChannelController.getInstance().getDeployedChannelById(connector.getChannelId()) .getName() + "\", expected ResultSet or List<Map<String, Object>>: " + unwrappedResult.toString()); } done = true; } else { throw new DatabaseReceiverException("Unrecognized value returned from script in channel \"" + ChannelController.getInstance().getDeployedChannelById(connector.getChannelId()) .getName() + "\", expected ResultSet or List<Map<String, Object>>: " + result.toString()); } } catch (Exception e) { if (attempts++ < maxRetryCount && !connector.isTerminated()) { logger.error("An error occurred while polling for messages, retrying after " + retryInterval + " ms...", e); // Wait the specified amount of time before retrying Thread.sleep(retryInterval); } else { throw new DatabaseReceiverException("Error executing script " + selectScriptId + ".", e.getCause()); } } } return finalResult; }
From source file:com.eastcom.baseframe.web.modules.sys.web.controller.api.DictController.java
@ResponseBody @RequestMapping(value = "/list", method = RequestMethod.POST) public DataGridJson list(HttpSession session, HttpServletRequest request, @RequestParam Map<String, Object> params) { logger.info("--?--"); DataGridJson gridJson = new DataGridJson(); try {/*www .j a va 2s. c o m*/ int pageNo = NumberUtils.toInt((String) params.get("page"), 1); int pageSize = NumberUtils.toInt((String) params.get("rows"), 1000); String parentId = StringUtils.defaultString((String) params.get("parentId"), "null"); Map<String, Object> reqParams = new HashMap<String, Object>(); reqParams.put("parentId", parentId); PageHelper<Dict> pageHelper = dictService.find(reqParams, pageNo, pageSize); gridJson.setRows(pageHelper.getList()); gridJson.setTotal(pageHelper.getCount()); } catch (Exception e) { e.printStackTrace(); } return gridJson; }
From source file:com.esri.geoevent.test.performance.ui.ConsumerController.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(ConsumerController.class); preferences.put("protocol", selectedProtocol.toString()); preferences.put("port", String.valueOf(portNumber)); preferences.put("serverPort", String.valueOf(serverPortNumber)); }
From source file:com.github.dactiv.fear.commons.AuthCoder.java
/** * // w w w. j a va 2 s. c o m * * @param value ? * @param key * @param randomKeyLength ? ? 0-32???? * ???iv?? * ? = 16 randomKeyLength 0 ?? * @param encoding ? * @return ? */ public static String decode(String value, String key, int randomKeyLength, String encoding) throws UnsupportedEncodingException { key = DigestUtils.md5Hex(key.getBytes()); String keya = DigestUtils.md5Hex(StringUtils.substring(key, 0, 16).getBytes()); String keyb = DigestUtils.md5Hex(StringUtils.substring(key, 16, 16 + 16).getBytes()); String keyc = randomKeyLength > 0 ? StringUtils.substring(value, 0, randomKeyLength) : ""; String cryptKey = keya + DigestUtils.md5Hex((keya + keyc).getBytes()); int cryptKeyLen = cryptKey.length(); value = new String(Base64.decodeBase64((StringUtils.substring(value, randomKeyLength))), encoding); int stringLen = value.length(); List<Integer> rndKey = new ArrayList<>(); StringBuilder result = new StringBuilder(); Integer[] box = new Integer[256]; for (int i = 0; i < box.length; i++) { box[i] = i; } for (int i = 0; i <= 255; i++) { rndKey.add((int) cryptKey.charAt(i % cryptKeyLen)); } for (int j = 0, i = 0; i < 256; i++) { j = (j + box[i] + rndKey.get(i)) % 256; int tmp = box[i]; box[i] = box[j]; box[j] = tmp; } for (int k = 0, j = 0, i = 0; i < stringLen; i++) { k = (k + 1) % 256; j = (j + box[k]) % 256; int tmp = box[k]; box[k] = box[j]; box[j] = tmp; int a = (int) value.charAt(i); int b = box[(box[k] + box[j]) % 256]; char r = (char) (a ^ b); result.append(r); } if ((NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), -1) == 0 || NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), 0) - System.currentTimeMillis() / 1000 > 0) && StringUtils.substring(result.toString(), 10, 10 + 16) .equals(StringUtils.substring( DigestUtils .md5Hex((StringUtils.substring(result.toString(), 26) + keyb).getBytes()), 0, 16))) { return StringUtils.substring(result.toString(), 26); } else { return ""; } }
From source file:com.doxologic.nifi.processors.Repeater.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();/*ww w . j a v a2 s . c o m*/ if (flowFile == null) { return; } int maxRepeatCount = context.getProperty(REPEAT_COUNT).asInteger(); boolean penalizePasses = context.getProperty(PENALIZE_PASSES).asBoolean(); int repeatCount = NumberUtils.toInt(flowFile.getAttribute(REPEATER_COUNT_ATTR), 0) + 1; HashMap<String, String> attributes = new HashMap<>(); attributes.put(REPEATER_COUNT_ATTR, String.valueOf(repeatCount)); flowFile = session.putAllAttributes(flowFile, attributes); session.getProvenanceReporter().modifyAttributes(flowFile); if (penalizePasses && repeatCount > 1) { flowFile = session.penalize(flowFile); } if (repeatCount <= maxRepeatCount) { // route to repeat relationship session.transfer(flowFile, REPEAT); } else { // route to no-repeat relationship session.transfer(flowFile, NO_REPEAT); } }
From source file:com.eastcom.hrmis.modules.emp.web.controller.api.EmployeeController.java
/** * //from ww w . jav a 2s .c o m * * @param session * @param request * @param params * @return */ @RequiresPermissions("emp:baseinfomgr:view") @ResponseBody @RequestMapping(value = "/list", method = RequestMethod.POST) public DataGridJson list(HttpSession session, HttpServletRequest request, @RequestParam Map<String, Object> params) { logger.info("--??--"); DataGridJson gridJson = new DataGridJson(); try { int pageNo = NumberUtils.toInt((String) params.get("page"), 1); int pageSize = NumberUtils.toInt((String) params.get("rows"), 1); Map<String, Object> reqParams = Maps.newHashMap(params); reqParams.remove("page"); reqParams.remove("rows"); PageHelper<Employee> pageHelper = employeeService.find(reqParams, pageNo, pageSize); gridJson.setRows(pageHelper.getList()); gridJson.setTotal(pageHelper.getCount()); } catch (Exception e) { e.printStackTrace(); } return gridJson; }
From source file:com.omertron.themoviedbapi.TheMovieDbApiTest.java
@BeforeClass public static void setUpClass() throws Exception { TestLogger.Configure();//w w w .j a va 2 s .c o m Properties props = new Properties(); File f = new File(PROP_FIlENAME); if (f.exists()) { LOG.info("Loading properties from '{}'", PROP_FIlENAME); TestLogger.loadProperties(props, f); API_KEY = props.getProperty("API_Key"); ACCOUNT_ID_APITESTS = NumberUtils.toInt(props.getProperty("Account_ID"), 0); SESSION_ID_APITESTS = props.getProperty("Session_ID"); } else { LOG.info("Property file '{}' not found, creating dummy file.", PROP_FIlENAME); props.setProperty("API_Key", "INSERT_YOUR_KEY_HERE"); props.setProperty("Account_ID", "ACCOUNT ID FOR SESSION TESTS"); props.setProperty("Session_ID", "INSERT_YOUR_SESSION_ID_HERE"); TestLogger.saveProperties(props, f, "Properties file for tests"); fail("Failed to get key information from properties file '" + PROP_FIlENAME + "'"); } tmdb = new TheMovieDbApi(API_KEY); }
From source file:io.lavagna.service.Scheduler.java
@Override public void onApplicationEvent(DatabaseMigrationDoneEvent event) { if ("MYSQL".equals(env.getProperty("datasource.dialect"))) { taskScheduler.scheduleAtFixedRate(new Runnable() { @Override/*from w w w. j a v a 2 s . c om*/ public void run() { mySqlFullTextSupportService.syncNewCards(); mySqlFullTextSupportService.syncUpdatedCards(); mySqlFullTextSupportService.syncNewCardData(); mySqlFullTextSupportService.syncUpdatedCardData(); } }, 2 * 1000); } Integer timespan = NumberUtils .toInt(configurationRepository.getValueOrNull(Key.EMAIL_NOTIFICATION_TIMESPAN), 30); taskScheduler.scheduleAtFixedRate( new EmailNotificationHandler(configurationRepository, notificationService), timespan * 1000); }
From source file:com.formkiq.core.equifax.service.EquifaxServiceImpl.java
/** * Get Request Cache.// w w w . j av a2s.c o m * @param form {@link FormJSON} * @return int */ private int getRequestCache(final FormJSON form) { int cache = 0; Optional<FormJSONField> op = findValueByKey(form, "requestcache"); if (op.isPresent()) { cache = NumberUtils.toInt(op.get().getValue(), 0); } return cache; }
From source file:com.moviejukebox.tools.DateTimeTools.java
/** * Take a string runtime in various formats and try to output this in minutes * * @param runtime/* www . j av a 2 s .c o m*/ * @return */ public static int processRuntime(final String runtime) { if (StringUtils.isBlank(runtime)) { // No string to parse return -1; } // See if we can convert this to a number and assume it's correct if we can int returnValue = (int) NumberUtils.toFloat(runtime, -1f); if (returnValue < 0) { // This is for the format xx(hour/hr/min)yy(min), e.g. 1h30, 90mins, 1h30m Pattern hrmnPattern = Pattern.compile("(?i)(\\d+)(\\D*)(\\d*)(.*?)"); Matcher matcher = hrmnPattern.matcher(runtime); if (matcher.find()) { int first = NumberUtils.toInt(matcher.group(1), -1); String divide = matcher.group(2); int second = NumberUtils.toInt(matcher.group(3), -1); if (first > -1 && second > -1) { returnValue = (first > -1 ? first * 60 : 0) + (second > -1 ? second : 0); } else if (isNotValidString(divide)) { // No divider value, so assume this is a straight minute value returnValue = first; } else if (second > -1 && isValidString(divide)) { // this is xx(text) so we need to work out what the (text) is if (divide.toLowerCase().contains("h")) { // Assume it is a form of "hours", so convert to minutes returnValue = first * 60; } else { // Assume it's a form of "minutes" returnValue = first; } } } } return returnValue; }