Class StringDiff


  • public class StringDiff
    extends java.lang.Object
    Container object that holds a start and end position within a string. A list of StringDiffs is used to keep track of changes made to a string.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String text
      String being inserted.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static StringDiff allTextReplaced​(java.lang.String newText)
      Construct a new StringDiff with pos1 and pos2 are initialized to -1
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      static StringDiff restore​(java.lang.String text, int start, int end)  
      static StringDiff textDeleted​(int start, int end)
      Construct a new StringDiff that indicates text was deleted from pos1 to pos2
      static StringDiff textInserted​(java.lang.String newText, int start)
      Construct a new StringDiff that indicates that insertData was inserted at the given position
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • text

        public java.lang.String text
        String being inserted. This can be an insert or a complete replace (the positions will both be -1 in a replace; pos1 will be non-negative during an insert).
    • Method Detail

      • allTextReplaced

        public static StringDiff allTextReplaced​(java.lang.String newText)
        Construct a new StringDiff with pos1 and pos2 are initialized to -1
        Parameters:
        newText - string
        Returns:
        the new diff
      • textDeleted

        public static StringDiff textDeleted​(int start,
                                             int end)
        Construct a new StringDiff that indicates text was deleted from pos1 to pos2
        Parameters:
        start - position 1 for the diff
        end - position 2 for the diff
        Returns:
        the new diff
      • textInserted

        public static StringDiff textInserted​(java.lang.String newText,
                                              int start)
        Construct a new StringDiff that indicates that insertData was inserted at the given position
        Parameters:
        newText - inserted string
        start - position where the text was inserted
        Returns:
        the new diff
      • restore

        public static StringDiff restore​(java.lang.String text,
                                         int start,
                                         int end)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object