Package com.gengoai.string
Interface CharMatcher
-
- All Superinterfaces:
Predicate<Character>
,Serializable
,SerializablePredicate<Character>
- 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 CharMatcher extends SerializablePredicate<Character>
A
CharMatcher
is aSerializablePredicate
forCharacter
s testing if characters match a specific pattern. Additionally, methods exist to match against all, any, or no part of aCharSequence
.- Author:
- David B. Bracewell
-
-
Field Summary
Fields Modifier and Type Field Description static CharMatcher
Any
Matches any characterstatic CharMatcher
Ascii
Matches any ascii character (int value<=
127)static CharMatcher
BreakingWhiteSpace
Matches breaking whitespace.static CharMatcher
Digit
Matches digits defined usingCharacter.isDigit(char)
static CharMatcher
Ideographic
Matches ideographic characters defined usingCharacter.isIdeographic(int)
static CharMatcher
Letter
Matches letters defined usingCharacter.isLetter(char)
static CharMatcher
LetterOrDigit
Matches letters or digits usingCharacter.isLetterOrDigit(char)
static CharMatcher
LowerCase
Matches lower case usingCharacter.isLowerCase(char)
static CharMatcher
None
Matches nothingstatic CharMatcher
Punctuation
Matches punctuation.static CharMatcher
UpperCase
Matches upper case usingCharacter.isUpperCase(char)
static CharMatcher
WhiteSpace
Matches whitespace usingCharacter.isWhitespace(char)
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default CharMatcher
and(@NonNull SerializablePredicate<? super Character> other)
static CharMatcher
anyOf(@NonNull CharSequence characters)
Matches against any character in the given sequence.sdefault int
findIn(@NonNull CharSequence sequence)
Finds the first character in the given sequence that matches.default int
findIn(@NonNull CharSequence sequence, int offset)
Finds the first character in the given sequence that matches.default boolean
matchesAllOf(@NonNull CharSequence sequence)
Checks if the entire CharSequence matches.default boolean
matchesAnyOf(@NonNull CharSequence sequence)
Checks if any of the CharSequence matches.default boolean
matchesNoneOf(@NonNull CharSequence sequence)
Checks if none of the CharSequence matches.default CharMatcher
negate()
default CharMatcher
or(@NonNull SerializablePredicate<? super Character> other)
default String
trimFrom(@NonNull CharSequence sequence)
Removes matches from the beginning and end of the string.default String
trimLeadingFrom(@NonNull CharSequence sequence)
Removes matches from the beginning of the string until a non-match is found.default String
trimTrailingFrom(@NonNull CharSequence sequence)
Trims matches from the end of the string until a non-match is found.-
Methods inherited from interface com.gengoai.function.SerializablePredicate
and, or
-
-
-
-
Field Detail
-
Any
static final CharMatcher Any
Matches any character
-
Ascii
static final CharMatcher Ascii
Matches any ascii character (int value<=
127)
-
Digit
static final CharMatcher Digit
Matches digits defined usingCharacter.isDigit(char)
-
Ideographic
static final CharMatcher Ideographic
Matches ideographic characters defined usingCharacter.isIdeographic(int)
-
Letter
static final CharMatcher Letter
Matches letters defined usingCharacter.isLetter(char)
-
LetterOrDigit
static final CharMatcher LetterOrDigit
Matches letters or digits usingCharacter.isLetterOrDigit(char)
-
LowerCase
static final CharMatcher LowerCase
Matches lower case usingCharacter.isLowerCase(char)
-
None
static final CharMatcher None
Matches nothing
-
Punctuation
static final CharMatcher Punctuation
Matches punctuation.
-
UpperCase
static final CharMatcher UpperCase
Matches upper case usingCharacter.isUpperCase(char)
-
WhiteSpace
static final CharMatcher WhiteSpace
Matches whitespace usingCharacter.isWhitespace(char)
-
BreakingWhiteSpace
static final CharMatcher BreakingWhiteSpace
Matches breaking whitespace.
-
-
Method Detail
-
anyOf
static CharMatcher anyOf(@NonNull @NonNull CharSequence characters)
Matches against any character in the given sequence.s- Parameters:
characters
- the characters- Returns:
- the char matcher
-
and
default CharMatcher and(@NonNull @NonNull SerializablePredicate<? super Character> other)
- Specified by:
and
in interfaceSerializablePredicate<Character>
-
findIn
default int findIn(@NonNull @NonNull CharSequence sequence)
Finds the first character in the given sequence that matches.- Parameters:
sequence
- the sequence- Returns:
- the index of the first match or -1 if none
-
findIn
default int findIn(@NonNull @NonNull CharSequence sequence, int offset)
Finds the first character in the given sequence that matches.- Parameters:
sequence
- the sequenceoffset
- the starting position to search in the CharSequence- Returns:
- the index of the first match or -1 if none
-
matchesAllOf
default boolean matchesAllOf(@NonNull @NonNull CharSequence sequence)
Checks if the entire CharSequence matches.- Parameters:
sequence
- the sequence- Returns:
- True if this matcher matches all of the given CharSequence
-
matchesAnyOf
default boolean matchesAnyOf(@NonNull @NonNull CharSequence sequence)
Checks if any of the CharSequence matches.- Parameters:
sequence
- the sequence- Returns:
- True if this matcher matches any of the given CharSequence
-
matchesNoneOf
default boolean matchesNoneOf(@NonNull @NonNull CharSequence sequence)
Checks if none of the CharSequence matches.- Parameters:
sequence
- the sequence- Returns:
- True if this matcher matches none of the given CharSequence
-
negate
default CharMatcher negate()
-
or
default CharMatcher or(@NonNull @NonNull SerializablePredicate<? super Character> other)
- Specified by:
or
in interfaceSerializablePredicate<Character>
-
trimFrom
default String trimFrom(@NonNull @NonNull CharSequence sequence)
Removes matches from the beginning and end of the string.- Parameters:
sequence
- the sequence- Returns:
- the trimmed string
-
trimLeadingFrom
default String trimLeadingFrom(@NonNull @NonNull CharSequence sequence)
Removes matches from the beginning of the string until a non-match is found.- Parameters:
sequence
- the sequence- Returns:
- the trimmed string
-
trimTrailingFrom
default String trimTrailingFrom(@NonNull @NonNull CharSequence sequence)
Trims matches from the end of the string until a non-match is found.- Parameters:
sequence
- the sequence- Returns:
- the trimmed string
-
-