public class UnicodeSetSpanner extends Object
Note: The counting, deletion, and replacement depend on alternating a UnicodeSet.SpanCondition with
its inverse. That is, the code spans, then spans for the inverse, then spans, and so on.
For the inverse, the following mapping is used:
UnicodeSet.SpanCondition.SIMPLE → UnicodeSet.SpanCondition.NOT_CONTAINEDUnicodeSet.SpanCondition.CONTAINED → UnicodeSet.SpanCondition.NOT_CONTAINEDUnicodeSet.SpanCondition.NOT_CONTAINED → UnicodeSet.SpanCondition.SIMPLE
| SIMPLE | xxx[ab]cyyy |
|---|---|
| CONTAINED | xxx[abc]yyy |
| NOT_CONTAINED | [xxx]ab[cyyy] |
So here is what happens when you alternate:
| start | |xxxabcyyy |
|---|---|
| NOT_CONTAINED | xxx|abcyyy |
| CONTAINED | xxxabc|yyy |
| NOT_CONTAINED | xxxabcyyy| |
| Modifier and Type | Class and Description |
|---|---|
static class |
UnicodeSetSpanner.CountMethod
Options for replaceFrom and countIn to control how to treat each matched span.
|
static class |
UnicodeSetSpanner.TrimOption
Options for the trim() method
|
| Constructor and Description |
|---|
UnicodeSetSpanner(UnicodeSet source)
Create a spanner from a UnicodeSet.
|
| Modifier and Type | Method and Description |
|---|---|
int |
countIn(CharSequence sequence)
Returns the number of matching characters found in a character sequence,
counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE.
|
int |
countIn(CharSequence sequence,
UnicodeSetSpanner.CountMethod countMethod)
Returns the number of matching characters found in a character sequence, using SpanCondition.SIMPLE.
|
int |
countIn(CharSequence sequence,
UnicodeSetSpanner.CountMethod countMethod,
UnicodeSet.SpanCondition spanCondition)
Returns the number of matching characters found in a character sequence.
|
String |
deleteFrom(CharSequence sequence)
Delete all the matching spans in sequence, using SpanCondition.SIMPLE
The code alternates spans; see the class doc for
UnicodeSetSpanner for a note about boundary conditions. |
String |
deleteFrom(CharSequence sequence,
UnicodeSet.SpanCondition spanCondition)
Delete all matching spans in sequence, according to the spanCondition.
|
boolean |
equals(Object other)
Compares this instance with the specified object and indicates if they
are equal.
|
UnicodeSet |
getUnicodeSet()
Returns the UnicodeSet used for processing.
|
int |
hashCode()
Returns an integer hash code for this object.
|
String |
replaceFrom(CharSequence sequence,
CharSequence replacement)
Replace all matching spans in sequence by the replacement,
counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE.
|
String |
replaceFrom(CharSequence sequence,
CharSequence replacement,
UnicodeSetSpanner.CountMethod countMethod)
Replace all matching spans in sequence by replacement, according to the CountMethod, using SpanCondition.SIMPLE.
|
String |
replaceFrom(CharSequence sequence,
CharSequence replacement,
UnicodeSetSpanner.CountMethod countMethod,
UnicodeSet.SpanCondition spanCondition)
Replace all matching spans in sequence by replacement, according to the countMethod and spanCondition.
|
CharSequence |
trim(CharSequence sequence)
Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start and
end of the string, using TrimOption.BOTH and SpanCondition.SIMPLE.
|
CharSequence |
trim(CharSequence sequence,
UnicodeSetSpanner.TrimOption trimOption)
Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or
end of the string, using the trimOption and SpanCondition.SIMPLE.
|
CharSequence |
trim(CharSequence sequence,
UnicodeSetSpanner.TrimOption trimOption,
UnicodeSet.SpanCondition spanCondition)
Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or
end of the string, depending on the trimOption and spanCondition.
|
public UnicodeSetSpanner(UnicodeSet source)
source - the original UnicodeSetpublic UnicodeSet getUnicodeSet()
public boolean equals(Object other)
o must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true only if this ==
o. See Writing a correct
equals method
if you intend implementing your own equals method.
The general contract for the equals and Object.hashCode() methods is that if equals returns true for
any two objects, then hashCode() must return the same value for
these objects. This means that subclasses of Object usually
override either both methods or neither of them.
equals in class Objectother - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public int hashCode()
Object.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in class ObjectObject.equals(java.lang.Object)public int countIn(CharSequence sequence)
UnicodeSetSpanner for a note about boundary conditions.sequence - the sequence to count characters inpublic int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod)
UnicodeSetSpanner for a note about boundary conditions.sequence - the sequence to count characters incountMethod - whether to treat an entire span as a match, or individual elements as matchespublic int countIn(CharSequence sequence, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)
UnicodeSetSpanner for a note about boundary conditions.sequence - the sequence to count characters incountMethod - whether to treat an entire span as a match, or individual elements as matchesspanCondition - the spanCondition to use. SIMPLE or CONTAINED means only count the elements in the span;
NOT_CONTAINED is the reverse.
public String deleteFrom(CharSequence sequence)
UnicodeSetSpanner for a note about boundary conditions.sequence - charsequence to replace matching spans in.public String deleteFrom(CharSequence sequence, UnicodeSet.SpanCondition spanCondition)
UnicodeSetSpanner for a note about boundary conditions.sequence - charsequence to replace matching spans in.spanCondition - specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching (NOT_CONTAINED)public String replaceFrom(CharSequence sequence, CharSequence replacement)
UnicodeSetSpanner for a note about boundary conditions.sequence - charsequence to replace matching spans in.replacement - replacement sequence. To delete, use ""public String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod)
UnicodeSetSpanner for a note about boundary conditions.sequence - charsequence to replace matching spans in.replacement - replacement sequence. To delete, use ""countMethod - whether to treat an entire span as a match, or individual elements as matchespublic String replaceFrom(CharSequence sequence, CharSequence replacement, UnicodeSetSpanner.CountMethod countMethod, UnicodeSet.SpanCondition spanCondition)
UnicodeSetSpanner for a note about boundary conditions.sequence - charsequence to replace matching spans in.replacement - replacement sequence. To delete, use ""countMethod - whether to treat an entire span as a match, or individual elements as matchesspanCondition - specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching
(NOT_CONTAINED)public CharSequence trim(CharSequence sequence)
new UnicodeSet("[ab]").trim("abacatbab")
... returns "cat".sequence - the sequence to trimpublic CharSequence trim(CharSequence sequence, UnicodeSetSpanner.TrimOption trimOption)
new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING)
... returns "catbab".sequence - the sequence to trimtrimOption - LEADING, TRAILING, or BOTHpublic CharSequence trim(CharSequence sequence, UnicodeSetSpanner.TrimOption trimOption, UnicodeSet.SpanCondition spanCondition)
new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING, SpanCondition.SIMPLE)
... returns "catbab".sequence - the sequence to trimtrimOption - LEADING, TRAILING, or BOTHspanCondition - SIMPLE, CONTAINED or NOT_CONTAINED