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:io.bitsquare.gui.util.validation.AccountNrValidator.java
@Override public ValidationResult validate(String input) { int length;/*w w w.ja v a 2s . c om*/ String input2; switch (countryCode) { case "GB": length = 8; if (isNumberWithFixedLength(input, length)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNr", length)); case "US": if (isNumberInRange(input, 4, 17)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNr", "4 - 17")); case "BR": if (isStringInRange(input, 1, 20)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNrChars", "1 - 20")); case "NZ": input2 = input != null ? input.replaceAll("-", "") : null; if (isNumberInRange(input2, 15, 16)) return super.validate(input); else return new ValidationResult(false, "Account number must be of format: 03-1587-0050000-00"); case "AU": if (isNumberInRange(input, 4, 10)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNr", "4 - 10")); case "CA": if (isNumberInRange(input, 7, 12)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.accountNr", "7 - 12")); case "MX": length = 18; if (isNumberWithFixedLength(input, length)) return super.validate(input); else return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length)); case "HK": input2 = input != null ? input.replaceAll("-", "") : null; if (isNumberInRange(input2, 9, 12)) return super.validate(input); else return new ValidationResult(false, "Account number must be of format: 005-231289-112"); case "NO": if (input != null) { length = 11; // Provided by sturles: // https://github.com/bitsquare/bitsquare/pull/707 // https://no.wikipedia.org/wiki/MOD11#Implementasjoner_i_forskjellige_programmeringspr.C3.A5k // https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits6 // 11 digits, last digit is checksum. Checksum algoritm is // MOD11 with weights 2,3,4,5,6,7,2,3,4,5 right to left. // First remove whitespace and periods. Normal formatting is: // 1234.56.78903 input2 = StringUtils.remove(input, " "); input2 = StringUtils.remove(input2, "."); // 11 digits, numbers only if (input2.length() != length || !StringUtils.isNumeric(input2)) return new ValidationResult(false, BSResources.get("validation.sortCodeNumber", getLabel(), length)); int lastDigit = Character.getNumericValue(input2.charAt(input2.length() - 1)); if (getMod11ControlDigit(input2) != lastDigit) return new ValidationResult(false, "Kontonummer har feil sjekksum"); else return super.validate(input); } else { return super.validate(input); } default: return super.validate(input); } }
From source file:edu.usu.sdl.openstorefront.common.util.Convert.java
/** * Attempts to convert several different formats * * MM/dd/yyyy HH:mm:ss z yyyy-mm-dd HH:mm:ss z yyyy-MM-dd'T'HH:mm:ss.SSS'Z * MM/dd/yyyy yyyy-mm-dd date standard milliseconds * * @param dateString// w w w. j ava2 s .c om * @return date */ public static Date toDate(String dateString) { Date dateConverted = null; if (StringUtils.isNotBlank(dateString)) { try { if (StringUtils.isNumeric(dateString)) { dateConverted = new Date(Long.parseLong(dateString)); } else { String formats[] = { "MM/dd/yyyy HH:mm:ss z ", "yyyy-mm-dd HH:mm:ss z ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z", "MM/dd/yyyy", "yyyy-mm-dd ", }; for (String format : formats) { SimpleDateFormat sdf = new SimpleDateFormat(format); dateConverted = sdf.parse(dateString, new ParsePosition(0)); if (dateConverted != null) { break; } } } } catch (Exception e) { dateConverted = null; } } return dateConverted; }
From source file:com.glaf.core.domain.SystemProperty.java
public int getIntValue() { if (StringUtils.isNotEmpty(value) && StringUtils.isNumeric(value)) { return Integer.parseInt(value); }//from w ww . j a v a2 s . c o m if (StringUtils.isNotEmpty(initValue) && StringUtils.isNumeric(initValue)) { return Integer.parseInt(initValue); } return -1; }
From source file:com.moto.miletus.application.utils.MqttSettingsActivity.java
/** * saveSettings//from w w w . ja v a 2 s. c o m */ private void saveSettings() { String mqttIp = this.mqttIp.getText().toString(); String mqttPort = this.mqttPort.getText().toString(); if (TextUtils.isEmpty(mqttIp)) { this.mqttIp.setError(getString(R.string.field_error)); return; } if (TextUtils.isEmpty(mqttPort) || !StringUtils.isNumeric(mqttPort)) { this.mqttPort.setError(getString(R.string.field_error)); return; } SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(Strings.MQTT_IP, mqttIp); editor.putString(Strings.MQTT_PORT, mqttPort); editor.apply(); }
From source file:com.mythesis.profileanalysis.Utils.java
/** * Method that gets the results form sWebRank and puts them all together in the same file * @param inputDirectory the output directory of sWebRank * @param outputDirectory the directory where im gonna save the new file * @param file the name of the file where im gonna save the results e.g. xxx.txt *//*from w w w . ja v a 2 s . c o m*/ public void getLDAcontent(String inputDirectory, String outputDirectory, String file) { System.out.println("Getting webpages from " + inputDirectory); //Find output paths File root = new File(inputDirectory); File[] contents = root.listFiles(); List<String> sWebRanklevels = new ArrayList<>(); for (File f : contents) { if (f.getAbsolutePath().contains("level")) sWebRanklevels.add(f.getAbsolutePath()); } //Find all query paths //for now this only works for bing search engine List<String> totalQueries = new ArrayList<>(); for (String s : sWebRanklevels) { File level = new File(s); File[] queries = level.listFiles(); for (File f : queries) { if (!f.getAbsolutePath().contains("txt")) totalQueries.add(f.getAbsolutePath() + "\\" + "bing" + "\\"); } } int totalDocs = 0; //String totalContent=""; List<String> totalContent = new ArrayList<>(); String webpage = ""; for (String s : totalQueries) { File level = new File(s); File[] docPaths = level.listFiles(); for (File f : docPaths) { String str = f.getAbsolutePath(); if (StringUtils.isNumeric(str.substring(str.lastIndexOf("\\") + 1))) { File webPagePath = new File(str + "\\html_parse_content.txt"); try { if (!directoryContains(f, webPagePath)) { webPagePath = new File(f.getAbsolutePath() + "\\youtube_content.txt"); if (!directoryContains(f, webPagePath)) continue; webpage = readFileToString(webPagePath).replace("\n", "").replace("\r", ""); YoutubeContent ytc = new YoutubeContent(); webpage = ytc.parse(webpage); } else { webpage = readFileToString(webPagePath); } } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); } if (webpage.isEmpty()) continue; totalContent.add(webpage); } } } Set<String> hs = new HashSet<>(); hs.addAll(totalContent); totalContent.clear(); totalContent.addAll(hs); //find for each word the documents that appears in Map<String, HashSet<Integer>> wordsToSetOfDocsMap = new TreeMap<>(); int size = totalContent.size(); for (int d = 0; d < size; d++) { String doc = totalContent.get(d); String[] words = doc.trim().split(" "); int length = words.length; for (int w = 0; w < length; w++) { String word = words[w]; if (!wordsToSetOfDocsMap.containsKey(word)) { wordsToSetOfDocsMap.put(word, new HashSet<Integer>()); } HashSet<Integer> setOfDocs = wordsToSetOfDocsMap.get(word); setOfDocs.add(d); wordsToSetOfDocsMap.put(word, setOfDocs); } } //remove frequent words totalContent = removeFrequentWords(wordsToSetOfDocsMap, totalContent); //remove infrequent words totalContent = removeInfrequentWords(wordsToSetOfDocsMap, totalContent); //store results for (int i = 0; i < totalContent.size(); i++) { String content = totalContent.get(i).replaceAll("\\s+", " ").trim(); totalContent.set(i, content); } totalDocs = totalContent.size(); totalContent.add(0, String.valueOf(totalDocs)); String LDAdirectory = outputDirectory; File ldaContent = new File(LDAdirectory + file); try { FileUtils.writeLines(ldaContent, totalContent); } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("I stored the results in " + outputDirectory + file); }
From source file:com.nike.cerberus.endpoints.admin.GetSDBMetaData.java
/** * Validates that the offset value is a number that is >= 0 * @param offsetQueryValue/*from ww w . j a v a 2 s . c o m*/ */ protected void validateOffsetQuery(String offsetQueryValue) { if (!StringUtils.isNumeric(offsetQueryValue)) { throw ApiException.newBuilder() .withApiErrors(new ApiErrorBase(DefaultApiError.INVALID_QUERY_PARAMS.getName(), DefaultApiError.INVALID_QUERY_PARAMS.getErrorCode(), String.format("offset query param must be an int >= 0, '%s' given", offsetQueryValue), DefaultApiError.INVALID_QUERY_PARAMS.getHttpStatusCode())) .build(); } }
From source file:gov.nih.nci.caintegrator.application.analysis.GenePatternHelper.java
private boolean isParameterValid(ParameterInfo parameterInfo) { if (INTEGER_TYPE.equals(getAttributeValue(parameterInfo, TYPE_ATTRIBUTE)) && !StringUtils.isEmpty(parameterInfo.getValue())) { String[] choiceEntries = parameterInfo.getValue().split(";"); for (String choiceEntry : choiceEntries) { String[] parts = choiceEntry.split("=", 2); if (parts.length >= 1 && !StringUtils.isNumeric(parts[0])) { return false; }/* ww w .j a va2s.com*/ } } if (getAttributeValue(parameterInfo, TYPE_ATTRIBUTE) == null) { return false; } return true; }
From source file:com.galenframework.speclang2.reader.specs.SpecImageProcessor.java
private Integer parseIntegerParameter(String name, String value) { if (StringUtils.isNumeric(value)) { return Integer.parseInt(value); } else//ww w . jav a 2 s . c om throw new SyntaxException(name + " parameter should be integer: " + value); }
From source file:com.thruzero.common.jsf.support.beans.dialog.AbstractAboutApplicationBean.java
public String getJarRows() { StringBuffer result = new StringBuffer(); try {/*w w w. jav a 2 s .c o m*/ File webInfDir = FacesUtils.getWebInfDir(); if (webInfDir != null) { File libDir = new File(webInfDir, "lib"); String[] extensions = { "jar" }; @SuppressWarnings("unchecked") // FileUtils isn't generic Collection<File> jarFiles = FileUtils.listFiles(libDir, extensions, false); StringMap aboutLibs = ConfigLocator.locate() .getSectionAsStringMap(AboutBoxConfigKeys.ABOUT_LIBS_SECTION); if (aboutLibs == null) { result.append("<br/><span style=\"color:red;\">The " + AboutBoxConfigKeys.ABOUT_LIBS_SECTION + " config section was not found.</span>"); } else { for (File jarFile : jarFiles) { String version = StringUtils.substringAfterLast(jarFile.getName(), "-"); version = StringUtils.remove(version, ".jar"); String aboutKey = StringUtils.substringBeforeLast(jarFile.getName(), "-"); // make sure it's the full version number (e.g., "hibernate-c3p0-3.5.0-Final" at this point will be "Final". Need to back up a segment to get the version number. String versComp = StringUtils.substringBefore(version, "."); if (!StringUtils.isNumeric(versComp)) { String version2 = StringUtils.substringAfterLast(aboutKey, "-"); versComp = StringUtils.substringBefore(version2, "."); if (StringUtils.isNumeric(versComp)) { aboutKey = StringUtils.substringBeforeLast(aboutKey, "-"); version = version2 + "-" + version; } else { continue; // give up on this one } } // get config value for this jar file if (StringUtils.isNotEmpty(aboutKey) && StringUtils.isNotEmpty(version) && aboutLibs.containsKey(aboutKey)) { String href = aboutLibs.get(aboutKey); aboutKey = StringUtils.remove(aboutKey, "-core"); result.append(TableUtils.createSimpleFormRow(aboutKey, href, version)); } } } } } catch (Exception e) { // don't let the about box crash the app } return result.toString(); }
From source file:com.galenframework.config.GalenConfig.java
public int getLogLevel() { String value = readProperty(GalenProperty.GALEN_LOG_LEVEL); if (StringUtils.isNumeric(value)) { return Integer.parseInt(value); } else//from ww w.jav a 2 s .c om return 10; }