List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:com.glaf.base.online.web.springmvc.UserOnlineController.java
@RequestMapping("/remain") public ModelAndView remain(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); int timeoutSeconds = 300; SystemProperty p = systemPropertyService.getSystemProperty("SYS", "login_time_check"); if (p != null && p.getValue() != null && StringUtils.isNumeric(p.getValue())) { timeoutSeconds = Integer.parseInt(p.getValue()); }// w w w . j a v a 2 s. c o m if (timeoutSeconds > 3600) { timeoutSeconds = 3600; } timeoutSeconds = timeoutSeconds - 60; if (timeoutSeconds < 60) { timeoutSeconds = 60; } request.setAttribute("timeoutSeconds", timeoutSeconds); String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } return new ModelAndView("/modules/sys/online/remain", modelMap); }
From source file:datadidit.helpful.hints.processors.csv.converter.ConvertCSVToJSON.java
public List<Map<?, ?>> fixMap(List<Map<?, ?>> map) { List<Map<?, ?>> newList = new ArrayList<>(); for (Map<?, ?> entry : map) { Map<String, Object> newMap = new HashMap<String, Object>(); for (Map.Entry<?, ?> mEntry : entry.entrySet()) { String value = mEntry.getValue().toString(); //Need to remove leading . for isNumeric to work with Doubles if (value.startsWith(".") && StringUtils.isNumeric(value.substring(1))) { newMap.put(mEntry.getKey().toString(), Double.parseDouble(value)); } else if (StringUtils.isNumeric(mEntry.getValue().toString())) { newMap.put(mEntry.getKey().toString(), Integer.parseInt(value)); } else { newMap.put(mEntry.getKey().toString(), mEntry.getValue().toString()); }//from w w w . j av a 2 s . c o m } newList.add(newMap); } return newList; }
From source file:ee.ria.xroad.asyncdb.messagequeue.MessageQueueImpl.java
@Override public List<RequestInfo> getRequests() throws Exception { LOG.info("Getting requests for provider '{}' ", provider); List<RequestInfo> requests = new ArrayList<>(); String[] requestDirectories = AsyncDBUtil.getDirectoriesList(new File(providerDirPath)); if (requestDirectories == null) { throw new IllegalStateException("Request directories must be present when requests are read!"); }//ww w .j a va2s .c o m List<Integer> requestDirectoryNumbers = new ArrayList<>(requestDirectories.length); for (String requestDirectory : requestDirectories) { if (!StringUtils.isNumeric(requestDirectory)) { continue; } requestDirectoryNumbers.add(Integer.parseInt(requestDirectory)); } Collections.sort(requestDirectoryNumbers); for (Integer requestDirectoryNo : requestDirectoryNumbers) { requests.add(loadExistingRequest(requestDirectoryNo)); } LOG.info("Got requests for provider '{}': '{}'", provider, requests); return requests; }
From source file:jongo.filter.DefaultFormatFilter.java
private String formatSuccessJSONResponse(final JongoSuccess response) { final StringBuilder b = new StringBuilder("{"); b.append("\"success\":"); b.append(response.isSuccess());//from w w w .j a v a 2 s . c om b.append(",\"cells\":[ "); //this last space is important! for (Row r : response.getRows()) { List<String> args = new ArrayList<String>(); for (String key : r.getCells().keySet()) { String val = StringEscapeUtils.escapeJson(r.getCells().get(key)); if (StringUtils.isNumeric(val)) { if (StringUtils.isWhitespace(val)) { args.add("\"" + key.toLowerCase() + "\"" + ":" + "\"\""); } else { args.add("\"" + key.toLowerCase() + "\"" + ":" + val); } } else { args.add("\"" + key.toLowerCase() + "\"" + ":" + "\"" + val + "\""); } } b.append("{"); b.append(StringUtils.join(args, ",")); b.append("}"); b.append(","); } b.deleteCharAt(b.length() - 1); b.append("]}"); return b.toString(); }
From source file:com.sunway.cbm.util.ServletUtils.java
public static Integer getIntegerParameter(HttpServletRequest request, String name) { String value = getStringParameter(request, name); if (StringUtils.isNumeric(value)) return new Integer(value); else/* w w w . j a v a2 s.c o m*/ return null; }
From source file:com.moviejukebox.model.Filmography.java
public void setCastId(String castId) { if (isValidString(castId) && !castId.equalsIgnoreCase(Integer.toString(this.castId))) { if (StringUtils.isNumeric(castId)) { this.castId = Integer.parseInt(castId); setDirty();/*from www . j a va 2 s . c o m*/ } } }
From source file:com.streamsets.pipeline.stage.origin.jdbc.CommonSourceConfigBean.java
public static BigDecimal getQueriesPerSecondFromInterval(Object queryIntervalValue, int numThreads, String queriesPerSecondField, String queryIntervalField) { if (numThreads <= 0) { LOG.warn("numThreads was given as {} in query rate limit upgrade; switching to default value of 1", numThreads);/*www.ja va2 s.co m*/ numThreads = 1; } BigDecimal queriesPerSecond = new BigDecimal(DEFAULT_QUERIES_PER_SECONDS); Long intervalSeconds = null; if (queryIntervalValue instanceof String) { final String queryIntervalExpr = (String) queryIntervalValue; // total hack, but we don't have access to a real EL evaluation within upgraders so we will only recognize // specific kinds of experssions (namely, the previous default value of ${10 * SECONDS}, or any similar // expression with a number other than 10 final String secondsElExpr = "^\\s*\\$\\{\\s*([0-9]*)\\s*\\*\\s*SECONDS\\s*\\}\\s*$"; final Matcher matcher = Pattern.compile(secondsElExpr).matcher(queryIntervalExpr); if (matcher.matches()) { final String secondsStr = matcher.group(1); intervalSeconds = Long.valueOf(secondsStr); } else if (StringUtils.isNumeric(queryIntervalExpr)) { intervalSeconds = Long.valueOf(queryIntervalExpr); } else { LOG.warn( "{} was a String, but was not a recognized format (either EL expression like '${N * SECONDS}' or simply" + " an integral number, so could not automatically convert it; will use a default value", queryIntervalValue); } } else if (queryIntervalValue instanceof Integer) { intervalSeconds = (long) ((Integer) queryIntervalValue).intValue(); } else if (queryIntervalValue instanceof Long) { intervalSeconds = (Long) queryIntervalValue; } if (intervalSeconds != null) { if (intervalSeconds > 0) { // Force a double operation to not lose precision. // Don't use BigDecimal#divide() to avoid hitting ArithmeticException if numThreads/intervalSeconds // is non-terminating. queriesPerSecond = BigDecimal.valueOf(((double) numThreads) / intervalSeconds); LOG.info("Calculated a {} value of {} from {} of {} and numThreads of {}", queriesPerSecondField, queriesPerSecond, queryIntervalField, queryIntervalValue, numThreads); } else { queriesPerSecond = BigDecimal.ZERO; LOG.warn( "{} value of {} was not positive, so had to use a value of {} for {}, which means unlimited", queryIntervalField, queryIntervalValue, queriesPerSecondField, queriesPerSecond); } } else { LOG.warn("Could not calculate a {} value, so using a default value of {}", queriesPerSecondField, queriesPerSecond); } return queriesPerSecond; }
From source file:net.ceos.project.poi.annotated.core.CellFormulaConverter.java
/** * Validate propagation with template range address passed as parameter. * <p>/*from w w w . ja va 2s . c o m*/ * Acceptable values are: * <ul> * <li>if PropagationType.HORIZONTAL, only numeric values allowed * <li>if PropagationType.VERTICAL, only letters values allowed * </ul> * * @param configCriteria * the {@link XConfigCriteria} * @param templateRangeAddress * the template range address * @throws ConfigurationException */ private static void validatePropagationWithRangeAddress(final XConfigCriteria configCriteria, String templateRangeAddress) throws ConfigurationException { if (PredicateFactory.isPropagationHorizontal.test(configCriteria.getPropagation()) && StringUtils.isNumeric(templateRangeAddress) || PredicateFactory.isPropagationVertical.test(configCriteria.getPropagation()) && StringUtils.isAlpha(templateRangeAddress)) { throw new ConfigurationException( ExceptionMessage.CONFIGURATION_CONFLICT_CONDITIONAL_FORMAT.getMessage()); } }
From source file:de.undercouch.citeproc.bibtex.DateParser.java
/** * Parses the given month string//w w w . java2s. c o m * @param month the month to parse. May be a number (<code>1-12</code>), * a short month name (<code>Jan</code> to <code>Dec</code>), or a * long month name (<code>January</code> to </code>December</code>). This * method is also able to recognize month names in several locales. * @return the month's number (<code>1-12</code>) or <code>-1</code> if * the string could not be parsed */ public static int toMonth(String month) { int m = -1; if (month != null && !month.isEmpty()) { if (StringUtils.isNumeric(month)) { m = Integer.parseInt(month); } else { m = tryParseMonth(month, Locale.ENGLISH); if (m <= 0) { m = tryParseMonth(month, Locale.getDefault()); if (m <= 0) { for (Locale l : Locale.getAvailableLocales()) { m = tryParseMonth(month, l); if (m > 0) { break; } } } } } } return m; }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.AreaServiceBean.java
@Override // FIXME rewrite me please and re use existing code public List<Map<String, Object>> getAreasByIds(final List<AreaTypeEntry> areaTypes) throws ServiceException { List<Map<String, Object>> areaColumnsList = new ArrayList<>(); Map<String, List<Long>> areaTypeGidMap = new HashMap<>(); for (AreaTypeEntry areaTypeEntry : areaTypes) { String gid = areaTypeEntry.getId(); String areaType = areaTypeEntry.getAreaType().value(); if (!StringUtils.isNumeric(gid)) { throw new SpatialServiceException(SpatialServiceErrors.INVALID_ID_TYPE, gid); }//from w w w . j av a 2 s .com boolean isAdded = false; for (Map.Entry<String, List<Long>> entry : areaTypeGidMap.entrySet()) { if (entry.getKey().equalsIgnoreCase(areaType)) { entry.getValue().add(Long.parseLong(gid)); isAdded = true; } } if (!isAdded) { areaTypeGidMap.put(areaType, new ArrayList(Arrays.asList(Long.parseLong(gid)))); } } for (Map.Entry<String, List<Long>> entry : areaTypeGidMap.entrySet()) { // FIXME looping and querying should be avoided String namedQuery = null; for (SpatialTypeEnum type : SpatialTypeEnum.values()) { if (type.getType().equalsIgnoreCase(entry.getKey())) { namedQuery = type.getNamedQuery(); } } if (namedQuery != null) { List<Map<String, Object>> selectedAreaColumns = repository.getAreasByIds(namedQuery, entry.getValue()); for (Map<String, Object> columnMap : selectedAreaColumns) { columnMap.put(AREA_TYPE, entry.getKey().toUpperCase()); } areaColumnsList.addAll(selectedAreaColumns); } } return areaColumnsList; }