/** * Check if any of the collection constraints is a regex to match strings that starts with another * string. */ private static boolean isAnyValueRegexStartsWith(Collection<?> constraints) { for (Object constraint : constraints) { if (isStartsWithRegex(constraint)) { return true; } } return false; }
/** * Creates a regex pattern to match a substring at the beginning of another string. * <p> * If given string is not a regex to match a string at the beginning of another string, then null * is returned. */ private static KeyConstraints cleanRegexStartsWith(KeyConstraints regex) { if (!isStartsWithRegex(regex)) { return null; } // remove all instances of \Q and \E from the remaining text & escape single quotes String literalizedString = ((String) regex.get("$regex")) .replaceAll("([^\\\\])(\\\\E)", "$1") .replaceAll("([^\\\\])(\\\\Q)", "$1") .replaceAll("^\\\\E", "") .replaceAll("^\\\\Q", "") .replaceAll("([^'])'", "$1''") .replaceAll("^'([^'])", "''$1"); regex.put("$regex", literalizedString + ".*"); return regex; }
if (isStartsWithRegex(constraint)) { decider = new Decider() { @Override