Class UnicodeSetSpanner

    • Constructor Detail

      • UnicodeSetSpanner

        public UnicodeSetSpanner​(UnicodeSet source)
        Create a spanner from a UnicodeSet. For speed and safety, the UnicodeSet should be frozen. However, this class can be used with a non-frozen version to avoid the cost of freezing.
        Parameters:
        source - the original UnicodeSet
    • Method Detail

      • getUnicodeSet

        public UnicodeSet getUnicodeSet()
        Returns the UnicodeSet used for processing. It is frozen iff the original was.
        Returns:
        the construction set.
      • equals

        public boolean equals​(Object other)
        Compares this instance with the specified object and indicates if they are equal. In order to be equal, 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.

        Overrides:
        equals in class Object
        Parameters:
        other - the object to compare this instance with.
        Returns:
        true if the specified object is equal to this Object; false otherwise.
        See Also:
        Object.hashCode()
      • hashCode

        public int hashCode()
        Returns an integer hash code for this object. By contract, any two objects for which 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.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • countIn

        public int countIn​(CharSequence sequence)
        Returns the number of matching characters found in a character sequence, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        sequence - the sequence to count characters in
        Returns:
        the count. Zero if there are none.
      • countIn

        public int countIn​(CharSequence sequence,
                           UnicodeSetSpanner.CountMethod countMethod)
        Returns the number of matching characters found in a character sequence, using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        sequence - the sequence to count characters in
        countMethod - whether to treat an entire span as a match, or individual elements as matches
        Returns:
        the count. Zero if there are none.
      • countIn

        public int countIn​(CharSequence sequence,
                           UnicodeSetSpanner.CountMethod countMethod,
                           UnicodeSet.SpanCondition spanCondition)
        Returns the number of matching characters found in a character sequence. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        sequence - the sequence to count characters in
        countMethod - whether to treat an entire span as a match, or individual elements as matches
        spanCondition - the spanCondition to use. SIMPLE or CONTAINED means only count the elements in the span; NOT_CONTAINED is the reverse.
        WARNING: when a UnicodeSet contains strings, there may be unexpected behavior in edge cases.
        Returns:
        the count. Zero if there are none.
      • deleteFrom

        public 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.
        Parameters:
        sequence - charsequence to replace matching spans in.
        Returns:
        modified string.
      • deleteFrom

        public String deleteFrom​(CharSequence sequence,
                                 UnicodeSet.SpanCondition spanCondition)
        Delete all matching spans in sequence, according to the spanCondition. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        sequence - charsequence to replace matching spans in.
        spanCondition - specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching (NOT_CONTAINED)
        Returns:
        modified string.
      • replaceFrom

        public String replaceFrom​(CharSequence sequence,
                                  CharSequence replacement)
        Replace all matching spans in sequence by the replacement, counting by CountMethod.MIN_ELEMENTS using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        sequence - charsequence to replace matching spans in.
        replacement - replacement sequence. To delete, use ""
        Returns:
        modified string.
      • replaceFrom

        public String replaceFrom​(CharSequence sequence,
                                  CharSequence replacement,
                                  UnicodeSetSpanner.CountMethod countMethod)
        Replace all matching spans in sequence by replacement, according to the CountMethod, using SpanCondition.SIMPLE. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        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 matches
        Returns:
        modified string.
      • replaceFrom

        public 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. The code alternates spans; see the class doc for UnicodeSetSpanner for a note about boundary conditions.
        Parameters:
        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 matches
        spanCondition - specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching (NOT_CONTAINED)
        Returns:
        modified string.
      • trim

        public 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. For example:
         
         
           new UnicodeSet("[ab]").trim("abacatbab")
         
        ... returns "cat".
        Parameters:
        sequence - the sequence to trim
        Returns:
        a subsequence
      • trim

        public 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. For example:
         
         
           new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING)
         
        ... returns "catbab".
        Parameters:
        sequence - the sequence to trim
        trimOption - LEADING, TRAILING, or BOTH
        Returns:
        a subsequence
      • trim

        public 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. For example:
         
         
           new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING, SpanCondition.SIMPLE)
         
        ... returns "catbab".
        Parameters:
        sequence - the sequence to trim
        trimOption - LEADING, TRAILING, or BOTH
        spanCondition - SIMPLE, CONTAINED or NOT_CONTAINED
        Returns:
        a subsequence