[jsword-svn] r1338 - trunk/common/src/main/java/org/crosswire/common/diff
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Tue May 22 04:41:52 MST 2007
Author: dmsmith
Date: 2007-05-22 04:41:51 -0700 (Tue, 22 May 2007)
New Revision: 1338
Modified:
trunk/common/src/main/java/org/crosswire/common/diff/Diff.java
trunk/common/src/main/java/org/crosswire/common/diff/Match.java
trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
Log:
checkstyle changes
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Diff.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Diff.java 2007-05-22 01:05:57 UTC (rev 1337)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Diff.java 2007-05-22 11:41:51 UTC (rev 1338)
@@ -55,7 +55,7 @@
*/
public static List main(String text1, String text2)
{
- return main(text1, text2, true);
+ return main(text1, text2, true);
}
/**
@@ -70,43 +70,44 @@
*/
public static List main(String text1, String text2, boolean checklines)
{
- // Check for equality (speedup)
- List diffs;
- if (text1.equals(text2)) {
- diffs = new LinkedList();
- diffs.add(new Difference(EditType.EQUAL, text1));
- return diffs;
- }
+ // Check for equality (speedup)
+ List diffs;
+ if (text1.equals(text2))
+ {
+ diffs = new LinkedList();
+ diffs.add(new Difference(EditType.EQUAL, text1));
+ return diffs;
+ }
- // Trim off common prefix (speedup)
- int commonlength = commonPrefix(text1, text2);
- String commonprefix = text1.substring(0, commonlength);
- String work1 = text1.substring(commonlength);
- String work2 = text2.substring(commonlength);
+ // Trim off common prefix (speedup)
+ int commonlength = commonPrefix(text1, text2);
+ String commonprefix = text1.substring(0, commonlength);
+ String work1 = text1.substring(commonlength);
+ String work2 = text2.substring(commonlength);
- // Trim off common suffix (speedup)
- commonlength = commonSuffix(work1, work2);
- String commonsuffix = work1.substring(work1.length() - commonlength);
- work1 = work1.substring(0, work1.length() - commonlength);
- work2 = work2.substring(0, work2.length() - commonlength);
+ // Trim off common suffix (speedup)
+ commonlength = commonSuffix(work1, work2);
+ String commonsuffix = work1.substring(work1.length() - commonlength);
+ work1 = work1.substring(0, work1.length() - commonlength);
+ work2 = work2.substring(0, work2.length() - commonlength);
- // Compute the diff on the middle block
- diffs = compute(work1, work2, checklines);
+ // Compute the diff on the middle block
+ diffs = compute(work1, work2, checklines);
- // Restore the prefix and suffix
- if (!commonprefix.equals("")) //$NON-NLS-1$
- {
- diffs.add(0, new Difference(EditType.EQUAL, commonprefix));
- }
+ // Restore the prefix and suffix
+ if (!commonprefix.equals("")) //$NON-NLS-1$
+ {
+ diffs.add(0, new Difference(EditType.EQUAL, commonprefix));
+ }
- if (!commonsuffix.equals("")) //$NON-NLS-1$
- {
- diffs.add(new Difference(EditType.EQUAL, commonsuffix));
- }
+ if (!commonsuffix.equals("")) //$NON-NLS-1$
+ {
+ diffs.add(new Difference(EditType.EQUAL, commonsuffix));
+ }
- cleanupMerge(diffs);
+ cleanupMerge(diffs);
- return diffs;
+ return diffs;
}
/**
@@ -118,136 +119,139 @@
* If true, then run a faster slightly less optimal diff
* @return Linked List of Diff objects
*/
- public static List compute(String text1, String text2,
- boolean checklines) {
- List diffs = new ArrayList();
+ public static List compute(String text1, String text2, boolean checklines)
+ {
+ List diffs = new ArrayList();
- if (text1.equals("")) //$NON-NLS-1$
- {
- // Just add some text (speedup)
- diffs.add(new Difference(EditType.INSERT, text2));
- return diffs;
- }
+ if (text1.equals("")) //$NON-NLS-1$
+ {
+ // Just add some text (speedup)
+ diffs.add(new Difference(EditType.INSERT, text2));
+ return diffs;
+ }
- if (text2.equals("")) //$NON-NLS-1$
- {
- // Just delete some text (speedup)
- diffs.add(new Difference(EditType.DELETE, text1));
- return diffs;
- }
+ if (text2.equals("")) //$NON-NLS-1$
+ {
+ // Just delete some text (speedup)
+ diffs.add(new Difference(EditType.DELETE, text1));
+ return diffs;
+ }
- String longtext = text1.length() > text2.length() ? text1 : text2;
- String shorttext = text1.length() > text2.length() ? text2 : text1;
- int i = longtext.indexOf(shorttext);
- if (i != -1) {
- // Shorter text is inside the longer text (speedup)
- EditType op = (text1.length() > text2.length()) ?
- EditType.DELETE : EditType.INSERT;
- diffs.add(new Difference(op, longtext.substring(0, i)));
- diffs.add(new Difference(EditType.EQUAL, shorttext));
- diffs.add(new Difference(op, longtext.substring(i + shorttext.length())));
- }
- longtext = shorttext = null; // Garbage collect
+ String longtext = text1.length() > text2.length() ? text1 : text2;
+ String shorttext = text1.length() > text2.length() ? text2 : text1;
+ int i = longtext.indexOf(shorttext);
+ if (i != -1)
+ {
+ // Shorter text is inside the longer text (speedup)
+ EditType op = (text1.length() > text2.length()) ? EditType.DELETE : EditType.INSERT;
+ diffs.add(new Difference(op, longtext.substring(0, i)));
+ diffs.add(new Difference(EditType.EQUAL, shorttext));
+ diffs.add(new Difference(op, longtext.substring(i + shorttext.length())));
+ }
- // Check to see if the problem can be split in two.
- CommonMiddle hm = halfMatch(text1, text2);
- if (hm != null)
- {
- // A half-match was found, sort out the return data.
- // Send both pairs off for separate processing.
- List diffs_a = main(hm.getLeftStart(), hm.getRightStart(), checklines);
- List diffs_b = main(hm.getLeftEnd(), hm.getRightEnd(), checklines);
- // Merge the results.
- diffs = diffs_a;
- diffs.add(new Difference(EditType.EQUAL, hm.getCommonality()));
- diffs.addAll(diffs_b);
- return diffs;
- }
+ // Garbage collect
+ longtext = null;
+ shorttext = null;
- // Perform a real diff.
- if (checklines && text1.length() + text2.length() < 250)
- {
- checklines = false; // Too trivial for the overhead.
- }
+ // Check to see if the problem can be split in two.
+ CommonMiddle hm = halfMatch(text1, text2);
+ if (hm != null)
+ {
+ // A half-match was found, sort out the return data.
+ // Send both pairs off for separate processing.
+ List diffs_a = main(hm.getLeftStart(), hm.getRightStart(), checklines);
+ List diffs_b = main(hm.getLeftEnd(), hm.getRightEnd(), checklines);
+ // Merge the results.
+ diffs = diffs_a;
+ diffs.add(new Difference(EditType.EQUAL, hm.getCommonality()));
+ diffs.addAll(diffs_b);
+ return diffs;
+ }
- ArrayList linearray = null;
- if (checklines)
- {
- // Scan the text on a line-by-line basis first.
- Object b[] = linesToChars(text1, text2);
- text1 = (String) b[0];
- text2 = (String) b[1];
- linearray = (ArrayList) b[2];
- }
+ // Perform a real diff.
+ if (checklines && text1.length() + text2.length() < 250)
+ {
+ checklines = false; // Too trivial for the overhead.
+ }
- diffs = map(text1, text2);
- if (diffs == null)
- {
- // No acceptable result.
- diffs = new ArrayList();
- diffs.add(new Difference(EditType.DELETE, text1));
- diffs.add(new Difference(EditType.INSERT, text2));
- }
+ ArrayList linearray = null;
+ if (checklines)
+ {
+ // Scan the text on a line-by-line basis first.
+ Object[] b = linesToChars(text1, text2);
+ text1 = (String) b[0];
+ text2 = (String) b[1];
+ linearray = (ArrayList) b[2];
+ }
- if (checklines)
- {
- // Convert the diff back to original text.
- charsToLines(diffs, linearray);
- // Eliminate freak matches (e.g. blank lines)
- cleanupSemantic(diffs);
+ diffs = map(text1, text2);
+ if (diffs == null)
+ {
+ // No acceptable result.
+ diffs = new ArrayList();
+ diffs.add(new Difference(EditType.DELETE, text1));
+ diffs.add(new Difference(EditType.INSERT, text2));
+ }
- // Rediff any replacement blocks, this time character-by-character.
- // Add a dummy entry at the end.
- diffs.add(new Difference(EditType.EQUAL, "")); //$NON-NLS-1$
- int count_delete = 0;
- int count_insert = 0;
- String text_delete = ""; //$NON-NLS-1$
- String text_insert = ""; //$NON-NLS-1$
- ListIterator pointer = diffs.listIterator();
- Difference thisDiff = (Difference) pointer.next();
- while (thisDiff != null)
+ if (checklines)
{
- if (thisDiff.getEditType() == EditType.INSERT)
- {
- count_insert++;
- text_insert += thisDiff.getText();
- }
- else if (thisDiff.getEditType() == EditType.DELETE)
- {
- count_delete++;
- text_delete += thisDiff.getText();
- }
- else
- {
- // Upon reaching an equality, check for prior redundancies.
- if (count_delete >= 1 && count_insert >= 1)
+ // Convert the diff back to original text.
+ charsToLines(diffs, linearray);
+ // Eliminate freak matches (e.g. blank lines)
+ cleanupSemantic(diffs);
+
+ // Rediff any replacement blocks, this time character-by-character.
+ // Add a dummy entry at the end.
+ diffs.add(new Difference(EditType.EQUAL, "")); //$NON-NLS-1$
+ int count_delete = 0;
+ int count_insert = 0;
+ String text_delete = ""; //$NON-NLS-1$
+ String text_insert = ""; //$NON-NLS-1$
+ ListIterator pointer = diffs.listIterator();
+ Difference thisDiff = (Difference) pointer.next();
+ while (thisDiff != null)
{
- // Delete the offending records and add the merged ones.
- pointer.previous();
- for (int j = 0; j < count_delete + count_insert; j++) {
- pointer.previous();
- pointer.remove();
- }
- List newDiffs = main(text_delete, text_insert, false);
- Iterator iter = newDiffs.iterator();
- while (iter.hasNext())
- {
- pointer.add(iter.next());
- }
+ if (thisDiff.getEditType() == EditType.INSERT)
+ {
+ count_insert++;
+ text_insert += thisDiff.getText();
+ }
+ else if (thisDiff.getEditType() == EditType.DELETE)
+ {
+ count_delete++;
+ text_delete += thisDiff.getText();
+ }
+ else
+ {
+ // Upon reaching an equality, check for prior redundancies.
+ if (count_delete >= 1 && count_insert >= 1)
+ {
+ // Delete the offending records and add the merged ones.
+ pointer.previous();
+ for (int j = 0; j < count_delete + count_insert; j++)
+ {
+ pointer.previous();
+ pointer.remove();
+ }
+ List newDiffs = main(text_delete, text_insert, false);
+ Iterator iter = newDiffs.iterator();
+ while (iter.hasNext())
+ {
+ pointer.add(iter.next());
+ }
+ }
+ count_insert = 0;
+ count_delete = 0;
+ text_delete = ""; //$NON-NLS-1$
+ text_insert = ""; //$NON-NLS-1$
+ }
+ thisDiff = pointer.hasNext() ? (Difference) pointer.next() : null;
}
- count_insert = 0;
- count_delete = 0;
- text_delete = ""; //$NON-NLS-1$
- text_insert = ""; //$NON-NLS-1$
- }
- thisDiff = pointer.hasNext() ? (Difference) pointer.next() : null;
+ diffs.remove(diffs.size() - 1); // Remove the dummy entry at the end.
}
- diffs.remove(diffs.size() - 1); // Remove the dummy entry at the end.
- }
- return diffs;
+ return diffs;
}
-
/**
* Split two texts into a list of strings. Reduce the texts to a string of
* hashes where each Unicode character represents one line.
@@ -270,7 +274,10 @@
String chars1 = linesToCharsMunge(text1, linearray, linehash);
String chars2 = linesToCharsMunge(text2, linearray, linehash);
- return new Object[]{chars1, chars2, linearray};
+ return new Object[]
+ {
+ chars1, chars2, linearray
+ };
}
/**
@@ -353,13 +360,14 @@
Map v2 = new HashMap();
v1.put(new Integer(1), new Integer(0));
v2.put(new Integer(1), new Integer(0));
- int x, y;
+ int x;
+ int y;
String footstep; // Used to track overlapping paths.
Map footsteps = new HashMap();
boolean done = false;
// If the total number of characters is odd, then the front path will
// collide with the reverse path.
- boolean front = ((text1.length() + text2.length()) % 2 == 1);
+ boolean front = (text1.length() + text2.length()) % 2 == 1;
for (int d = 0; d < max_d; d++)
{
// Bail out if timeout reached.
@@ -394,13 +402,12 @@
{
footsteps.put(footstep, new Integer(d));
}
- while (!done && x < text1.length() && y < text2.length()
- && text1.charAt(x) == text2.charAt(y))
+ while (!done && x < text1.length() && y < text2.length() && text1.charAt(x) == text2.charAt(y))
{
x++;
y++;
footstep = x + "," + y; //$NON-NLS-1$
- if (front && (footsteps.containsKey(footstep)))
+ if (front && footsteps.containsKey(footstep))
{
done = true;
}
@@ -417,8 +424,7 @@
// Front path ran over reverse path.
Integer footstepValue = (Integer) footsteps.get(footstep);
v_map2 = v_map2.subList(0, footstepValue.intValue() + 1);
- List a = path1(v_map1, text1.substring(0, x),
- text2.substring(0, y));
+ List a = path1(v_map1, text1.substring(0, x), text2.substring(0, y));
a.addAll(path2(v_map2, text1.substring(x), text2.substring(y)));
return a;
}
@@ -450,9 +456,7 @@
{
footsteps.put(footstep, new Integer(d));
}
- while (!done && x < text1.length() && y < text2.length()
- && text1.charAt(text1.length() - x - 1)
- == text2.charAt(text2.length() - y - 1))
+ while (!done && x < text1.length() && y < text2.length() && text1.charAt(text1.length() - x - 1) == text2.charAt(text2.length() - y - 1))
{
x++;
y++;
@@ -475,11 +479,8 @@
// Reverse path ran over front path.
Integer footstepValue = (Integer) footsteps.get(footstep);
v_map1 = v_map1.subList(0, footstepValue.intValue() + 1);
- List a
- = path1(v_map1, text1.substring(0, text1.length() - x),
- text2.substring(0, text2.length() - y));
- a.addAll(path2(v_map2, text1.substring(text1.length() - x),
- text2.substring(text2.length() - y)));
+ List a = path1(v_map1, text1.substring(0, text1.length() - x), text2.substring(0, text2.length() - y));
+ a.addAll(path2(v_map2, text1.substring(text1.length() - x), text2.substring(text2.length() - y)));
return a;
}
}
@@ -541,7 +542,7 @@
{
x--;
y--;
- assert (text1.charAt(x) == text2.charAt(y)) : "No diagonal. Can't happen. (diff_path1)"; //$NON-NLS-1$
+ assert text1.charAt(x) == text2.charAt(y) : "No diagonal. Can't happen. (diff_path1)"; //$NON-NLS-1$
if (last_op == EditType.EQUAL)
{
Difference firstDiff = (Difference) path.get(0);
@@ -558,7 +559,6 @@
return path;
}
-
/**
* Work from the middle back to the end to determine the path.
* @param v_map List of path sets.
@@ -587,8 +587,7 @@
}
else
{
- path.add(new Difference(EditType.DELETE,
- text1.substring(text1.length() - x - 1, text1.length() - x)));
+ path.add(new Difference(EditType.DELETE, text1.substring(text1.length() - x - 1, text1.length() - x)));
}
last_op = EditType.DELETE;
break;
@@ -603,8 +602,7 @@
}
else
{
- path.add(new Difference(EditType.INSERT,
- text2.substring(text2.length() - y - 1, text2.length() - y)));
+ path.add(new Difference(EditType.INSERT, text2.substring(text2.length() - y - 1, text2.length() - y)));
}
last_op = EditType.INSERT;
break;
@@ -613,9 +611,7 @@
{
x--;
y--;
- assert (text1.charAt(text1.length() - x - 1)
- == text2.charAt(text2.length() - y - 1))
- : "No diagonal. Can't happen. (diff_path2)"; //$NON-NLS-1$
+ assert text1.charAt(text1.length() - x - 1) == text2.charAt(text2.length() - y - 1) : "No diagonal. Can't happen. (diff_path2)"; //$NON-NLS-1$
if (last_op == EditType.EQUAL)
{
@@ -624,8 +620,7 @@
}
else
{
- path.add(new Difference(EditType.EQUAL,
- text1.substring(text1.length() - x - 1, text1.length() - x)));
+ path.add(new Difference(EditType.EQUAL, text1.substring(text1.length() - x - 1, text1.length() - x)));
}
last_op = EditType.EQUAL;
}
@@ -660,7 +655,6 @@
return pointermid;
}
-
/**
* Trim off common suffix
* @param text1 First string
@@ -687,7 +681,6 @@
return pointermid;
}
-
/**
* Do the two texts share a substring which is at least half the length of the
* longer text?
@@ -708,9 +701,9 @@
}
// First check if the second quarter is the seed for a half-match.
- CommonMiddle hm1 = halfMatch_i(longtext, shorttext, (int) Math.ceil(longtextLength/4));
+ CommonMiddle hm1 = halfMatchI(longtext, shorttext, (int) Math.ceil(longtextLength / 4));
// Check again based on the third quarter.
- CommonMiddle hm2 = halfMatch_i(longtext, shorttext, (int) Math.ceil(longtextLength/2));
+ CommonMiddle hm2 = halfMatchI(longtext, shorttext, (int) Math.ceil(longtextLength / 2));
CommonMiddle hm = null;
if (hm1 == null && hm2 == null)
{
@@ -724,7 +717,8 @@
{
hm = hm2;
}
- else // Both matched. Select the longest.
+ else
+ // Both matched. Select the longest.
{
hm = hm1.getCommonality().length() > hm2.getCommonality().length() ? hm1 : hm2;
}
@@ -747,10 +741,10 @@
* suffix of longtext, the prefix of shorttext, the suffix of shorttext
* and the common middle. Or null if there was no match.
*/
- private static CommonMiddle halfMatch_i(String longtext, String shorttext, int i)
+ private static CommonMiddle halfMatchI(String longtext, String shorttext, int i)
{
// Start with a 1/4 length substring at position i as a seed.
- String seed = longtext.substring(i, i + (longtext.length()/4));
+ String seed = longtext.substring(i, i + (longtext.length() / 4));
int j = -1;
String best_common = ""; //$NON-NLS-1$
String best_longtext_a = ""; //$NON-NLS-1$
@@ -771,7 +765,7 @@
}
}
- if (best_common.length() >= longtext.length()/2)
+ if (best_common.length() >= longtext.length() / 2)
{
return new CommonMiddle(best_longtext_a, best_longtext_b, best_common, best_shorttext_a, best_shorttext_b);
}
@@ -779,7 +773,6 @@
return null;
}
-
/**
* Reduce the number of edits by eliminating semantically trivial equalities.
* @param diffs LinkedList of Diff objects
@@ -795,7 +788,7 @@
Difference curDiff = pointer.hasNext() ? (Difference) pointer.next() : null;
while (curDiff != null)
{
- EditType editType = curDiff.getEditType();
+ EditType editType = curDiff.getEditType();
if (EditType.EQUAL.equals(editType))
{
// equality found
@@ -822,7 +815,7 @@
pointer.set(new Difference(EditType.DELETE, lastequality));
// Insert a coresponding an insert.
pointer.add(new Difference(EditType.INSERT, lastequality));
- equalities.pop(); // Throw away the equality we just deleted;
+ equalities.pop(); // Throw away the equality we just deleted;
if (!equalities.empty())
{
// Throw away the previous equality (it needs to be reevaluated).
@@ -842,7 +835,7 @@
curDiff = (Difference) equalities.lastElement();
while (curDiff != pointer.previous())
{
- // Intentionally empty loop.
+ // Intentionally empty loop.
}
}
@@ -925,10 +918,12 @@
// <ins>A</ins><del>B</del>X<ins>C</ins>
// <ins>A</del>X<ins>C</ins><del>D</del>
// <ins>A</ins><del>B</del>X<del>C</del>
- if (lastequality != null && (((pre_ins + pre_del + post_ins + post_del) > 0) || ((lastequality.length() < EDIT_COST/2) && (pre_ins + pre_del + post_ins + post_del) == 3)))
+ if (lastequality != null
+ && (((pre_ins + pre_del + post_ins + post_del) > 0) || ((lastequality.length() < EDIT_COST / 2) && (pre_ins + pre_del + post_ins + post_del) == 3)))
{
// position pointer to the element after the one at the end of the stack
- while (curDiff != equalities.lastElement()) {
+ while (curDiff != equalities.lastElement())
+ {
curDiff = (Difference) pointer.previous();
}
pointer.next();
@@ -939,7 +934,7 @@
curDiff = new Difference(EditType.INSERT, lastequality);
pointer.add(curDiff);
- equalities.pop(); // Throw away the equality we just deleted;
+ equalities.pop(); // Throw away the equality we just deleted;
lastequality = null;
if (pre_ins == 1 && pre_del == 1)
{
@@ -987,7 +982,6 @@
}
}
-
/**
* Reorder and merge like edit sections. Merge equalities.
* Any edit section can move as long as it doesn't cross an equality.
@@ -996,7 +990,7 @@
public static void cleanupMerge(List diffs)
{
// Add a dummy entry at the end.
- diffs.add(new Difference(EditType.EQUAL, "")); //$NON-NLS-1$
+ diffs.add(new Difference(EditType.EQUAL, "")); //$NON-NLS-1$
int count_delete = 0;
int count_insert = 0;
@@ -1030,13 +1024,15 @@
{
// Delete the offending records.
pointer.previous(); // Reverse direction.
- while (count_delete-- > 0) {
- pointer.previous();
- pointer.remove();
+ while (count_delete-- > 0)
+ {
+ pointer.previous();
+ pointer.remove();
}
- while (count_insert-- > 0) {
- pointer.previous();
- pointer.remove();
+ while (count_insert-- > 0)
+ {
+ pointer.previous();
+ pointer.remove();
}
if (count_delete != 0 && count_insert != 0)
@@ -1107,7 +1103,7 @@
Difference lastDiff = (Difference) diffs.get(diffs.size() - 1);
if (lastDiff.getText().length() == 0)
{
- diffs.remove(diffs.size() - 1); // Remove the dummy entry at the end.
+ diffs.remove(diffs.size() - 1); // Remove the dummy entry at the end.
}
}
@@ -1297,11 +1293,11 @@
/**
* Number of seconds to map a diff before giving up. (0 for infinity)
*/
- public static final double TIMEOUT = 1.0;
+ public static final double TIMEOUT = 1.0;
/**
* Cost of an empty edit operation in terms of edit characters.
*/
- public static final int EDIT_COST = 4;
+ public static final int EDIT_COST = 4;
}
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Match.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Match.java 2007-05-22 01:05:57 UTC (rev 1337)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Match.java 2007-05-22 11:41:51 UTC (rev 1338)
@@ -39,10 +39,11 @@
// Locate the best instance of 'pattern' in 'text' near 'loc'.
public static int main(String text, String pattern, int loc)
{
- if (text.length() == 0) {
+ if (text.length() == 0)
+ {
// Nothing to match.
return -1;
- }
+ }
if (text.equals(pattern))
{
@@ -79,14 +80,14 @@
int best_loc = text.indexOf(pattern, loc);
if (best_loc != -1)
{
- score_threshold = Math.min(Match.bitap_score(pattern, score_text_length, loc, 0, best_loc), score_threshold);
+ score_threshold = Math.min(Match.bitapScore(pattern, score_text_length, loc, 0, best_loc), score_threshold);
}
-
+
// What about in the other direction? (speedup)
best_loc = text.lastIndexOf(pattern, loc + pattern.length());
if (best_loc != -1)
{
- score_threshold = Math.min(Match.bitap_score(pattern, score_text_length, loc, 0, best_loc), score_threshold);
+ score_threshold = Math.min(Match.bitapScore(pattern, score_text_length, loc, 0, best_loc), score_threshold);
}
// Initialise the bit arrays.
@@ -108,7 +109,7 @@
bin_mid = bin_max;
while (bin_min < bin_mid)
{
- if (Match.bitap_score(pattern, score_text_length, loc, d, bin_mid) < score_threshold)
+ if (Match.bitapScore(pattern, score_text_length, loc, d, bin_mid) < score_threshold)
{
bin_min = bin_mid;
}
@@ -147,7 +148,7 @@
if ((rd[j] & matchmask) != 0)
{
- double score = Match.bitap_score(pattern, score_text_length, loc, d, j);
+ double score = Match.bitapScore(pattern, score_text_length, loc, d, j);
// This match will almost certainly be better than any existing match. But check anyway.
if (score <= score_threshold)
{
@@ -168,7 +169,7 @@
}
}
- if (Match.bitap_score(pattern, score_text_length, loc, d + 1, loc) > score_threshold) // No hope for a (better) match at greater error levels.
+ if (Match.bitapScore(pattern, score_text_length, loc, d + 1, loc) > score_threshold) // No hope for a (better) match at greater error levels.
{
// No hope for a (better) match at greater error levels.
break;
@@ -180,11 +181,11 @@
return best_loc;
}
- private static double bitap_score(String pattern, int score_text_length, int loc, int e, int x)
+ private static double bitapScore(String pattern, int score_text_length, int loc, int e, int x)
{
// Compute and return the score for a match with e errors and x location.
int d = Math.abs(loc - x);
- return (e / (float)pattern.length() / Match.BALANCE) + (d / (float) score_text_length / (1.0 - Match.BALANCE));
+ return (e / (float) pattern.length() / Match.BALANCE) + (d / (float) score_text_length / (1.0 - Match.BALANCE));
}
// Initialize the alphabet for the Bitap algorithm.
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Patch.java 2007-05-22 01:05:57 UTC (rev 1337)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Patch.java 2007-05-22 11:41:51 UTC (rev 1338)
@@ -91,7 +91,8 @@
patch.adjustLength2(len);
}
- if (EditType.EQUAL.equals(editType) && len >= 2 * Patch.MARGIN) {
+ if (EditType.EQUAL.equals(editType) && len >= 2 * Patch.MARGIN)
+ {
// Time for a new patch.
if (patch.hasDifferences())
{
@@ -211,7 +212,7 @@
* limit of the match algorithm.
* @param patches List of Patch objects.
*/
- static public void splitMax(List patches)
+ public static void splitMax(List patches)
{
ListIterator pointer = patches.listIterator();
PatchEntry bigpatch = pointer.hasNext() ? (PatchEntry) pointer.next() : null;
@@ -324,7 +325,8 @@
* @param patches List of Patch objects.
* @return Text representation of patches.
*/
- public static String toText(List patches) {
+ public static String toText(List patches)
+ {
StringBuffer text = new StringBuffer();
Iterator iter = patches.iterator();
while (iter.hasNext())
@@ -353,7 +355,7 @@
{
Matcher matcher = patchPattern.matcher(text[lineCount]);
matcher.matches();
- assert matcher.groupCount() == 4 : "Invalid patch string:\n"+text[lineCount]; //$NON-NLS-1$
+ assert matcher.groupCount() == 4 : "Invalid patch string:\n" + text[lineCount]; //$NON-NLS-1$
// m = text[0].match(/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/);
patch = new PatchEntry();
@@ -413,7 +415,7 @@
case '@': // start of next patch
break consume;
default: // What!!!
- assert false : "Invalid patch mode: '"+sign+"'\n"+line; //$NON-NLS-1$ //$NON-NLS-2$
+ assert false : "Invalid patch mode: '" + sign + "'\n" + line; //$NON-NLS-1$ //$NON-NLS-2$
}
}
lineCount++;
More information about the jsword-svn
mailing list