Class TextChange<S,​Self extends TextChange<S,​Self>>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected S inserted  
      protected int position  
      protected S removed  
    • Constructor Summary

      Constructors 
      Constructor Description
      TextChange​(int position, S removed, S inserted)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract S concat​(S a, S b)  
      protected abstract Self create​(int position, S removed, S inserted)  
      boolean equals​(java.lang.Object other)  
      S getInserted()  
      int getInsertionEnd()
      Returns the position where the inserted ends (e.g.
      int getNetLength()
      Gets the net length of this change (i.e., insertedLength() - removedLength())
      int getPosition()
      Gets the start position of where the replacement happened
      int getRemovalEnd()
      Returns the position where the removal ends (e.g.
      S getRemoved()  
      int hashCode()  
      protected abstract int insertedLength()  
      Self invert()
      Returns a new subclass of TextChange that makes the inserted the removed object and the removed the inserted object
      boolean isIdentity()
      Returns true if this change is an identity change: applying it does nothing as it removes what it inserts.
      java.util.Optional<Self> mergeWith​(Self latter)
      Merges this change with the given change, if possible.
      protected abstract int removedLength()  
      protected abstract S sub​(S s, int from, int to)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • position

        protected final int position
      • removed

        protected final S removed
      • inserted

        protected final S inserted
    • Constructor Detail

      • TextChange

        public TextChange​(int position,
                          S removed,
                          S inserted)
    • Method Detail

      • getPosition

        public int getPosition()
        Gets the start position of where the replacement happened
      • getRemoved

        public S getRemoved()
      • getInserted

        public S getInserted()
      • invert

        public Self invert()
        Returns a new subclass of TextChange that makes the inserted the removed object and the removed the inserted object
      • getRemovalEnd

        public int getRemovalEnd()
        Returns the position where the removal ends (e.g. position + removedLength())
      • getInsertionEnd

        public int getInsertionEnd()
        Returns the position where the inserted ends (e.g. position + insertedLength())
      • getNetLength

        public int getNetLength()
        Gets the net length of this change (i.e., insertedLength() - removedLength())
      • removedLength

        protected abstract int removedLength()
      • insertedLength

        protected abstract int insertedLength()
      • concat

        protected abstract S concat​(S a,
                                    S b)
      • sub

        protected abstract S sub​(S s,
                                 int from,
                                 int to)
      • create

        protected abstract Self create​(int position,
                                       S removed,
                                       S inserted)
      • isIdentity

        public final boolean isIdentity()
        Returns true if this change is an identity change: applying it does nothing as it removes what it inserts. See also Function.identity()
      • mergeWith

        public java.util.Optional<Self> mergeWith​(Self latter)
        Merges this change with the given change, if possible. This change is considered to be the former and the given change is considered to be the latter. Changes can be merged if either
        • the latter's start matches the former's added text end; or
        • the latter's removed text end matches the former's added text end.
        Parameters:
        latter - change to merge with this change.
        Returns:
        a new merged change if changes can be merged, null otherwise.
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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