/** * Returns {@code true} if the exclusion {@link Pattern} at index {@code patternIndex} * matches the supplied candidate {@code String}. */ @Override protected boolean matchesExclusion(String candidate, int patternIndex) { Matcher matcher = this.compiledExclusionPatterns[patternIndex].matcher(candidate); return matcher.matches(); }
/** * Extracts the hostname from a "host:port" address string. * @param address address string to parse * @return hostname or null if the given address is incorrect */ public static String getHost(String address) { Matcher matcher = HOST_PORT_PATTERN.matcher(address); return matcher.matches() ? matcher.group(1) : null; }
static boolean isJava8BelowUpdate45(String jvmVersion) { Matcher matcher = JAVA_8_RELEASE_VERSION_SCHEME.matcher(jvmVersion); if (matcher.matches()) { int update = Integer.parseInt(matcher.group(1)); return update < 45; } matcher = JAVA_8_DEV_VERSION_SCHEME.matcher(jvmVersion); if (matcher.matches()) { int update = Integer.parseInt(matcher.group(1)); return update < 45; } matcher = Pattern.compile("1\\.8\\.0-b\\d+").matcher(jvmVersion); return matcher.matches(); }
static List<File> matchingFiles( File fileWithRegexInName ) { File parent = fileWithRegexInName.getAbsoluteFile().getParentFile(); if ( parent == null || !parent.exists() ) { throw new IllegalArgumentException( "Directory of " + fileWithRegexInName + " doesn't exist" ); } final Pattern pattern = Pattern.compile( fileWithRegexInName.getName() ); List<File> files = new ArrayList<>(); for ( File file : parent.listFiles() ) { if ( pattern.matcher( file.getName() ).matches() ) { files.add( file ); } } return files; }
public void bindStringRegex(String var, String regex) { // Enforce requirements on variable names ($alphanumeric_) if (!STRING_REGEX_VAR_NAME_PATTERN.matcher(var).matches()) { throw new IllegalArgumentException("StringRegex binding error: Invalid variable name " + var); } Pattern varPattern = Pattern.compile(Pattern.quote(var)); String replace = Matcher.quoteReplacement(regex); stringRegexVariables.put(var, new Pair<>(varPattern, replace)); }
/** * See {@link hudson.FilePath#isAbsolute(String)}. * @param path String representing <code> Platform Specific </code> (unlike FilePath, which may get Platform agnostic paths), may not be null * @return true if String represents absolute path on this platform, false otherwise */ public static boolean isAbsolute(String path) { Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*"); return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches(); }
public void execute(TaskListener listener) { int numFiles = 0; File root = new File(getRootDir(), FINGERPRINTS_DIR_NAME); File[] files1 = root.listFiles(f -> f.isDirectory() && f.getName().length()==2); if(files1!=null) { for (File file1 : files1) { File[] files2 = file1.listFiles(f -> f.isDirectory() && f.getName().length()==2); for(File file2 : files2) { File[] files3 = file2.listFiles(f -> f.isFile() && FINGERPRINT_FILE_PATTERN.matcher(f.getName()).matches()); for(File file3 : files3) { if(check(file3, listener)) numFiles++; } deleteIfEmpty(file2); } deleteIfEmpty(file1); } } listener.getLogger().println("Cleaned up "+numFiles+" records"); }
public List<IndexedWord> getAllNodesByPartOfSpeechPattern(String pattern) { Pattern p = Pattern.compile(pattern); List<IndexedWord> nodes = new ArrayList<>(); for (IndexedWord vertex : vertexSet()) { String pos = vertex.tag(); if ((pos == null && pattern == null) || pos != null && p.matcher(pos).matches()) { nodes.add(vertex); } } return nodes; }
/** * Extracts the port number from a "host:port" address string. * @param address address string to parse * @return port number or null if the given address is incorrect */ public static Integer getPort(String address) { Matcher matcher = HOST_PORT_PATTERN.matcher(address); return matcher.matches() ? Integer.parseInt(matcher.group(2)) : null; }
/** * Returns {@code true} if the {@link Pattern} at index {@code patternIndex} * matches the supplied candidate {@code String}. */ @Override protected boolean matches(String pattern, int patternIndex) { Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern); return matcher.matches(); }
/** * @return {@code true} if application runs on a mobile device */ public static boolean isMobileDevice() { // RegEx pattern from detectmobilebrowsers.com (public domain) String pattern = "(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec" + "|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)" + "i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)" + "|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk"; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(Window.Navigator.getUserAgent().toLowerCase()); return m.matches(); }
private List<String> getDispatcherNames(Properties configuration) { List<String> dispatcherNames = new ArrayList<String>(); for (Object propertyName : configuration.keySet()) { Matcher matcher = REACTOR_NAME_PATTERN.matcher((String) propertyName); if (matcher.matches()) { dispatcherNames.add(matcher.group(1)); } } return dispatcherNames; }
private static String[] splitTokenize(Pattern splitRegexp, Pattern ignoreRegexp, String cWord) { String[] bits = splitRegexp.split(cWord); if (ignoreRegexp != null) { List<String> keepBits = new ArrayList<>(bits.length); for (String bit : bits) { if ( ! ignoreRegexp.matcher(bit).matches()) { keepBits.add(bit); } } if (keepBits.size() != bits.length) { bits = new String[keepBits.size()]; keepBits.toArray(bits); } } return bits; }
/** * Returns all nodes of type {@link edu.stanford.nlp.ling.IndexedWord * IndexedWord} in this {@code SemanticGraph} having the given word or * regex, or returns empty list if no such found. */ public List<IndexedWord> getAllNodesByWordPattern(String pattern) { Pattern p = Pattern.compile(pattern); List<IndexedWord> nodes = new ArrayList<>(); for (IndexedWord vertex : vertexSet()) { String w = vertex.word(); if ((w == null && pattern == null) || w != null && p.matcher(w).matches()) { nodes.add(vertex); } } return nodes; }