List of usage examples for com.google.common.base CharMatcher JAVA_LETTER_OR_DIGIT
CharMatcher JAVA_LETTER_OR_DIGIT
To view the source code for com.google.common.base CharMatcher JAVA_LETTER_OR_DIGIT.
Click Source Link
From source file:com.google.dart.tools.ui.internal.cleanup.migration.Migrate_1M1_library_CleanUp.java
/** * Converts string literal version of library name into identifier named. *//* ww w .j a v a 2s . c o m*/ private static String mapLibraryName(String name) { name = StringUtils.removeEnd(name, ".dart"); name = CharMatcher.JAVA_LETTER_OR_DIGIT.negate().replaceFrom(name, '_'); return name; }
From source file:apps.Source2XML.java
/** * //ww w . jav a 2 s. 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.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 w w w . j a v a 2 s . com * 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:edu.cmu.lti.oaqa.baseqa.answer.score.AnswerCandidateProvider.java
@Override public boolean match(Answer candidate, Collection<Answer> gs) { Set<String> gsTexts = gs.stream().map(TypeUtil::getCandidateAnswerVariantNames).flatMap(Collection::stream) .map(CharMatcher.JAVA_LETTER_OR_DIGIT::retainFrom).map(String::toLowerCase).collect(toSet()); return TypeUtil.getCandidateAnswerVariantNames(candidate).stream() .map(CharMatcher.JAVA_LETTER_OR_DIGIT::retainFrom).map(String::toLowerCase) .anyMatch(gsTexts::contains); }
From source file:fr.putnami.pwt.plugin.code.client.configuration.java.JavaKeywordAssistHandler.java
private int getCurrentTokenStartIndex(String text, int cursorPos) { int startIndex = cursorPos; while (startIndex > 0) { if (!CharMatcher.JAVA_LETTER_OR_DIGIT.matches(text.charAt(startIndex - 1))) { return startIndex; }/*w w w. ja v a2 s.c o m*/ startIndex--; } return startIndex; }
From source file:iterator.view.Details.java
public void setDetails() { StringBuilder html = new StringBuilder("<html>"); String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, Optional.fromNullable(ifs.getName()).or(IFS.UNTITLED)); String words = CharMatcher.JAVA_LETTER_OR_DIGIT.negate().replaceFrom(name, ' '); html.append("<a name=\"top\"></a>").append(String.format("<h1 id=\"title\">IFS %s</h1>", words)); if (ifs.isEmpty()) { html.append("<h2>Empty</h2>"); } else {/*www. ja v a 2 s . c o m*/ int i = 0; int columns = (int) Math.floor((float) getWidth() / 350f); html.append("<table>"); for (Transform t : Ordering.from(IFS.IDENTITY).immutableSortedCopy(ifs)) { if (i % columns == 0 && i != 0) html.append("</tr>"); if (i % columns == 0) html.append("<tr>"); html.append("<td>").append("<table class=\"ifs\" width=\"250px\">"); double[] matrix = new double[6]; t.getTransform().getMatrix(matrix); Color c = Color.WHITE; if (controller.isColour()) { if (controller.hasPalette()) { c = controller.getColours().get(i % controller.getPaletteSize()); } else { c = Color.getHSBColor((float) i / (float) ifs.size(), 0.8f, 0.8f); } } String transform = String.format( "<tr class=\"transform\">" + "<td class=\"id\">%02d</td>" + "<td class=\"bracketl\" rowspan=\"2\"> </td>" + "<td class=\"matrixr1\" align=\"right\">%.3f</td>" + "<td class=\"matrixr1\" align=\"right\">%.3f</td>" + "<td class=\"matrixr1\" align=\"right\">%.3f</td>" + "<td class=\"bracketr\" rowspan=\"2\"> </td>" + "</tr>" + "<tr class=\"transform\">" + "<td class=\"info\">%.1f%%" + "<div style=\"width: 15px; height: 10px; border: 1px solid %s; " + "background: #%02x%02x%02x; padding: 0; margin: 0;\"> </div>" + "</td>" + "<td class=\"matrixr2\" align=\"right\">%.3f</td>" + "<td class=\"matrixr2\" align=\"right\">%.3f</td>" + "<td class=\"matrixr2\" align=\"right\">%.3f</td>" + "</tr>" + "<tr class=\"space\"><td colspan=\"6\"> </td></tr>", t.getId(), matrix[0], matrix[1], matrix[2], 100d * t.getDeterminant() / ifs.getWeight(), controller.isColour() ? "black" : "white", c.getRed(), c.getGreen(), c.getBlue(), matrix[3], matrix[4], matrix[5]); html.append(transform).append("</table>").append("</td>"); i++; } html.append("</tr>").append("</table>"); } html.append("</html>"); setText(html.toString()); repaint(); scrollToReference("top"); }
From source file:org.apache.beam.sdk.transforms.reflect.OnTimerInvokers.java
/** * Generates a {@link OnTimerInvoker} class for the given {@link DoFnSignature} and {@link * TimerId}.//from www . j a v a 2s .com */ private static Class<? extends OnTimerInvoker<?, ?>> generateOnTimerInvokerClass(DoFnSignature signature, String timerId) { Class<? extends DoFn<?, ?>> fnClass = signature.fnClass(); final TypeDescription clazzDescription = new TypeDescription.ForLoadedType(fnClass); final String className = "auxiliary_OnTimer_" + CharMatcher.JAVA_LETTER_OR_DIGIT.retainFrom(timerId); DynamicType.Builder<?> builder = new ByteBuddy() // Create subclasses inside the target class, to have access to // private and package-private bits .with(new NamingStrategy.SuffixingRandom(className) { @Override public String subclass(TypeDescription.Generic superClass) { return super.name(clazzDescription); } }) // class <invoker class> implements OnTimerInvoker { .subclass(OnTimerInvoker.class, ConstructorStrategy.Default.NO_CONSTRUCTORS) // private final <fn class> delegate; .defineField(FN_DELEGATE_FIELD_NAME, fnClass, Visibility.PRIVATE, FieldManifestation.FINAL) // <invoker class>(<fn class> delegate) { this.delegate = delegate; } .defineConstructor(Visibility.PUBLIC).withParameter(fnClass).intercept(new InvokerConstructor()) // public invokeOnTimer(ExtraContextFactory) { // this.delegate.<@OnTimer method>(... pass the right args ...) // } .method(ElementMatchers.named("invokeOnTimer")) .intercept(new InvokeOnTimerDelegation(signature.onTimerMethods().get(timerId))); DynamicType.Unloaded<?> unloaded = builder.make(); @SuppressWarnings("unchecked") Class<? extends OnTimerInvoker<?, ?>> res = (Class<? extends OnTimerInvoker<?, ?>>) unloaded .load(OnTimerInvokers.class.getClassLoader(), ClassLoadingStrategy.Default.INJECTION).getLoaded(); return res; }
From source file:org.unhack.bip38decrypt.Utils.java
public static boolean isValidBTCAddressSubstring(final String substring) { boolean validity = true; if (!CharMatcher.JAVA_LETTER_OR_DIGIT.matchesAllOf(substring) || substring.length() > BTC_ADDRESS_MAX_LENGTH || !CharMatcher.anyOf(ALPHABET).matchesAllOf(substring)) { validity = false;//from w ww. ja v a 2s .co m } return validity; }
From source file:edu.cmu.lti.oaqa.knn4qa.annotators.GoodTokens.java
/** * /*from w w w. ja 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 * @param isStrict if true, use a stricter definition of a good term. * @return true if a good word. */ private boolean isGoodWord(String text, boolean isStrict) { if (text.isEmpty()) return false; CharMatcher m = isStrict ? CharMatcher.JAVA_LETTER : CharMatcher.JAVA_LETTER_OR_DIGIT; if (!m.matches(text.charAt(0))) return false; for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); if (c != '-' && c != '\'' && !m.matches(c)) { return false; } } return true; }