/** * 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(); }
/** * Gets the set of unique path parameters used in the given URI. If a parameter is used twice * in the URI, it will only show up once in the set. */ static Set<String> parsePathParameters(String path) { Matcher m = PARAM_URL_REGEX.matcher(path); Set<String> patterns = new LinkedHashSet<>(); while (m.find()) { patterns.add(m.group(1)); } return patterns; }
/** * 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(); }
/** * 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(); }
private void assertDescriptionContainsExpectedPath(ClassPathResource resource, String expectedPath) { Matcher matcher = DESCRIPTION_PATTERN.matcher(resource.getDescription()); assertTrue(matcher.matches()); assertEquals(1, matcher.groupCount()); String match = matcher.group(1); assertEquals(expectedPath, match); }
/** * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used * in Android) requires a successful match in order to generate a {@code MatchResult}: * http://goo.gl/5VQFmC */ private static MatchResult newMatchResult() { Matcher matcher = Pattern.compile(".").matcher("X"); matcher.find(); return matcher.toMatchResult(); }
/** * 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(); }
private static String resolveJarUrl(Class<?> clazz) { URL location = clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class"); if (location != null) { Matcher matcher = Pattern.compile("(jar:file.*-[\\d.]+(-rc[\\d]+|-SNAPSHOT)?.jar)!.*$").matcher(location.toString()); if (matcher.matches()) { return matcher.group(1); } } return null; } }
/** * @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 static void assertContainsRegex(String expectedRegex, String actual) { Pattern pattern = Pattern.compile(expectedRegex); Matcher matcher = pattern.matcher(actual); if (!matcher.find()) { String actualDesc = (actual == null) ? "null" : ('<' + actual + '>'); fail("expected to contain regex:<" + expectedRegex + "> but was:" + actualDesc); } } }
private void handleInstanceGET(HttpExchange httpExchange) throws IOException { Matcher matcher = Pattern.compile("/v2/instances/([^/]+)").matcher(httpExchange.getRequestURI().getPath()); if (matcher.matches()) { mapResponse(httpExchange, requestHandler.getInstance(matcher.group(1))); } else { httpExchange.sendResponseHeaders(HttpServletResponse.SC_NOT_FOUND, 0); } }