org.crosswire.common.diff

## Class Patch

- java.lang.Object
- - org.crosswire.common.diff.Patch

-     public class Patch
      extends Object

  Marshals a patch to a list of Differences, Differences to a patch and applies a list of differences to text to patch it. Based on the LGPL Diff_Match_Patch v1.5 javascript of Neil Fraser, Copyright (C) 2006
  http://neil.fraser.name/software/diff_match_patch/
  Author:
    DM Smith
  See Also:
    `The GNU Lesser General Public License for details.`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Patch.PatchResults` A holder of the results of a patch, with a results indicating which patch entries were able to be applied.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private int` | `margin`
    `private static Pattern` | `patchBoundaryPattern`
    `private List<PatchEntry>` | `patches`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Patch()` Create an empty patch.
    `Patch(String input)` Create a Patch from a textual representation,
    `Patch(String source, String target)` Create a patch that can turn text1 into text2.
    `Patch(String source, String target, List<Difference> diffs)` Create a patch that can turn text1 into text2.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Patch.PatchResults` | `apply(String text)` Merge this patch onto the text.
    `Patch` | `fromText(String input)` Parse a textual representation of patches and return a List of Patch objects.
    `Patch` | `make(String source, String target, List<Difference> diffList)` Compute a list of patches to turn text1 into text2.
    `void` | `splitMax()` Look through the patches and break up any which are longer than the maximum limit of the match algorithm.
    `String` | `toText()` Take a list of patches and return a textual representation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### patchBoundaryPattern

          private static Pattern patchBoundaryPattern

    - #### patches

          private List<PatchEntry> patches

    - #### margin

          private int margin

  - ### Constructor Detail

    - #### Patch

          public Patch()

      Create an empty patch.

    - #### Patch

          public Patch(String input)

      Create a Patch from a textual representation,
      Parameters:
        `input` - Text representation of patches

    - #### Patch

          public Patch(String source,
               String target)

      Create a patch that can turn text1 into text2.
      Parameters:
        `source` - Old text
        `target` - New text

    - #### Patch

          public Patch(String source,
               String target,
               List<Difference> diffs)

      Create a patch that can turn text1 into text2. Use the diffs provided, if not null. Compute diffs otherwise.
      Parameters:
        `source` - Old text
        `target` - New text
        `diffs` - Optional array of diff tuples for text1 to text2.

  - ### Method Detail

    - #### make

          public Patch make(String source,
                   String target,
                   List<Difference> diffList)

      Compute a list of patches to turn text1 into text2. Use the diffs provided.
      Parameters:
        `source` - Old text
        `target` - New text
        `diffList` - Optional array of diff tuples for text1 to text2.
      Returns:
        this patch

    - #### apply

          public Patch.PatchResults apply(String text)

      Merge this patch onto the text. Return a patched text, as well as an array of true/false values indicating which patches were applied.
      Parameters:
        `text` - Old text
      Returns:
        the patch result

    - #### splitMax

          public void splitMax()

      Look through the patches and break up any which are longer than the maximum limit of the match algorithm.

    - #### toText

          public String toText()

      Take a list of patches and return a textual representation.
      Returns:
        Text representation of patches.

    - #### fromText

          public Patch fromText(String input)

      Parse a textual representation of patches and return a List of Patch objects.
      Parameters:
        `input` - Text representation of patches
      Returns:
        List of Patch objects