List of usage examples for com.google.common.base CharMatcher matchesAllOf
public boolean matchesAllOf(CharSequence sequence)
From source file:com.google.gerrit.server.index.FieldDef.java
private static String checkName(String name) { CharMatcher m = CharMatcher.anyOf("abcdefghijklmnopqrstuvwxyz0123456789_"); checkArgument(name != null && m.matchesAllOf(name), "illegal field name: %s", name); return name;// w w w. java 2s .c om }
From source file:apps.Source2XML.java
/** * /*from w w w . j a v a 2s . c o m*/ * A good word should start from the letter: it may contain a letter, * a dash, or an apostrophe. * * @param text input * * @return true if a good word. */ protected static boolean isGoodWord(String text) { if (text.isEmpty()) return false; // CharMatcher m = (CharMatcher.JAVA_LETTER_OR_DIGIT).and(CharMatcher.ASCII); m = m.or(CharMatcher.is('-')); m = m.or(CharMatcher.is('\'')); return m.matchesAllOf(text); }
From source file:org.mayocat.context.RequestContextInitializer.java
private static Predicate<String> matchesAllOf(final CharMatcher charMatcher) { return new Predicate<String>() { public boolean apply(String string) { return charMatcher.matchesAllOf(string); }/*from ww w . j a v a 2 s .c o m*/ }; }
From source file:co.cask.cdap.data.stream.StreamUtils.java
/** * Finds the current generation if of a stream. It scans the stream directory to look for largest generation * number in directory name./* w w w .j ava 2 s. c om*/ * * @param streamLocation location to scan for generation id * @return the generation id */ public static int getGeneration(Location streamLocation) throws IOException { // Default generation is 0. int genId = 0; CharMatcher numMatcher = CharMatcher.inRange('0', '9'); List<Location> locations = streamLocation.list(); if (locations == null) { return 0; } for (Location location : locations) { if (numMatcher.matchesAllOf(location.getName()) && location.isDirectory()) { int id = Integer.parseInt(location.getName()); if (id > genId) { genId = id; } } } return genId; }
From source file:com.google.devtools.build.lib.syntax.StringModule.java
private static boolean matches(String str, CharMatcher matcher, boolean requiresAtLeastOneCasedLetter) { if (str.isEmpty()) { return false; } else if (!requiresAtLeastOneCasedLetter) { return matcher.matchesAllOf(str); }//from w w w. jav a2s . co m int casedLetters = 0; for (char current : str.toCharArray()) { if (!matcher.matches(current)) { return false; } else if (requiresAtLeastOneCasedLetter && CASED.matches(current)) { ++casedLetters; } } return casedLetters > 0; }
From source file:org.jclouds.azurecompute.arm.compute.config.AzureNameValidator.java
public void validate(String name) { if (name == null || name.length() < minLength || name.length() > maxLength) throw exception(name, "Can't be null or empty. Length must be " + minLength + " to " + maxLength + " symbols"); if (!CharMatcher.JAVA_LETTER_OR_DIGIT.matches(name.charAt(0))) throw exception(name, "Should start with letter/number"); CharMatcher range = getAcceptableRange(); if (!range.matchesAllOf(name)) throw exception(name, "Should have lowercase or uppercase ASCII letters, numbers, dashes, underscores and periods"); }
From source file:org.jclouds.predicates.validators.DnsNameValidator.java
public void validate(String name) { if (name == null || name.length() < min || name.length() > max) throw exception(name, "Can't be null or empty. Length must be " + min + " to " + max + " symbols."); if (CharMatcher.JAVA_LETTER_OR_DIGIT.indexIn(name) != 0) throw exception(name, "Should start with letter/number"); if (!name.toLowerCase().equals(name)) throw exception(name, "Should be only lowercase"); /*/*from www .jav a2 s .c o m*/ * The name must be a valid DNS name. From wikipedia: "The characters allowed in a label are a * subset of the ASCII character set, a and includes the characters a through z, A through Z, * digits 0 through 9". From Azure: Every Dash (-) Must Be Immediately Preceded and Followed * by a Letter or Number. */ CharMatcher range = getAcceptableRange(); if (!range.matchesAllOf(name)) throw exception(name, "Should have lowercase ASCII letters, " + "numbers, or dashes"); }
From source file:com.opengamma.strata.collect.ArgChecker.java
/** * Checks that the specified argument is non-null and only contains the specified characters. * <p>/*w w w . ja v a2 s. c o m*/ * Given the input argument, this returns only if it is non-null and matches * the {@link CharMatcher} specified. * For example, in a constructor: * <pre> * this.name = ArgChecker.matches(REGEX_NAME, 1, Integer.MAX_VALUE, name, "name", "[A-Z]+"); * </pre> * * @param matcher the matcher to check against, not null * @param minLength the minimum length to allow * @param maxLength the minimum length to allow * @param argument the argument to check, null throws an exception * @param name the name of the argument to use in the error message, not null * @param equivalentRegex the equivalent regular expression pattern * @return the input {@code argument}, not null * @throws IllegalArgumentException if the input is null or empty */ public static String matches(CharMatcher matcher, int minLength, int maxLength, String argument, String name, String equivalentRegex) { notNull(matcher, "pattern"); notNull(argument, name); if (argument.length() < minLength || argument.length() > maxLength || !matcher.matchesAllOf(argument)) { throw new IllegalArgumentException(matchesMsg(matcher, name, argument, equivalentRegex)); } return argument; }
From source file:com.opengamma.strata.collect.TypedString.java
/** * Creates an instance, validating the name against a matcher. * <p>/* w w w . ja v a2 s . c om*/ * In most cases, a {@link CharMatcher} will be faster than a regex {@link Pattern}, * typically by over an order of magnitude. * * @param name the name, not empty * @param matcher the matcher for validating the name * @param msg the message to use to explain validation failure */ protected TypedString(String name, CharMatcher matcher, String msg) { ArgChecker.notEmpty(name, "name"); ArgChecker.notNull(matcher, "pattern"); ArgChecker.notEmpty(msg, "msg"); if (matcher.matchesAllOf(name) == false) { throw new IllegalArgumentException(msg); } this.name = name; }