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

    • 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 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object