private void validatePathName(int p, String name) { if (!PARAM_NAME_REGEX.matcher(name).matches()) { throw parameterError(method, p, "@Path parameter name must match %s. Found: %s", PARAM_URL_REGEX.pattern(), name); } // Verify URL replacement name is actually present in the URL path. if (!relativeUrlParamNames.contains(name)) { throw parameterError(method, p, "URL \"%s\" does not contain \"{%s}\".", relativeUrl, name); } }
public PostgreSQLDataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); if (matcher.find()) { hostName = matcher.group(1); port = Strings.isNullOrEmpty(matcher.group(2)) ? DEFAULT_PORT : Integer.valueOf(matcher.group(2)); schemaName = matcher.group(3); } else { throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern()); } }
Pattern pattern = Pattern.compile(args.get("regexp")); String requiredTagRegexp = args.get("postag_regexp"); boolean negatePos = args.containsKey("negate_pos"); boolean two_groups_regexp = args.containsKey("two_groups_regexp"); String token = patternTokens[tokenPos - 1].getToken(); Matcher matcher = pattern.matcher(token); if ((matcher.groupCount() != 1) && !(two_groups_regexp)) { throw new RuntimeException("Got " + matcher.groupCount() + " groups for regex '" + pattern.pattern() + "', expected 1"); throw new RuntimeException("Got " + matcher.groupCount() + " groups for regex '" + pattern.pattern() + "', expected 2"); if (matcher.matches()) { String partialToken = matcher.group(1); if (matcher.groupCount() == 2) {
@Override public void configure(Context context) { String regexString = context.getString(REGEX); Preconditions.checkArgument(!StringUtils.isEmpty(regexString), "Must supply a valid regex string"); regex = Pattern.compile(regexString); regex.pattern(); regex.matcher("").groupCount(); configureSerializers(context); }
private void writeGraphName(Object graphName) throws IOException { boolean isPattern = graphName instanceof Pattern; outputStream.writeBoolean(isPattern); if (isPattern) { final Pattern pattern = (Pattern) graphName; outputStream.writeUTF(pattern.pattern()); outputStream.writeInt(pattern.flags()); } else { outputStream.writeUTF(graphName.toString()); } }
@Override public String getAlbumTitle(URL url) throws MalformedURLException { try { // Attempt to use album title as GID Elements elems = getFirstPage().select("legend"); String title = elems.first().text(); LOGGER.info("Title text: '" + title + "'"); Pattern p = Pattern.compile("^(.*)\\s\\d* image.*$"); Matcher m = p.matcher(title); if (m.matches()) { return getHost() + "_" + getGID(url) + " (" + m.group(1).trim() + ")"; } LOGGER.info("Doesn't match " + p.pattern()); } catch (Exception e) { // Fall back to default album naming convention LOGGER.warn("Failed to get album title from " + url, e); } return super.getAlbumTitle(url); }
private void initialize() { matcher = null; groupList.clear(); groupList.add(null); Iterator iter = styleMap.keySet().iterator(); String regexp = ""; while (iter.hasNext()) { String nextRegexp = (String)iter.next(); regexp += "|(" + nextRegexp + ")"; // have to compile regexp first so that it will match groupList.add(Pattern.compile(nextRegexp).pattern()); } if (!regexp.equals("")) { matcher = Pattern.compile(regexp.substring(1)).matcher(""); iter = children.values().iterator(); while (iter.hasNext()) { ((LexerNode)iter.next()).initialize(); } } initialized = true; }
public H2DataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); if (matcher.find()) { hostName = matcher.group(1); port = DEFAULT_PORT; schemaName = matcher.group(2); } else { throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern()); } }
@GwtIncompatible // Doubles.tryParse public void testTryParseFailures() { for (String badInput : BAD_TRY_PARSE_INPUTS) { assertThat(badInput) .doesNotMatch( Pattern.compile( Doubles.FLOATING_POINT_PATTERN.pattern(), Doubles.FLOATING_POINT_PATTERN.flags())); assertEquals(referenceTryParse(badInput), Doubles.tryParse(badInput)); assertNull(Doubles.tryParse(badInput)); } }
String apply(String distinguishedName) { if (isDefault) { return distinguishedName; } String result = null; final Matcher m = pattern.matcher(distinguishedName); if (m.matches()) { result = distinguishedName.replaceAll(pattern.pattern(), escapeLiteralBackReferences(replacement, m.groupCount())); } if (toLowerCase && result != null) { result = result.toLowerCase(Locale.ENGLISH); } else if (toUpperCase & result != null) { result = result.toUpperCase(Locale.ENGLISH); } return result; }
public static void validate(final ScimUser user) throws InvalidScimResourceException { Pattern usernamePattern = Pattern.compile("[\\p{L}+0-9+\\-_.@'!]+"); if (!hasText(user.getUserName())) { throw new InvalidScimResourceException("A username must be provided."); } if (OriginKeys.UAA.equals(user.getOrigin()) && !usernamePattern.matcher(user.getUserName()).matches()) { throw new InvalidScimResourceException("Username must match pattern: " + usernamePattern.pattern()); } if (user.getEmails() == null || user.getEmails().size() != 1) { throw new InvalidScimResourceException("Exactly one email must be provided."); } for (ScimUser.Email email : user.getEmails()) { if (email == null || email.getValue() == null || email.getValue().isEmpty()) { throw new InvalidScimResourceException("An email must be provided."); } } } }
/** * Verifies that the given {@code CharSequence} contains the given regular expression. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param regex the regular expression to find in the actual {@code CharSequence}. * @throws NullPointerException if the given pattern is {@code null}. * @throws PatternSyntaxException if the regular expression's syntax is invalid. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the actual {@code CharSequence} does not contain the given regular expression. */ public void assertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex) { checkRegexIsNotNull(regex); assertNotNull(info, actual); Pattern pattern = Pattern.compile(regex.toString()); Matcher matcher = pattern.matcher(actual); if (!matcher.find()) throw failures.failure(info, shouldContainPattern(actual, pattern.pattern())); }
public OracleDataSourceMetaData(final String url) { Matcher matcher = pattern.matcher(url); if (matcher.find()) { hostName = matcher.group(1); port = Strings.isNullOrEmpty(matcher.group(2)) ? DEFAULT_PORT : Integer.valueOf(matcher.group(2)); schemaName = matcher.group(3); } else { throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern()); } }
/** * Checks the given objects for equality. Handles {@link Pattern} and arrays correctly. * * @param left * @param right * @return */ private boolean isEqual(Object left, Object right) { if (left == null) { return right == null; } if (Pattern.class.isInstance(left)) { if (!Pattern.class.isInstance(right)) { return false; } Pattern leftPattern = (Pattern) left; Pattern rightPattern = (Pattern) right; return leftPattern.pattern().equals(rightPattern.pattern()) // && leftPattern.flags() == rightPattern.flags(); } return ObjectUtils.nullSafeEquals(left, right); }