Java Code Examples for org.apache.commons.lang3.math.NumberUtils#isDigits()
The following examples show how to use
org.apache.commons.lang3.math.NumberUtils#isDigits() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectorUtils.java From elucidate-server with MIT License | 6 votes |
public static XYWHFragmentSelector extractXywhFragmentSelector(String str) { if (StringUtils.isNotBlank(str)) { Matcher matcher = XYWH_MATCHER.matcher(str); if (matcher.find()) { String xStr = matcher.group(1); String yStr = matcher.group(2); String wStr = matcher.group(3); String hStr = matcher.group(4); if (NumberUtils.isDigits(xStr) && NumberUtils.isDigits(yStr) && NumberUtils.isDigits(wStr) && NumberUtils.isDigits(hStr)) { XYWHFragmentSelector xywhFragmentSelector = new XYWHFragmentSelector(); xywhFragmentSelector.setX(Integer.parseInt(xStr)); xywhFragmentSelector.setY(Integer.parseInt(yStr)); xywhFragmentSelector.setW(Integer.parseInt(wStr)); xywhFragmentSelector.setH(Integer.parseInt(hStr)); return xywhFragmentSelector; } } } return null; }
Example 2
Source File: SelectorUtils.java From elucidate-server with MIT License | 5 votes |
public static TFragmentSelector extractTFragmentSelector(String str) { if (StringUtils.isNotBlank(str)) { Matcher matcher = T_MATCHER.matcher(str); if (matcher.find()) { String startStr = matcher.group(1); String endStr = matcher.group(3); if (StringUtils.isBlank(startStr) && StringUtils.isNotBlank(endStr)) { startStr = Integer.toString(0); } else if (StringUtils.isNotBlank(startStr) && StringUtils.isBlank(endStr)) { endStr = Integer.toString(Integer.MAX_VALUE); } if (NumberUtils.isDigits(startStr) && NumberUtils.isDigits(endStr)) { TFragmentSelector tFragmentSelector = new TFragmentSelector(); tFragmentSelector.setStart(Integer.parseInt(startStr)); tFragmentSelector.setEnd(Integer.parseInt(endStr)); return tFragmentSelector; } } } return null; }
Example 3
Source File: VcfAnnotation.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
public static VcfAnnotation fromVcfInfo(VcfMetaInfo info) { Annotation.Type type = VcfAnnotation.toAnnotationType(info.getType()); Integer number = null; boolean unbounded = false; boolean perAltAllele = false; boolean perGenotype = false; // Number can be A -> field has one value per alternate allele // Or G -> the field has one value for each possible genotype // Or . -> is unknown, or is unbounded // Or an Integer if (info.getNumber() != null) { if (info.getNumber().equalsIgnoreCase("A")) { perAltAllele = true; } else if (info.getNumber().equalsIgnoreCase("G")) { perGenotype = true; } else if (info.getNumber().equals(".")) { unbounded = true; } else if (NumberUtils.isDigits(info.getNumber())) { number = Integer.parseInt(info.getNumber()); } } return new VcfAnnotation(info.getId(), info.getDescription(), type, number, unbounded, perAltAllele, perGenotype); }
Example 4
Source File: ClassNameUtils.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
public static boolean isAnonymousClass(final String name) { if (!name.contains(INNER_MARK)) { return false; } final int i = name.lastIndexOf(INNER_MARK); if (i < name.length()) { final String s = name.substring(i + 1); return NumberUtils.isDigits(s); } return false; }
Example 5
Source File: RuleEngineUtils.java From smockin with Apache License 2.0 | 5 votes |
static Integer extractJSONFieldListPosition(final String field) { int bracketStart = field.indexOf("["); final String positionStr = field.substring( (bracketStart + 1), (field.length() - 1) ); if (!NumberUtils.isDigits(positionStr)) { return null; } return Integer.valueOf(positionStr); }
Example 6
Source File: Constraint.java From para with Apache License 2.0 | 5 votes |
/** * The 'digits' constraint - field must be a {@link Number} or {@link String} containing digits where the * number of digits in the integral part is limited by 'integer', and the * number of digits for the fractional part is limited * by 'fraction'. * @param integer the max number of digits for the integral part * @param fraction the max number of digits for the fractional part * @return constraint */ public static Constraint digits(final Number integer, final Number fraction) { return new Constraint("digits", digitsPayload(integer, fraction)) { public boolean isValid(Object actualValue) { if (actualValue != null) { if (!((actualValue instanceof Number) || (actualValue instanceof String))) { return false; } else { if (integer != null && fraction != null) { String val = actualValue.toString(); String[] split = val.split("[,.]"); if (!NumberUtils.isDigits(split[0])) { return false; } if (integer.intValue() < split[0].length()) { return false; } if (split.length > 1 && fraction.intValue() < split[1].length()) { return false; } } } } return true; } }; }
Example 7
Source File: FuzzyValues.java From icure-backend with GNU General Public License v2.0 | 5 votes |
/** * Indicates if the submitted text has the format of a SSIN. <br/> * It does <b>NOT</b> check if the SSIN is valid! */ public static boolean isSsin(String text) { if (!NumberUtils.isDigits(text) || text.length() != 11) { return false; } BigInteger checkDigits = new BigInteger(text.substring(9)); BigInteger big97 = new BigInteger("97"); BigInteger modBefore2000 = new BigInteger(text.substring(0, 9)).mod(big97); BigInteger modAfter2000 = new BigInteger("2" + text.substring(0, 9)).mod(big97); return big97.subtract(modBefore2000).equals(checkDigits) || big97.subtract(modAfter2000).equals(checkDigits); }
Example 8
Source File: SiteConfig.java From wind-im with Apache License 2.0 | 5 votes |
/** * <pre> * 1天 * 7天 * 14天 * </pre> * * @return */ public static int getGroupQRExpireDay() { int expireDay = 14; Map<Integer, String> map = getConfigMap(); if (map != null) { String value = map.get(ConfigProto.ConfigKey.GROUP_QR_EXPIRE_TIME_VALUE); if (NumberUtils.isDigits(value)) { int day = Integer.valueOf(value); if (day == 1 || day == 7 || day == 14) { return day; } } } return expireDay; }
Example 9
Source File: VideoResponseFactory.java From prebid-server-java with Apache License 2.0 | 5 votes |
private List<ExtAdPod> adPodsWithTargetingFrom(List<Bid> bids) { final List<ExtAdPod> adPods = new ArrayList<>(); for (Bid bid : bids) { final Map<String, String> targeting = targeting(bid); if (targeting.get("hb_uuid") == null) { continue; } final String impId = bid.getImpid(); final String podIdString = impId.split("_")[0]; if (!NumberUtils.isDigits(podIdString)) { continue; } final Integer podId = Integer.parseInt(podIdString); final ExtResponseVideoTargeting videoTargeting = ExtResponseVideoTargeting.of( targeting.get("hb_pb"), targeting.get("hb_pb_cat_dur"), targeting.get("hb_uuid")); ExtAdPod adPod = adPods.stream() .filter(extAdPod -> extAdPod.getPodid().equals(podId)) .findFirst() .orElse(null); if (adPod == null) { adPod = ExtAdPod.of(podId, new ArrayList<>(), null); adPods.add(adPod); } adPod.getTargeting().add(videoTargeting); } return adPods; }
Example 10
Source File: MainPresenter.java From chat-socket with MIT License | 5 votes |
private boolean verifyInputs() { String listenOnIp = view.getIp(); String portAsString = view.getPort(); if (!NumberUtils.isDigits(portAsString)) { postMessageBox("Port must be a number", MessageType.Error); return false; } else if (StringUtils.isEmpty(listenOnIp)) { postMessageBox("Ip must be not empty", MessageType.Error); return false; } return true; }
Example 11
Source File: TraceGenerator.java From jvm-sandbox-repeater with Apache License 2.0 | 5 votes |
public static boolean isValid(String traceId) { if (StringUtils.isBlank(traceId)) { return false; } if (traceId.length() != 32 && !traceId.endsWith(END_FLAG)) { return false; } return NumberUtils.isDigits(traceId.substring(25, 30)); }
Example 12
Source File: WebannoTsv1Reader.java From webanno with Apache License 2.0 | 4 votes |
/** * Iterate through all lines and get available annotations<br> * First column is sentence number and a blank new line marks end of a sentence<br> * The Second column is the token <br> * The third column is the lemma annotation <br> * The fourth column is the POS annotation <br> * The fifth column is used for Named Entity annotations (Multiple annotations separeted by | * character) <br> * The sixth column is the origin token number of dependency parsing <br> * The seventh column is the function/type of the dependency parsing <br> * eighth and ninth columns are undefined currently */ private void setAnnotations(InputStream aIs, String aEncoding, StringBuilder text, Map<Integer, String> tokens, Map<Integer, String> pos, Map<Integer, String> lemma, Map<Integer, String> namedEntity, Map<Integer, String> dependencyFunction, Map<Integer, Integer> dependencyDependent, List<Integer> firstTokenInSentence) throws IOException { int tokenNumber = 0; boolean first = true; int base = 0; LineIterator lineIterator = IOUtils.lineIterator(aIs, aEncoding); boolean textFound = false; StringBuilder tmpText = new StringBuilder(); while (lineIterator.hasNext()) { String line = lineIterator.next().trim(); if (line.startsWith("#text=")) { text.append(line.substring(6)).append("\n"); textFound = true; continue; } if (line.startsWith("#")) { continue; // it is a comment line } int count = StringUtils.countMatches(line, "\t"); if (line.isEmpty()) { continue; } if (count != 9) { // not a proper TSV file getUimaContext().getLogger().log(Level.INFO, "This is not a valid TSV File"); throw new IOException(fileName + " This is not a valid TSV File"); } StringTokenizer lineTk = new StringTokenizer(line, "\t"); if (first) { tokenNumber = Integer.parseInt(line.substring(0, line.indexOf("\t"))); firstTokenInSentence.add(tokenNumber); first = false; } else { int lineNumber = Integer.parseInt(line.substring(0, line.indexOf("\t"))); if (lineNumber == 1) { base = tokenNumber; firstTokenInSentence.add(base); } tokenNumber = base + Integer.parseInt(line.substring(0, line.indexOf("\t"))); } while (lineTk.hasMoreElements()) { lineTk.nextToken(); String token = lineTk.nextToken(); // for backward compatibility tmpText.append(token).append(" "); tokens.put(tokenNumber, token); lemma.put(tokenNumber, lineTk.nextToken()); pos.put(tokenNumber, lineTk.nextToken()); String ne = lineTk.nextToken(); lineTk.nextToken();// make it compatible with prev WebAnno TSV reader namedEntity.put(tokenNumber, (ne.equals("_") || ne.equals("-")) ? "O" : ne); String dependentValue = lineTk.nextToken(); if (NumberUtils.isDigits(dependentValue)) { int dependent = Integer.parseInt(dependentValue); dependencyDependent.put(tokenNumber, dependent == 0 ? 0 : base + dependent); dependencyFunction.put(tokenNumber, lineTk.nextToken()); } else { lineTk.nextToken(); } lineTk.nextToken(); lineTk.nextToken(); } } if (!textFound) { text.append(tmpText); } }
Example 13
Source File: HelpCommand.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; String command; int pageNumber; int pageHeight; int pageWidth; if (args.length == 0) { command = ""; pageNumber = 1; } else if (NumberUtils.isDigits(args[args.length - 1])) { command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " "); try { pageNumber = NumberUtils.createInteger(args[args.length - 1]); } catch (NumberFormatException exception) { pageNumber = 1; } if (pageNumber <= 0) { pageNumber = 1; } } else { command = StringUtils.join(args, " "); pageNumber = 1; } if (sender instanceof ConsoleCommandSender) { pageHeight = ChatPaginator.UNBOUNDED_PAGE_HEIGHT; pageWidth = ChatPaginator.UNBOUNDED_PAGE_WIDTH; } else { pageHeight = ChatPaginator.CLOSED_CHAT_PAGE_HEIGHT - 1; pageWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; } HelpMap helpMap = Bukkit.getServer().getHelpMap(); HelpTopic topic = helpMap.getHelpTopic(command); if (topic == null) { topic = helpMap.getHelpTopic("/" + command); } if (topic == null) { topic = findPossibleMatches(command); } if (topic == null || !topic.canSee(sender)) { sender.sendMessage(ChatColor.RED + "No help for " + command); return true; } ChatPaginator.ChatPage page = ChatPaginator.paginate(topic.getFullText(sender), pageNumber, pageWidth, pageHeight); StringBuilder header = new StringBuilder(); header.append(ChatColor.YELLOW); header.append("--------- "); header.append(ChatColor.WHITE); header.append("Help: "); header.append(topic.getName()); header.append(" "); if (page.getTotalPages() > 1) { header.append("("); header.append(page.getPageNumber()); header.append("/"); header.append(page.getTotalPages()); header.append(") "); } header.append(ChatColor.YELLOW); for (int i = header.length(); i < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; i++) { header.append("-"); } sender.sendMessage(header.toString()); sender.sendMessage(page.getLines()); return true; }
Example 14
Source File: DataTable.java From bookish with MIT License | 4 votes |
public void parseCSV(String csv) { try { Reader in = new StringReader(csv); CSVFormat format = CSVFormat.EXCEL.withHeader(); CSVParser parser = format.parse(in); this.firstColIsIndex = false; for (CSVRecord record : parser) { if ( !firstColIsIndex && Character.isAlphabetic(record.get(0).charAt(0)) ) { // latch if we see alpha not number firstColIsIndex = true; } List<String> row = new ArrayList<>(); for (int i = 0; i<record.size(); i++) { String v = record.get(i); boolean isInt = false; try { Integer.parseInt(v); isInt = true; } catch (NumberFormatException nfe) { isInt = false; } if ( !isInt && !NumberUtils.isDigits(v) && NumberUtils.isCreatable(v) ) { v = String.format("%.4f",Precision.round(Double.valueOf(v), 4)); } else { v = abbrevString(v, 25); } row.add(v); } rows.add(row); } Set<String> colNames = parser.getHeaderMap().keySet(); if ( !firstColIsIndex ) { colNames.remove(""); // remove index column name } this.colNames.addAll(colNames); } catch (Exception e) { throw new RuntimeException(e); } }
Example 15
Source File: FuzzyValues.java From icure-backend with GNU General Public License v2.0 | 4 votes |
private static boolean isPartiallyFormedYYYYMMDD(String text) { return NumberUtils.isDigits(text) && text.matches("(\\d{4})(0?[1-9]|1[012])?(0?[1-9]|[12][0-9]|3[01])?"); }
Example 16
Source File: ConnectionPresenter.java From chat-socket with MIT License | 4 votes |
private boolean verifyInputs() { String serverIp = view.getServerIp(); String serverPortAsString = view.getServerPort(); return !StringUtils.isEmpty(serverIp) && NumberUtils.isDigits(serverPortAsString); }
Example 17
Source File: CLI.java From blockchain-java with Apache License 2.0 | 4 votes |
/** * 命令行解析入口 */ public void parse() { this.validateArgs(args); try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); switch (args[0]) { case "createblockchain": String createblockchainAddress = cmd.getOptionValue("address"); if (StringUtils.isBlank(createblockchainAddress)) { help(); } this.createBlockchain(createblockchainAddress); break; case "getbalance": String getBalanceAddress = cmd.getOptionValue("address"); if (StringUtils.isBlank(getBalanceAddress)) { help(); } this.getBalance(getBalanceAddress); break; case "send": String sendFrom = cmd.getOptionValue("from"); String sendTo = cmd.getOptionValue("to"); String sendAmount = cmd.getOptionValue("amount"); if (StringUtils.isBlank(sendFrom) || StringUtils.isBlank(sendTo) || !NumberUtils.isDigits(sendAmount)) { help(); } this.send(sendFrom, sendTo, Integer.valueOf(sendAmount)); break; case "createwallet": this.createWallet(); break; case "printaddresses": this.printAddresses(); break; case "printchain": this.printChain(); break; case "h": this.help(); break; default: this.help(); } } catch (Exception e) { log.error("Fail to parse cli command ! ", e); } finally { RocksDBUtils.getInstance().closeDB(); } }
Example 18
Source File: UtilsStaticAnalyzer.java From apogen with Apache License 2.0 | 4 votes |
/** * BETA VERSION: trims the url of the web page, to get an meaningful name for * the PO test the correct use of last index of and extension removal * * @param statesList * @throws MalformedURLException */ public static String getClassNameFromUrl(State state, List<State> statesList) throws MalformedURLException { // new add: check it does not lead to inconsistencies if (state.getStateId().equals("index")) { return toSentenceCase("index"); } String s = state.getUrl(); String toTrim = ""; URL u = new URL(s); toTrim = u.toString(); // retrieves the page name toTrim = toTrim.substring(toTrim.lastIndexOf('/') + 1, toTrim.length()); // removes the php extension if any toTrim = toTrim.replace(".php", ""); // removes the html extension if any toTrim = toTrim.replace(".html", ""); // removes the & and ? if (toTrim.contains("?")) toTrim = toTrim.substring(0, toTrim.indexOf('?')); // camel case the string toTrim = toSentenceCase(toTrim); // check the uniqueness, solve the ambiguity otherwise toTrim = solveAmbiguity(toTrim, statesList); if (toTrim == "") { toTrim = u.getFile(); // retrieves the page name toTrim = toTrim.substring(toTrim.lastIndexOf('/') + 1, toTrim.length()); // removes the php extension if any toTrim = toTrim.replace(".php", ""); // removes the html extension if any toTrim = toTrim.replace(".html", ""); // removes the & and ? if (toTrim.contains("?")) toTrim = toTrim.substring(0, toTrim.indexOf('?')); // camel case the string toTrim = toSentenceCase(toTrim); // check the uniqueness, solve the ambiguity otherwise toTrim = solveAmbiguity(toTrim, statesList); } if (toTrim == "") { return toSentenceCase(state.getStateId()); } if (NumberUtils.isNumber(toTrim) || NumberUtils.isDigits(toTrim)) { return toSentenceCase("PageObject_" + toTrim); } return toTrim; }
Example 19
Source File: IMDBParser.java From drftpd with GNU General Public License v2.0 | 4 votes |
private boolean getInfo() { try { String url = _url + "/reference"; String data = HttpUtils.retrieveHttpAsString(url); if (!data.contains("<meta property='og:type' content=\"video.movie\" />")) { logger.warn("Request for IMDB info for a Tv Show, this is not handled by this plugin. URL:{}", url); return false; } _title = parseData(data, "<meta property='og:title' content=\"", "("); _language = parseData(data, "<td class=\"ipl-zebra-list__label\">Language</td>", "</td>").replaceAll("\\s{2,}", "|"); _country = parseData(data, "<td class=\"ipl-zebra-list__label\">Country</td>", "</td>").replaceAll("\\s{2,}", "|"); _genres = parseData(data, "<td class=\"ipl-zebra-list__label\">Genres</td>", "</td>").replaceAll("\\s{2,}", "|"); _director = parseData(data, "<div class=\"titlereference-overview-section\">\\n\\s+Directors?:", "</div>", false, true).replaceAll("\\s+?,\\s+?", "|"); String rating = parseData(data, "<span class=\"ipl-rating-star__rating\">", "</span>"); if (!rating.equals("N|A") && (rating.length() == 1 || rating.length() == 3) && NumberUtils.isDigits(rating.replaceAll("\\D", ""))) { _rating = Integer.valueOf(rating.replaceAll("\\D", "")); if (rating.length() == 1) { // Rating an even(single digit) number, multiply by 10 _rating = _rating * 10; } String votes = parseData(data, "<span class=\"ipl-rating-star__total-votes\">", "</span>"); if (!votes.equals("N|A") && NumberUtils.isDigits(votes.replaceAll("\\D", ""))) _votes = Integer.valueOf(votes.replaceAll("\\D", "")); } _plot = parseData(data, "<section class=\"titlereference-section-overview\">", "</div>", true, true); Pattern p = Pattern.compile("<a href=\"/title/tt\\d+/releaseinfo\">\\d{2} [a-zA-Z]{3} (\\d{4})"); Matcher m = p.matcher(data); if (m.find() && NumberUtils.isDigits(m.group(1))) { _year = Integer.valueOf(m.group(1)); } String runtime = parseData(data, "<td class=\"ipl-zebra-list__label\">Runtime</td>", "</td>"); if (!runtime.equals("N|A") && NumberUtils.isDigits(runtime.replaceAll("\\D", ""))) { _runtime = Integer.valueOf(runtime.replaceAll("\\D", "")); } } catch (Exception e) { logger.error("", e); return false; } return true; }
Example 20
Source File: GeneralUtils.java From smockin with Apache License 2.0 | 3 votes |
public static int exactVersionNo(String versionNo) { if (versionNo == null) throw new IllegalArgumentException("versionNo is not defined"); versionNo = org.apache.commons.lang3.StringUtils.removeIgnoreCase(versionNo, "-SNAPSHOT"); versionNo = org.apache.commons.lang3.StringUtils.remove(versionNo, "."); if (!NumberUtils.isDigits(versionNo)) throw new IllegalArgumentException("extracted versionNo is not a valid number: " + versionNo); return Integer.valueOf(versionNo); }