Class Substring.Suffix
java.lang.Object
com.google.mu.util.Substring.Pattern
com.google.mu.util.Substring.Suffix
- All Implemented Interfaces:
CharSequence
- Enclosing class:
Substring
An immutable string suffix
Pattern with extra utilities such as addToIfAbsent(String), removeFrom(StringBuilder), isIn(CharSequence) etc.
Can usually be declared as a constant to save allocation cost. Because Suffix
implements CharSequence, it can be used almost interchangeably as a string. You can:
- directly append a suffix as in
path + SHARD_SUFFIX; - or append the suffix into a
StringBuilder:builder.append(SHARD_SUFFIX)}; - pass it to any CharSequence-accepting APIs such as
CharMatcher.anyOf(...).matchesAnyOf(MY_PREFIX),Substring.first(':').splitThenTrim(MY_PREFIX)etc.
- Since:
- 4.6
-
Method Summary
Modifier and TypeMethodDescriptionaddToIfAbsent(String string) Ifstringhas this suffix, return it as-is; otherwise, return it with this suffix appended.booleanaddToIfAbsent(StringBuilder builder) Ifbuilderdoes not already have this suffix, append this suffix to it.charcharAt(int index) booleaninthashCode()Returns a view ofsourcewith this suffix hidden away if present, or else returnssourceas is.booleanisIn(CharSequence source) Returns true ifsourceends with this suffix.intlength()Returns the length of this suffix.booleanremoveFrom(StringBuilder builder) Removes this suffix frombuilderif it ends with the suffix.booleanreplaceFrom(StringBuilder builder, CharSequence replacement) Replaces this suffix frombuilderwithreplacementif it ends with the suffix.subSequence(int start, int end) toString()Returns this suffix string.Methods inherited from class com.google.mu.util.Substring.Pattern
followedBy, from, immediatelyBetween, immediatelyBetween, in, in, limit, notFollowedBy, notImmediatelyBetween, notPrecededBy, or, peek, precededBy, removeFrom, repeatedly, replaceFrom, replaceFrom, separatedBy, separatedBy, skip, split, split, splitThenTrim, splitThenTrim, then, toEndMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Method Details
-
isIn
-
addToIfAbsent
-
addToIfAbsent
Ifbuilderdoes not already have this suffix, append this suffix to it.- Returns:
- true if this suffix is appended
- Since:
- 5.7
-
removeFrom
Removes this suffix frombuilderif it ends with the suffix.- Returns:
- true if this suffix is removed
- Since:
- 5.7
-
hideFrom
Returns a view ofsourcewith this suffix hidden away if present, or else returnssourceas is.- Since:
- 6.5
-
replaceFrom
Replaces this suffix frombuilderwithreplacementif it ends with the suffix.- Returns:
- true if this suffix is replaced
- Since:
- 5.7
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence- Since:
- 5.7
-
subSequence
- Specified by:
subSequencein interfaceCharSequence- Since:
- 5.7
-
length
public int length()Returns the length of this suffix.- Specified by:
lengthin interfaceCharSequence- Since:
- 5.7
-
hashCode
-
equals
-
toString
Returns this suffix string.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classSubstring.Pattern
-