Class Chunk


  • public class Chunk
    extends ToString
    Holds a information about a part of the text involved in a differencing or patching operation.
    Version:
    $Id: Chunk.java,v 1.1 2006/03/12 00:24:21 juanca Exp $
    Author:
    Juanco Anez
    See Also:
    Diff, Delta
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int anchor  
      protected java.util.List<java.lang.Object> chunk  
      protected int count  
    • Constructor Summary

      Constructors 
      Constructor Description
      Chunk​(int pos, int count)
      Creates a chunk that doesn't copy the original text.
      Chunk​(java.lang.Object[] iseq, int pos, int count)
      Creates a chunk and saves a copy the original chunk's text.
      Chunk​(java.lang.Object[] iseq, int pos, int count, int offset)
      Creates a chunk that will be displaced in the resulting text, and saves a copy the original chunk's text.
      Chunk​(java.util.List<java.lang.Object> iseq, int pos, int count)
      Creates a chunk and saves a copy the original chunk's text.
      Chunk​(java.util.List<java.lang.Object> iseq, int pos, int count, int offset)
      Creates a chunk that will be displaced in the resulting text, and saves a copy the original chunk's text.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int anchor()
      Returns the anchor position of the chunk.
      void applyAdd​(int start, java.util.List<java.lang.Object> target)
      Add the text of this chunk to the target at the given position.
      void applyDelete​(java.util.List<java.lang.Object> target)
      Delete this chunk from he given text.
      java.util.List<java.lang.Object> chunk()
      Returns the text saved for this chunk.
      int first()
      Returns the index of the first line of the chunk.
      int last()
      Returns the index of the last line of the chunk.
      java.lang.String rangeString()
      Provide a string representation of the numeric range of this chunk.
      void rangeString​(java.lang.StringBuilder s)
      Provide a string representation of the numeric range of this chunk.
      void rangeString​(java.lang.StringBuilder s, java.lang.String separ)
      Provide a string representation of the numeric range of this chunk.
      int rcsfrom()
      Returns the from index of the chunk in RCS terms.
      int rcsto()
      Returns the to index of the chunk in RCS terms.
      int size()
      Returns the size of the chunk.
      static java.util.List<java.lang.Object> slice​(java.lang.Object[] seq, int pos, int count)
      Retrieves a slice from an Object array.
      static <T> java.util.List<T> slice​(java.util.List<T> seq, int pos, int count)
      Retrieves the specified part from a List.
      void toString​(java.lang.StringBuilder s)
      Provide a string image of the chunk using the an empty prefix and postfix.
      java.lang.StringBuilder toString​(java.lang.StringBuilder s, java.lang.String prefix, java.lang.String postfix)
      Provide a string image of the chunk using the given prefix and postfix.
      boolean verify​(java.util.List<java.lang.Object> target)
      Verifies that this chunk's saved text matches the corresponding text in the given sequence.
      • Methods inherited from class java.lang.Object

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

      • anchor

        protected int anchor
      • count

        protected int count
      • chunk

        protected java.util.List<java.lang.Object> chunk
    • Constructor Detail

      • Chunk

        public Chunk​(int pos,
                     int count)
        Creates a chunk that doesn't copy the original text.
        Parameters:
        pos - the start position in the text.
        count - the size of the chunk.
      • Chunk

        public Chunk​(java.lang.Object[] iseq,
                     int pos,
                     int count)
        Creates a chunk and saves a copy the original chunk's text.
        Parameters:
        iseq - the original text.
        pos - the start position in the text.
        count - the size of the chunk.
      • Chunk

        public Chunk​(java.lang.Object[] iseq,
                     int pos,
                     int count,
                     int offset)
        Creates a chunk that will be displaced in the resulting text, and saves a copy the original chunk's text.
        Parameters:
        iseq - the original text.
        pos - the start position in the text.
        count - the size of the chunk.
        offset - the position the chunk should have in the resulting text.
      • Chunk

        public Chunk​(java.util.List<java.lang.Object> iseq,
                     int pos,
                     int count)
        Creates a chunk and saves a copy the original chunk's text.
        Parameters:
        iseq - the original text.
        pos - the start position in the text.
        count - the size of the chunk.
      • Chunk

        public Chunk​(java.util.List<java.lang.Object> iseq,
                     int pos,
                     int count,
                     int offset)
        Creates a chunk that will be displaced in the resulting text, and saves a copy the original chunk's text.
        Parameters:
        iseq - the original text.
        pos - the start position in the text.
        count - the size of the chunk.
        offset - the position the chunk should have in the resulting text.
    • Method Detail

      • anchor

        public int anchor()
        Returns the anchor position of the chunk.
        Returns:
        the anchor position.
      • size

        public int size()
        Returns the size of the chunk.
        Returns:
        the size.
      • first

        public int first()
        Returns the index of the first line of the chunk.
        Returns:
        int
      • last

        public int last()
        Returns the index of the last line of the chunk.
        Returns:
        int
      • rcsfrom

        public int rcsfrom()
        Returns the from index of the chunk in RCS terms.
        Returns:
        int
      • rcsto

        public int rcsto()
        Returns the to index of the chunk in RCS terms.
        Returns:
        int
      • chunk

        public java.util.List<java.lang.Object> chunk()
        Returns the text saved for this chunk.
        Returns:
        the text.
      • verify

        public boolean verify​(java.util.List<java.lang.Object> target)
        Verifies that this chunk's saved text matches the corresponding text in the given sequence.
        Parameters:
        target - the sequence to verify against.
        Returns:
        true if the texts match.
      • applyDelete

        public void applyDelete​(java.util.List<java.lang.Object> target)
        Delete this chunk from he given text.
        Parameters:
        target - the text to delete from.
      • applyAdd

        public void applyAdd​(int start,
                             java.util.List<java.lang.Object> target)
        Add the text of this chunk to the target at the given position.
        Parameters:
        start - where to add the text.
        target - the text to add to.
      • toString

        public void toString​(java.lang.StringBuilder s)
        Provide a string image of the chunk using the an empty prefix and postfix.
        Overrides:
        toString in class ToString
        Parameters:
        s -
      • toString

        public java.lang.StringBuilder toString​(java.lang.StringBuilder s,
                                                java.lang.String prefix,
                                                java.lang.String postfix)
        Provide a string image of the chunk using the given prefix and postfix.
        Parameters:
        s - where the string image should be appended.
        prefix - the text that should prefix each line.
        postfix - the text that should end each line.
        Returns:
        StringBuilder
      • slice

        public static <T> java.util.List<T> slice​(java.util.List<T> seq,
                                                  int pos,
                                                  int count)
        Retrieves the specified part from a List.
        Type Parameters:
        T - the type of objects contained in seq
        Parameters:
        seq - the list to retrieve a slice from.
        pos - the start position.
        count - the number of items in the slice.
        Returns:
        a List containing the specified items.
      • slice

        public static java.util.List<java.lang.Object> slice​(java.lang.Object[] seq,
                                                             int pos,
                                                             int count)
        Retrieves a slice from an Object array.
        Parameters:
        seq - the list to retrieve a slice from.
        pos - the start position.
        count - the number of items in the slice.
        Returns:
        a List containing the specified items.
      • rangeString

        public java.lang.String rangeString()
        Provide a string representation of the numeric range of this chunk.
        Returns:
        String
      • rangeString

        public void rangeString​(java.lang.StringBuilder s)
        Provide a string representation of the numeric range of this chunk.
        Parameters:
        s - where the string representation should be appended.
      • rangeString

        public void rangeString​(java.lang.StringBuilder s,
                                java.lang.String separ)
        Provide a string representation of the numeric range of this chunk.
        Parameters:
        s - where the string representation should be appended.
        separ - what to use as line separator.