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.

@FunctionalInterface public interface CharPredicate
A predicate of character. More efficient than Predicate<Character>.
Since:
6.0
  • Field Details

    • ALPHA

      static final CharPredicate ALPHA
      Equivalent to the [a-zA-Z] character class.
    • WORD

      static final CharPredicate WORD
      Equivalent to the [a-zA-Z0-9_] character class.
    • ASCII

      static final CharPredicate ASCII
      Corresponds to the ASCII characters.
    • ANY

      static final CharPredicate ANY
      Corresponds to all characters.
    • NONE

      static final CharPredicate NONE
      Corresponds to no characters.
  • Method Details

    • is

      static CharPredicate is(char ch)
      Returns a CharPredicate for the range of characters: [from, to].
    • isNot

      static CharPredicate isNot(char ch)
      Returns a CharPredicate that matches except ch.
    • range

      static CharPredicate range(char from, char to)
      Returns a CharPredicate for the range of characters: [from, to].
    • anyOf

      static CharPredicate anyOf(String chars)
      Returns a CharPredicate that matches any of chars.
    • noneOf

      static CharPredicate noneOf(String chars)
      Returns a CharPredicate that matches any of chars.
    • test

      boolean test(char ch)
      Returns true if ch satisfies this predicate.
    • or

      default CharPredicate or(CharPredicate that)
      Returns a CharPredicate that evaluates true if either this or that predicate evaluate to true.
    • or

      default CharPredicate or(String chars)
      Returns a CharPredicate that evaluates true if either this evaluates to true, or the character is equal to any of chars.
      Since:
      9.9.4
    • and

      default CharPredicate and(CharPredicate that)
      Returns a CharPredicate that evaluates true if both this and that predicate evaluate to true.
    • or

      default CharPredicate or(char ch)
      Returns a CharPredicate that evaluates true if either this predicate evaluates to true, or the character is ch.
    • orRange

      default CharPredicate orRange(char from, char to)
      Returns a CharPredicate that evaluates true if either this predicate evaluates to true, or the character is in the range of [from, to].
    • not

      default CharPredicate not()
      Returns the negation of this CharPredicate.
    • matchesAnyOf

      default boolean matchesAnyOf(CharSequence sequence)
      Returns true if a character sequence contains at least one matching BMP character. Equivalent to !matchesNoneOf(sequence).
      Since:
      7.0
    • matchesAllOf

      default boolean matchesAllOf(CharSequence sequence)
      Returns true if a character sequence contains only matching BMP characters.
      Since:
      7.0
    • matchesNoneOf

      default boolean matchesNoneOf(CharSequence sequence)
      Returns true if a character sequence contains no matching BMP characters. Equivalent to !matchesAnyOf(sequence).
      Since:
      7.0
    • isPrefixOf

      default boolean isPrefixOf(CharSequence sequence)
      Returns true if sequence starts with a character that matches this predicate.
      Since:
      9.0
    • isSuffixOf

      default boolean isSuffixOf(CharSequence sequence)
      Returns true if sequence ends with a character that matches this predicate.
      Since:
      9.0
    • precomputeForAscii

      default CharPredicate precomputeForAscii()
      Returns an equivalent CharPredicate but 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) and noneOf(java.lang.String) are already pre-computed for ASCII chars. You may still want to call it on a deeply composed CharPredicate though.

      Since:
      9.9.4