org.crosswire.common.diff
Class Commonality

java.lang.Object
  extended by org.crosswire.common.diff.Commonality

public class Commonality
extends Object

A Commonality is shared text at the beginning, middle or end of two strings. 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 [dmsmith555 at yahoo dot com]
See Also:
for license details.
The copyright to this program is held by it's authors.

Constructor Summary
private Commonality()
          This is a utility class, therefore the constructor is private.
 
Method Summary
private static int ceil(int number, int divisor)
           
static CommonMiddle halfMatch(String source, String target)
          Do the two texts share a substring which is at least half the length of the longer text?
private static CommonMiddle halfMatch(String longText, String shortText, int startIndex)
          Does a substring of shortText exist within longText such that the substring is at least half the length of longText?
static int prefix(String source, String target)
          Find the length of a common prefix.
static int suffix(String source, String target)
          Find the length of a common suffix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Commonality

private Commonality()
This is a utility class, therefore the constructor is private.

Method Detail

prefix

public static int prefix(String source,
                         String target)
Find the length of a common prefix.

Parameters:
source - First string
target - Second string
Returns:
The number of characters common to the start of each string.

suffix

public static int suffix(String source,
                         String target)
Find the length of a common suffix.

Parameters:
source - First string
target - Second string
Returns:
The number of characters common to the end of each string.

halfMatch

public static CommonMiddle halfMatch(String source,
                                     String target)
Do the two texts share a substring which is at least half the length of the longer text?

Parameters:
source - Baseline string
target - Changed string
Returns:
a CommonMiddle Or null if there was no match.

ceil

private static int ceil(int number,
                        int divisor)

halfMatch

private static CommonMiddle halfMatch(String longText,
                                      String shortText,
                                      int startIndex)
Does a substring of shortText exist within longText such that the substring is at least half the length of longText?

Parameters:
longText - Longer string
shortText - Shorter string
startIndex - Start index of quarter length substring within longText
Returns:
Five element String array, containing the prefix of longText, the suffix of longText, the prefix of shortText, the suffix of shortText and the common middle. Or null if there was no match.

Copyright ยจ 2003-2007