WordTokenizer implements Tokenizer { public boolean onlyLettersOrDigits(final @NonNull CharSequence input, final int numCharsToCheck, final int start) { if (start < 0 || start > input.length()) { return false; } for (int i = 0; i < numCharsToCheck; i++) { int positionToCheck = start + i; if (positionToCheck >= input.length()) { return false; } char charToCheck = input.charAt(positionToCheck); if (!Character.isLetterOrDigit(charToCheck)) { return false; } } return true; } WordTokenizer();  WordTokenizer(final @NonNull WordTokenizerConfig config); @Override int findTokenStart(final @NonNull Spanned text, final int cursor); @Override int findTokenEnd(final @NonNull Spanned text, final int cursor); boolean isValidMention(final @NonNull Spanned text, final int start, final int end); @Override @NonNull Spanned terminateToken(final @NonNull Spanned text); boolean isExplicitChar(final char c); boolean isWordBreakingChar(final char c); boolean isExplicit(final @NonNull CharSequence text, final int cursor); char getExplicitChar(final @NonNull CharSequence text, final int cursor); boolean containsExplicitChar(final @NonNull CharSequence input); boolean containsWordBreakingChar(final @NonNull CharSequence input); boolean onlyLettersOrDigits(final @NonNull CharSequence input, final int numCharsToCheck, final int start);  }
@Test public void testHasThreeCharactersOrDigits() { assertFalse(mTokenizer.onlyLettersOrDigits("123", 3, -1)); assertTrue(mTokenizer.onlyLettersOrDigits("1b3", 3, 0)); assertFalse(mTokenizer.onlyLettersOrDigits("1b3", 3, 1)); assertFalse(mTokenizer.onlyLettersOrDigits("1b3", 3, 2)); assertFalse(mTokenizer.onlyLettersOrDigits("1b3", 3, 4)); assertFalse(mTokenizer.onlyLettersOrDigits("1 a", 3, 0)); assertFalse(mTokenizer.onlyLettersOrDigits("1a ", 3, 0)); assertFalse(mTokenizer.onlyLettersOrDigits(" 1a", 3, 1)); assertFalse(mTokenizer.onlyLettersOrDigits("a'1", 3, 0)); assertTrue(mTokenizer.onlyLettersOrDigits("Jon Caveman", 3, 4)); }