Class Edits


  • public final class Edits
    extends java.lang.Object
    Records lengths of string edits but not replacement text. Supports replacements, insertions, deletions in linear progression. Does not support moving/reordering of text.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Edits.Iterator
      Access to the list of edits.
    • Constructor Summary

      Constructors 
      Constructor Description
      Edits()
      Constructs an empty object.
    • Constructor Detail

      • Edits

        public Edits()
        Constructs an empty object.
    • Method Detail

      • reset

        public void reset()
        Resets the data but may not release memory.
      • addUnchanged

        public void addUnchanged​(int unchangedLength)
        Adds a record for an unchanged segment of text. Normally called from inside ICU string transformation functions, not user code.
      • addReplace

        public void addReplace​(int oldLength,
                               int newLength)
        Adds a record for a text replacement/insertion/deletion. Normally called from inside ICU string transformation functions, not user code.
      • lengthDelta

        public int lengthDelta()
        How much longer is the new text compared with the old text?
        Returns:
        new length minus old length
      • hasChanges

        public boolean hasChanges()
        Returns:
        true if there are any change edits
      • numberOfChanges

        public int numberOfChanges()
        Returns:
        the number of change edits
      • getCoarseChangesIterator

        public Edits.Iterator getCoarseChangesIterator()
        Returns an Iterator for coarse-grained changes for simple string updates. Skips non-changes.
        Returns:
        an Iterator that merges adjacent changes.
      • getCoarseIterator

        public Edits.Iterator getCoarseIterator()
        Returns an Iterator for coarse-grained changes and non-changes for simple string updates.
        Returns:
        an Iterator that merges adjacent changes.
      • getFineChangesIterator

        public Edits.Iterator getFineChangesIterator()
        Returns an Iterator for fine-grained changes for modifying styled text. Skips non-changes.
        Returns:
        an Iterator that separates adjacent changes.
      • getFineIterator

        public Edits.Iterator getFineIterator()
        Returns an Iterator for fine-grained changes and non-changes for modifying styled text.
        Returns:
        an Iterator that separates adjacent changes.
      • mergeAndAppend

        public Edits mergeAndAppend​(Edits ab,
                                    Edits bc)
        Merges the two input Edits and appends the result to this object.

        Consider two string transformations (for example, normalization and case mapping) where each records Edits in addition to writing an output string.
        Edits ab reflect how substrings of input string a map to substrings of intermediate string b.
        Edits bc reflect how substrings of intermediate string b map to substrings of output string c.
        This function merges ab and bc such that the additional edits recorded in this object reflect how substrings of input string a map to substrings of output string c.

        If unrelated Edits are passed in where the output string of the first has a different length than the input string of the second, then an IllegalArgumentException is thrown.

        Parameters:
        ab - reflects how substrings of input string a map to substrings of intermediate string b.
        bc - reflects how substrings of intermediate string b map to substrings of output string c.
        Returns:
        this, with the merged edits appended