Interface CharPredicate
- All Known Implementing Classes:
CharacterSet
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A predicate of character. More efficient than
Predicate<Character>.- Since:
- 6.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharPredicateEquivalent to the[a-zA-Z]character class.static final CharPredicateCorresponds to all characters.static final CharPredicateCorresponds to the ASCII characters.static final CharPredicateCorresponds to no characters.static final CharPredicateEquivalent to the[a-zA-Z0-9_]character class. -
Method Summary
Modifier and TypeMethodDescriptiondefault CharPredicateand(CharPredicate that) Returns aCharPredicatethat evaluates true if both this andthatpredicate evaluate to true.static CharPredicateReturns a CharPredicate that matches any ofchars.static CharPredicateis(char ch) Returns a CharPredicate for the range of characters:[from, to].static CharPredicateisNot(char ch) Returns a CharPredicate that matches exceptch.default booleanisPrefixOf(CharSequence sequence) Returns true ifsequencestarts with a character that matches this predicate.default booleanisSuffixOf(CharSequence sequence) Returns true ifsequenceends with a character that matches this predicate.default booleanmatchesAllOf(CharSequence sequence) Returnstrueif a character sequence contains only matching BMP characters.default booleanmatchesAnyOf(CharSequence sequence) Returnstrueif a character sequence contains at least one matching BMP character.default booleanmatchesNoneOf(CharSequence sequence) Returnstrueif a character sequence contains no matching BMP characters.static CharPredicateReturns a CharPredicate that matches any ofchars.default CharPredicatenot()Returns the negation of thisCharPredicate.default CharPredicateor(char ch) Returns aCharPredicatethat evaluates true if either this predicate evaluates to true, or the character isch.default CharPredicateor(CharPredicate that) Returns aCharPredicatethat evaluates true if either this orthatpredicate evaluate to true.default CharPredicateReturns aCharPredicatethat evaluates true if either this evaluates to true, or the character is equal to any ofchars.default CharPredicateorRange(char from, char to) Returns aCharPredicatethat evaluates true if either this predicate evaluates to true, or the character is in the range of[from, to].default CharPredicateReturns an equivalentCharPredicatebut pre-computes the results for all ASCII characters.static CharPredicaterange(char from, char to) Returns a CharPredicate for the range of characters:[from, to].booleantest(char ch) Returns true ifchsatisfies this predicate.
-
Field Details
-
ALPHA
Equivalent to the[a-zA-Z]character class. -
WORD
Equivalent to the[a-zA-Z0-9_]character class. -
ASCII
Corresponds to the ASCII characters. -
ANY
Corresponds to all characters. -
NONE
Corresponds to no characters.
-
-
Method Details
-
is
Returns a CharPredicate for the range of characters:[from, to]. -
isNot
Returns a CharPredicate that matches exceptch. -
range
Returns a CharPredicate for the range of characters:[from, to]. -
anyOf
Returns a CharPredicate that matches any ofchars. -
noneOf
Returns a CharPredicate that matches any ofchars. -
test
boolean test(char ch) Returns true ifchsatisfies this predicate. -
or
Returns aCharPredicatethat evaluates true if either this orthatpredicate evaluate to true. -
or
Returns aCharPredicatethat evaluates true if either this evaluates to true, or the character is equal to any ofchars.- Since:
- 9.9.4
-
and
Returns aCharPredicatethat evaluates true if both this andthatpredicate evaluate to true. -
or
Returns aCharPredicatethat evaluates true if either this predicate evaluates to true, or the character isch. -
orRange
Returns aCharPredicatethat evaluates true if either this predicate evaluates to true, or the character is in the range of[from, to]. -
not
Returns the negation of thisCharPredicate. -
matchesAnyOf
Returnstrueif a character sequence contains at least one matching BMP character. Equivalent to!matchesNoneOf(sequence).- Since:
- 7.0
-
matchesAllOf
Returnstrueif a character sequence contains only matching BMP characters.- Since:
- 7.0
-
matchesNoneOf
Returnstrueif a character sequence contains no matching BMP characters. Equivalent to!matchesAnyOf(sequence).- Since:
- 7.0
-
isPrefixOf
Returns true ifsequencestarts with a character that matches this predicate.- Since:
- 9.0
-
isSuffixOf
Returns true ifsequenceends with a character that matches this predicate.- Since:
- 9.0
-
precomputeForAscii
Returns an equivalentCharPredicatebut pre-computes the results for all ASCII characters. Useful if the CharPredicate is used in a hot path.This method is more efficient for ASCII chars than Guava
CharMatcher.precomputed(), and is far cheaper because it only uses two 64-bit long integers to store the pre-computation results.Note that
WORD,anyOf(java.lang.String)andnoneOf(java.lang.String)are already pre-computed for ASCII chars. You may still want to call it on a deeply composedCharPredicatethough.- Since:
- 9.9.4
-