Class CharMatcher.None
- java.lang.Object
-
- com.google.common.base.CharMatcher
-
- com.google.common.base.CharMatcher.FastMatcher
-
- com.google.common.base.CharMatcher.NamedFastMatcher
-
- com.google.common.base.CharMatcher.None
-
- All Implemented Interfaces:
Predicate<java.lang.Character>
,java.util.function.Predicate<java.lang.Character>
- Enclosing class:
- CharMatcher
private static final class CharMatcher.None extends CharMatcher.NamedFastMatcher
Implementation ofCharMatcher.none()
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.base.CharMatcher
CharMatcher.FastMatcher, CharMatcher.NamedFastMatcher, CharMatcher.NegatedFastMatcher, CharMatcher.Whitespace
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static CharMatcher.None
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description private
None()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharMatcher
and(CharMatcher other)
Returns a matcher that matches any character matched by both this matcher andother
.java.lang.String
collapseFrom(java.lang.CharSequence sequence, char replacement)
Returns a string copy of the input character sequence, with each group of consecutive matching BMP characters replaced by a single replacement character.int
countIn(java.lang.CharSequence sequence)
Returns the number of matchingchar
s found in a character sequence.int
indexIn(java.lang.CharSequence sequence)
Returns the index of the first matching BMP character in a character sequence, or-1
if no matching character is present.int
indexIn(java.lang.CharSequence sequence, int start)
Returns the index of the first matching BMP character in a character sequence, starting from a given position, or-1
if no character matches after that position.int
lastIndexIn(java.lang.CharSequence sequence)
Returns the index of the last matching BMP character in a character sequence, or-1
if no matching character is present.boolean
matches(char c)
Determines a true or false value for the given character.boolean
matchesAllOf(java.lang.CharSequence sequence)
Returnstrue
if a character sequence contains only matching BMP characters.boolean
matchesNoneOf(java.lang.CharSequence sequence)
Returnstrue
if a character sequence contains no matching BMP characters.CharMatcher
negate()
Returns a matcher that matches any character not matched by this matcher.CharMatcher
or(CharMatcher other)
Returns a matcher that matches any character matched by either this matcher orother
.java.lang.String
removeFrom(java.lang.CharSequence sequence)
Returns a string containing all non-matching characters of a character sequence, in order.java.lang.String
replaceFrom(java.lang.CharSequence sequence, char replacement)
Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character.java.lang.String
replaceFrom(java.lang.CharSequence sequence, java.lang.CharSequence replacement)
Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement sequence.java.lang.String
trimFrom(java.lang.CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning and from the end of the string.java.lang.String
trimLeadingFrom(java.lang.CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning of the string.java.lang.String
trimTrailingFrom(java.lang.CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the end of the string.-
Methods inherited from class com.google.common.base.CharMatcher.NamedFastMatcher
toString
-
Methods inherited from class com.google.common.base.CharMatcher.FastMatcher
precomputed
-
Methods inherited from class com.google.common.base.CharMatcher
any, anyOf, apply, ascii, breakingWhitespace, digit, forPredicate, inRange, invisible, is, isNot, javaDigit, javaIsoControl, javaLetter, javaLetterOrDigit, javaLowerCase, javaUpperCase, matchesAnyOf, none, noneOf, precomputedInternal, retainFrom, setBits, singleWidth, trimAndCollapseFrom, whitespace
-
-
-
-
Field Detail
-
INSTANCE
static final CharMatcher.None INSTANCE
-
-
Method Detail
-
matches
public boolean matches(char c)
Description copied from class:CharMatcher
Determines a true or false value for the given character.- Specified by:
matches
in classCharMatcher
-
indexIn
public int indexIn(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns the index of the first matching BMP character in a character sequence, or-1
if no matching character is present.The default implementation iterates over the sequence in forward order calling
CharMatcher.matches(char)
for each character.- Overrides:
indexIn
in classCharMatcher
- Parameters:
sequence
- the character sequence to examine from the beginning- Returns:
- an index, or
-1
if no character matches
-
indexIn
public int indexIn(java.lang.CharSequence sequence, int start)
Description copied from class:CharMatcher
Returns the index of the first matching BMP character in a character sequence, starting from a given position, or-1
if no character matches after that position.The default implementation iterates over the sequence in forward order, beginning at
start
, callingCharMatcher.matches(char)
for each character.- Overrides:
indexIn
in classCharMatcher
- Parameters:
sequence
- the character sequence to examinestart
- the first index to examine; must be nonnegative and no greater thansequence.length()
- Returns:
- the index of the first matching character, guaranteed to be no less than
start
, or-1
if no character matches
-
lastIndexIn
public int lastIndexIn(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns the index of the last matching BMP character in a character sequence, or-1
if no matching character is present.The default implementation iterates over the sequence in reverse order calling
CharMatcher.matches(char)
for each character.- Overrides:
lastIndexIn
in classCharMatcher
- Parameters:
sequence
- the character sequence to examine from the end- Returns:
- an index, or
-1
if no character matches
-
matchesAllOf
public boolean matchesAllOf(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returnstrue
if a character sequence contains only matching BMP characters.The default implementation iterates over the sequence, invoking
CharMatcher.matches(char)
for each character, until this returnsfalse
or the end is reached.- Overrides:
matchesAllOf
in classCharMatcher
- Parameters:
sequence
- the character sequence to examine, possibly empty- Returns:
true
if this matcher matches every character in the sequence, including when the sequence is empty
-
matchesNoneOf
public boolean matchesNoneOf(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returnstrue
if a character sequence contains no matching BMP characters. Equivalent to!matchesAnyOf(sequence)
.The default implementation iterates over the sequence, invoking
CharMatcher.matches(char)
for each character, until this returnstrue
or the end is reached.- Overrides:
matchesNoneOf
in classCharMatcher
- Parameters:
sequence
- the character sequence to examine, possibly empty- Returns:
true
if this matcher matches no characters in the sequence, including when the sequence is empty
-
removeFrom
public java.lang.String removeFrom(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns a string containing all non-matching characters of a character sequence, in order. For example:
... returnsCharMatcher.is('a').removeFrom("bazaar")
"bzr"
.- Overrides:
removeFrom
in classCharMatcher
-
replaceFrom
public java.lang.String replaceFrom(java.lang.CharSequence sequence, char replacement)
Description copied from class:CharMatcher
Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character. For example:
... returnsCharMatcher.is('a').replaceFrom("radar", 'o')
"rodor"
.The default implementation uses
CharMatcher.indexIn(CharSequence)
to find the first matching character, then iterates the remainder of the sequence callingCharMatcher.matches(char)
for each character.- Overrides:
replaceFrom
in classCharMatcher
- Parameters:
sequence
- the character sequence to replace matching characters inreplacement
- the character to append to the result string in place of each matching character insequence
- Returns:
- the new string
-
replaceFrom
public java.lang.String replaceFrom(java.lang.CharSequence sequence, java.lang.CharSequence replacement)
Description copied from class:CharMatcher
Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement sequence. For example:
... returnsCharMatcher.is('a').replaceFrom("yaha", "oo")
"yoohoo"
.Note: If the replacement is a fixed string with only one character, you are better off calling
CharMatcher.replaceFrom(CharSequence, char)
directly.- Overrides:
replaceFrom
in classCharMatcher
- Parameters:
sequence
- the character sequence to replace matching characters inreplacement
- the characters to append to the result string in place of each matching character insequence
- Returns:
- the new string
-
collapseFrom
public java.lang.String collapseFrom(java.lang.CharSequence sequence, char replacement)
Description copied from class:CharMatcher
Returns a string copy of the input character sequence, with each group of consecutive matching BMP characters replaced by a single replacement character. For example:
... returnsCharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')
"b-p-r"
.The default implementation uses
CharMatcher.indexIn(CharSequence)
to find the first matching character, then iterates the remainder of the sequence callingCharMatcher.matches(char)
for each character.- Overrides:
collapseFrom
in classCharMatcher
- Parameters:
sequence
- the character sequence to replace matching groups of characters inreplacement
- the character to append to the result string in place of each group of matching characters insequence
- Returns:
- the new string
-
trimFrom
public java.lang.String trimFrom(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning and from the end of the string. For example:
... returnsCharMatcher.anyOf("ab").trimFrom("abacatbab")
"cat"
.Note that:
... is equivalent toCharMatcher.inRange('\0', ' ').trimFrom(str)
String.trim()
.- Overrides:
trimFrom
in classCharMatcher
-
trimLeadingFrom
public java.lang.String trimLeadingFrom(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning of the string. For example:
... returnsCharMatcher.anyOf("ab").trimLeadingFrom("abacatbab")
"catbab"
.- Overrides:
trimLeadingFrom
in classCharMatcher
-
trimTrailingFrom
public java.lang.String trimTrailingFrom(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns a substring of the input character sequence that omits all matching BMP characters from the end of the string. For example:
... returnsCharMatcher.anyOf("ab").trimTrailingFrom("abacatbab")
"abacat"
.- Overrides:
trimTrailingFrom
in classCharMatcher
-
countIn
public int countIn(java.lang.CharSequence sequence)
Description copied from class:CharMatcher
Returns the number of matchingchar
s found in a character sequence.Counts 2 per supplementary character, such as for
CharMatcher.whitespace()
().CharMatcher.negate()
().- Overrides:
countIn
in classCharMatcher
-
and
public CharMatcher and(CharMatcher other)
Description copied from class:CharMatcher
Returns a matcher that matches any character matched by both this matcher andother
.- Overrides:
and
in classCharMatcher
-
or
public CharMatcher or(CharMatcher other)
Description copied from class:CharMatcher
Returns a matcher that matches any character matched by either this matcher orother
.- Overrides:
or
in classCharMatcher
-
negate
public CharMatcher negate()
Description copied from class:CharMatcher
Returns a matcher that matches any character not matched by this matcher.- Specified by:
negate
in interfacejava.util.function.Predicate<java.lang.Character>
- Overrides:
negate
in classCharMatcher.FastMatcher
-
-