[jsword-svn] r1418 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic common/src/main/java/org/crosswire/common/compress common/src/main/java/org/crosswire/common/config common/src/main/java/org/crosswire/common/diff common/src/main/java/org/crosswire/common/util common/src/test/java/org/crosswire/common/diff

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Wed Jun 20 05:00:39 MST 2007


Author: dmsmith
Date: 2007-06-20 05:00:38 -0700 (Wed, 20 Jun 2007)
New Revision: 1418

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
   trunk/common/src/main/java/org/crosswire/common/compress/Compressor.java
   trunk/common/src/main/java/org/crosswire/common/config/Config.java
   trunk/common/src/main/java/org/crosswire/common/diff/Diff.java
   trunk/common/src/main/java/org/crosswire/common/diff/Difference.java
   trunk/common/src/main/java/org/crosswire/common/diff/DifferenceEngine.java
   trunk/common/src/main/java/org/crosswire/common/diff/LineMap.java
   trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
   trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
   trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java
   trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java
Log:
checkstyle and javadoc changes

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -375,13 +375,13 @@
             center = comp;
             if (center == tabMain)
             {
-            	pnlMain.add(tabMain, BorderLayout.CENTER);
-   	        }
-   	        else
-   	        {
-   	        	pnlMain.add(scrMain, BorderLayout.CENTER);
-				//scrMain.setViewportView(center);
-   	 	    }
+                pnlMain.add(tabMain, BorderLayout.CENTER);
+            }
+            else
+            {
+                pnlMain.add(scrMain, BorderLayout.CENTER);
+                //scrMain.setViewportView(center);
+            }
         }
     }
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -103,7 +103,6 @@
      */
     public void setBookData(Book[] books, Key key)
     {
-        
         if (books == null || books.length == 0 || books[0] == null || key == null)
         {
             bdata = null;

Modified: trunk/common/src/main/java/org/crosswire/common/compress/Compressor.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/compress/Compressor.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/compress/Compressor.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -57,7 +57,7 @@
     /**
      * Uncompresses the input and provides the result.
      * 
-     * @param expectedSize the size of the result buffer
+     * @param expectedLength the size of the result buffer
      * @return the uncompressed result
      */
     ByteArrayOutputStream uncompress(int expectedLength) throws IOException;

Modified: trunk/common/src/main/java/org/crosswire/common/config/Config.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -103,8 +103,7 @@
 
     /**
      * Add a key/model pairing
-     * @param key The new name
-     * @param model The Field model to map to the key
+     * @param model The Choice model to map to its key
      */
     public void add(Choice model)
     {

Modified: trunk/common/src/main/java/org/crosswire/common/diff/Diff.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Diff.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Diff.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -39,66 +39,60 @@
 public class Diff
 {
     /**
-     * Find the differences between two texts.
+     * Construct an object that can find the differences between two texts.
      * Run a faster slightly less optimal diff.
-     * This method allows the 'checkLines' of main() to be optional.
+     * This constructor allows the 'checkLines' to be optional.
      * Most of the time checkLines is wanted, so default to true.
-     * @param text1 Old string to be diffed
-     * @param text2 New string to be diffed
+     * @param source Old string to be diffed
+     * @param target New string to be diffed
      */
-    public Diff(final String text1, final String text2)
+    public Diff(final String source, final String target)
     {
-        this(text1, text2, true);
+        this(source, target, true);
     }
 
     /**
-     * Find the differences between two texts.  Simplifies the problem by
-     * stripping any common prefix or suffix off the texts before diffing.
-     * @param text1 Old string to be diffed
-     * @param text2 New string to be diffed
+     * Construct an object that can find the differences between two texts.
+     * @param source Old string to be diffed
+     * @param target New string to be diffed
      * @param checkLines Speedup flag.  If false, then don't run a
      *     line-level diff first to identify the changed areas.
      *     If true, then run a faster slightly less optimal diff
      */
-    public Diff(final String text1, final String text2, final boolean checkLines)
+    public Diff(final String source, final String target, final boolean checkLines)
     {
-        this.text1 = text1;
-        this.text2 = text2;
+        this.source = source;
+        this.target = target;
         this.checkLines = checkLines;
     }
 
     /**
      * Find the differences between two texts.  Simplifies the problem by
      * stripping any common prefix or suffix off the texts before diffing.
-     * @param text1 Old string to be diffed
-     * @param text2 New string to be diffed
-     * @param checkLines Speedup flag.  If false, then don't run a
-     *     line-level diff first to identify the changed areas.
-     *     If true, then run a faster slightly less optimal diff
      * @return List of Difference objects
      */
     public List compare()
     {
         // Check for equality (speedup)
         List diffs;
-        if (text1.equals(text2))
+        if (source.equals(target))
         {
             diffs = new ArrayList();
-            diffs.add(new Difference(EditType.EQUAL, text1));
+            diffs.add(new Difference(EditType.EQUAL, source));
             return diffs;
         }
 
         // Trim off common prefix (speedup)
-        int commonLength = Commonality.prefix(text1, text2);
-        String commonPrefix = text1.substring(0, commonLength);
-        text1 = text1.substring(commonLength);
-        text2 = text2.substring(commonLength);
+        int commonLength = Commonality.prefix(source, target);
+        String commonPrefix = source.substring(0, commonLength);
+        source = source.substring(commonLength);
+        target = target.substring(commonLength);
 
         // Trim off common suffix (speedup)
-        commonLength = Commonality.suffix(text1, text2);
-        String commonSuffix = text1.substring(text1.length() - commonLength);
-        text1 = text1.substring(0, text1.length() - commonLength);
-        text2 = text2.substring(0, text2.length() - commonLength);
+        commonLength = Commonality.suffix(source, target);
+        String commonSuffix = source.substring(source.length() - commonLength);
+        source = source.substring(0, source.length() - commonLength);
+        target = target.substring(0, target.length() - commonLength);
 
         // Compute the diff on the middle block
         diffs = compute();
@@ -121,38 +115,33 @@
 
     /**
      * Find the differences between two texts.
-     * @param text1 Old string to be diffed
-     * @param text2 New string to be diffed
-     * @param checkLines Speedup flag.  If false, then don't run a
-     *     line-level diff first to identify the changed areas.
-     *     If true, then run a faster slightly less optimal diff
      * @return List of Difference objects
      */
     private List compute()
     {
         List diffs = new ArrayList();
 
-        if ("".equals(text1)) //$NON-NLS-1$
+        if ("".equals(source)) //$NON-NLS-1$
         {
             // Just add some text (speedup)
-            diffs.add(new Difference(EditType.INSERT, text2));
+            diffs.add(new Difference(EditType.INSERT, target));
             return diffs;
         }
 
-        if ("".equals(text2)) //$NON-NLS-1$
+        if ("".equals(target)) //$NON-NLS-1$
         {
             // Just delete some text (speedup)
-            diffs.add(new Difference(EditType.DELETE, text1));
+            diffs.add(new Difference(EditType.DELETE, source));
             return diffs;
         }
 
-        String longText = text1.length() > text2.length() ? text1 : text2;
-        String shortText = text1.length() > text2.length() ? text2 : text1;
+        String longText = source.length() > target.length() ? source : target;
+        String shortText = source.length() > target.length() ? target : source;
         int i = longText.indexOf(shortText);
         if (i != -1)
         {
             // Shorter text is inside the longer text (speedup)
-            EditType editType = (text1.length() > text2.length()) ? EditType.DELETE : EditType.INSERT;
+            EditType editType = (source.length() > target.length()) ? EditType.DELETE : EditType.INSERT;
             diffs.add(new Difference(editType, longText.substring(0, i)));
             diffs.add(new Difference(EditType.EQUAL, shortText));
             diffs.add(new Difference(editType, longText.substring(i + shortText.length())));
@@ -160,7 +149,7 @@
         }
 
         // Check to see if the problem can be split in two.
-        CommonMiddle middleMatch = Commonality.halfMatch(text1, text2);
+        CommonMiddle middleMatch = Commonality.halfMatch(source, target);
         if (middleMatch != null)
         {
             // A half-match was found, sort out the return data.
@@ -175,7 +164,7 @@
         }
 
         // Perform a real diff.
-        if (checkLines && text1.length() + text2.length() < 250)
+        if (checkLines && source.length() + target.length() < 250)
         {
             checkLines = false; // Too trivial for the overhead.
         }
@@ -184,19 +173,19 @@
         if (checkLines)
         {
             // Scan the text on a line-by-line basis first.
-            lineMap = new LineMap(text1, text2);
-            text1 = lineMap.getSourceMap();
-            text2 = lineMap.getTargetMap();
+            lineMap = new LineMap(source, target);
+            source = lineMap.getSourceMap();
+            target = lineMap.getTargetMap();
         }
 
-        diffs = new DifferenceEngine(text1, text2).generate();
+        diffs = new DifferenceEngine(source, target).generate();
 
         if (diffs == null)
         {
             // No acceptable result.
             diffs = new ArrayList();
-            diffs.add(new Difference(EditType.DELETE, text1));
-            diffs.add(new Difference(EditType.INSERT, text2));
+            diffs.add(new Difference(EditType.DELETE, source));
+            diffs.add(new Difference(EditType.INSERT, target));
         }
 
         if (checkLines && lineMap != null)
@@ -260,12 +249,12 @@
     }
 
     /**
-     * loc is a location in text1, compute and return the equivalent location in
-     * text2.
+     * loc is a location in source, compute and return the equivalent location in
+     * target.
      * e.g. "The cat" vs "The big cat", 1->1, 5->8
      * @param diffs List of Difference objects
-     * @param loc Location within text1
-     * @return Location within text2
+     * @param loc Location within source
+     * @return Location within target
      */
     public int xIndex(final List diffs, final int loc)
     {
@@ -349,12 +338,12 @@
     /**
      * The baseline text.
      */
-    private String text1;
+    private String source;
 
     /**
      * The changed text.
      */
-    private String text2;
+    private String target;
 
     /**
      * Whether a slightly faster less optimal diff should be run.

Modified: trunk/common/src/main/java/org/crosswire/common/diff/Difference.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Difference.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Difference.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -46,7 +46,7 @@
     }
 
     /**
-     * @param edit the EditType to set
+     * @param newEditType the EditType to set
      */
     public void setEditType(EditType newEditType)
     {
@@ -62,7 +62,7 @@
     }
 
     /**
-     * @param text the text to set
+     * @param newText the text to set
      */
     public void setText(String newText)
     {
@@ -78,7 +78,7 @@
     }
 
     /**
-     * @param index the index to set
+     * @param newIndex the index to set
      */
     public void setIndex(int newIndex)
     {
@@ -86,7 +86,7 @@
     }
 
     /**
-     * @param text the text to set
+     * @param addText the text to set
      */
     public void appendText(String addText)
     {
@@ -94,7 +94,7 @@
     }
 
     /**
-     * @param text the text to set
+     * @param addText the text to set
      */
     public void appendText(char addText)
     {
@@ -102,7 +102,7 @@
     }
 
     /**
-     * @param text the text to set
+     * @param addText the text to set
      */
     public void prependText(String addText)
     {
@@ -110,7 +110,7 @@
     }
 
     /**
-     * @param text the text to set
+     * @param addText the text to set
      */
     public void prependText(char addText)
     {

Modified: trunk/common/src/main/java/org/crosswire/common/diff/DifferenceEngine.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/DifferenceEngine.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/DifferenceEngine.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -53,9 +53,6 @@
      * stripping any common prefix or suffix off the texts before diffing.
      * @param source Old string to be diffed
      * @param target New string to be diffed
-     * @param checkLines Speedup flag.  If false, then don't run a
-     *     line-level diff first to identify the changed areas.
-     *     If true, then run a faster slightly less optimal diff
      */
     public DifferenceEngine(final String source, final String target)
     {
@@ -81,8 +78,6 @@
 
     /**
      * Explore the intersection points between the two texts.
-     * @param source Old string to be diffed
-     * @param target New string to be diffed
      * @return List of Difference objects or null if no diff available
      */
     public List generate()
@@ -228,15 +223,15 @@
     /**
      * Work from the middle back to the start to determine the path.
      * @param vMap List of path sets.
-     * @param left Old string fragment to be diffed
-     * @param right New string fragment to be diffed
+     * @param newSource Old string fragment to be diffed
+     * @param newTarget New string fragment to be diffed
      * @return List of Difference objects
      */
-    protected List path1(final List vMap, final String left, final String right)
+    protected List path1(final List vMap, final String newSource, final String newTarget)
     {
         List path = new ArrayList();
-        int x = left.length();
-        int y = right.length();
+        int x = newSource.length();
+        int y = newTarget.length();
         EditType lastEditType = null;
         for (int d = vMap.size() - 2; d >= 0; d--)
         {
@@ -249,11 +244,11 @@
                     if (EditType.DELETE.equals(lastEditType))
                     {
                         Difference firstDiff = (Difference) path.get(0);
-                        firstDiff.prependText(left.charAt(x));
+                        firstDiff.prependText(newSource.charAt(x));
                     }
                     else
                     {
-                        path.add(0, new Difference(EditType.DELETE, left.substring(x, x + 1)));
+                        path.add(0, new Difference(EditType.DELETE, newSource.substring(x, x + 1)));
                     }
                     lastEditType = EditType.DELETE;
                     break;
@@ -264,11 +259,11 @@
                     if (EditType.INSERT.equals(lastEditType))
                     {
                         Difference firstDiff = (Difference) path.get(0);
-                        firstDiff.prependText(right.charAt(y));
+                        firstDiff.prependText(newTarget.charAt(y));
                     }
                     else
                     {
-                        path.add(0, new Difference(EditType.INSERT, right.substring(y, y + 1)));
+                        path.add(0, new Difference(EditType.INSERT, newTarget.substring(y, y + 1)));
                     }
                     lastEditType = EditType.INSERT;
                     break;
@@ -277,15 +272,15 @@
                 {
                     x--;
                     y--;
-                    assert left.charAt(x) == right.charAt(y) : "No diagonal.  Can't happen. (path1)"; //$NON-NLS-1$
+                    assert newSource.charAt(x) == newTarget.charAt(y) : "No diagonal.  Can't happen. (path1)"; //$NON-NLS-1$
                     if (EditType.EQUAL.equals(lastEditType))
                     {
                         Difference firstDiff = (Difference) path.get(0);
-                        firstDiff.prependText(left.charAt(x));
+                        firstDiff.prependText(newSource.charAt(x));
                     }
                     else
                     {
-                        path.add(0, new Difference(EditType.EQUAL, left.substring(x, x + 1)));
+                        path.add(0, new Difference(EditType.EQUAL, newSource.substring(x, x + 1)));
                     }
                     lastEditType = EditType.EQUAL;
                 }
@@ -297,15 +292,15 @@
     /**
      * Work from the middle back to the end to determine the path.
      * @param vMap List of path sets.
-     * @param left Old string fragment to be diffed
-     * @param right New string fragment to be diffed
+     * @param newSource Old string fragment to be diffed
+     * @param newTarget New string fragment to be diffed
      * @return List of Difference objects
      */
-    protected List path2(final List vMap, final String left, final String right)
+    protected List path2(final List vMap, final String newSource, final String newTarget)
     {
         List path = new ArrayList();
-        int x = left.length();
-        int y = right.length();
+        int x = newSource.length();
+        int y = newTarget.length();
         EditType lastEditType = null;
         for (int d = vMap.size() - 2; d >= 0; d--)
         {
@@ -318,11 +313,11 @@
                     if (EditType.DELETE.equals(lastEditType))
                     {
                         Difference lastDiff = (Difference) path.get(path.size() - 1);
-                        lastDiff.appendText(left.charAt(left.length() - x - 1));
+                        lastDiff.appendText(newSource.charAt(newSource.length() - x - 1));
                     }
                     else
                     {
-                        path.add(new Difference(EditType.DELETE, left.substring(left.length() - x - 1, left.length() - x)));
+                        path.add(new Difference(EditType.DELETE, newSource.substring(newSource.length() - x - 1, newSource.length() - x)));
                     }
                     lastEditType = EditType.DELETE;
                     break;
@@ -333,11 +328,11 @@
                     if (EditType.INSERT.equals(lastEditType))
                     {
                         Difference lastDiff = (Difference) path.get(path.size() - 1);
-                        lastDiff.appendText(right.charAt(right.length() - y - 1));
+                        lastDiff.appendText(newTarget.charAt(newTarget.length() - y - 1));
                     }
                     else
                     {
-                        path.add(new Difference(EditType.INSERT, right.substring(right.length() - y - 1, right.length() - y)));
+                        path.add(new Difference(EditType.INSERT, newTarget.substring(newTarget.length() - y - 1, newTarget.length() - y)));
                     }
                     lastEditType = EditType.INSERT;
                     break;
@@ -346,16 +341,16 @@
                 {
                     x--;
                     y--;
-                    assert left.charAt(left.length() - x - 1) == right.charAt(right.length() - y - 1) : "No diagonal.  Can't happen. (path2)"; //$NON-NLS-1$
+                    assert newSource.charAt(newSource.length() - x - 1) == newTarget.charAt(newTarget.length() - y - 1) : "No diagonal.  Can't happen. (path2)"; //$NON-NLS-1$
 
                     if (EditType.EQUAL.equals(lastEditType))
                     {
                         Difference lastDiff = (Difference) path.get(path.size() - 1);
-                        lastDiff.appendText(left.charAt(left.length() - x - 1));
+                        lastDiff.appendText(newSource.charAt(newSource.length() - x - 1));
                     }
                     else
                     {
-                        path.add(new Difference(EditType.EQUAL, left.substring(left.length() - x - 1, left.length() - x)));
+                        path.add(new Difference(EditType.EQUAL, newSource.substring(newSource.length() - x - 1, newSource.length() - x)));
                     }
                     lastEditType = EditType.EQUAL;
                 }
@@ -364,6 +359,11 @@
         return path;
     }
 
+    /**
+     * Set the timeout for the diff operation. 0 for infinity. Default is 1 second.
+     * 
+     * @param newTimeout
+     */
     public static void setTimeout(float newTimeout)
     {
         timeout = newTimeout;

Modified: trunk/common/src/main/java/org/crosswire/common/diff/LineMap.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/LineMap.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/LineMap.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -62,7 +62,6 @@
      * Rehydrate the text in a diff from a string of line hashes to real lines of
      * text.
      * @param diffs List of Difference objects
-     * @param linearray List of unique strings
      */
     public void restore(final List diffs)
     {

Modified: trunk/common/src/main/java/org/crosswire/common/diff/Patch.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Patch.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Patch.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -60,8 +60,8 @@
 
     /**
      * Create a patch that can turn text1 into text2.
-     * @param text1 Old text
-     * @param text2 New text
+     * @param source Old text
+     * @param target New text
      */
     public Patch(String source, String target)
     {
@@ -71,8 +71,8 @@
     /**
      * Create a patch that can turn text1 into text2.
      * Use the diffs provided, if not null. Compute diffs otherwise.
-     * @param text1 Old text
-     * @param text2 New text
+     * @param source Old text
+     * @param target New text
      * @param diffs Optional array of diff tuples for text1 to text2.
      */
     public Patch(String source, String target, List diffs)
@@ -84,17 +84,17 @@
     /**
      * Compute a list of patches to turn text1 into text2.
      * Use the diffs provided.
-     * @param text1 Old text
-     * @param text2 New text
+     * @param source Old text
+     * @param target New text
      * @param diffs Optional array of diff tuples for text1 to text2.
      * @return this patch
      */
-    public Patch make(String text1, String text2, List diffList)
+    public Patch make(String source, String target, List diffList)
     {
         List diffs = diffList;
         if (diffs == null)
         {
-            Diff diff = new Diff(text1, text2);
+            Diff diff = new Diff(source, target);
             diffs = diff.compare();
             if (diffs.size() > 2)
             {
@@ -114,8 +114,8 @@
         int charCount1 = 0; // Number of characters into the text1 string.
         int charCount2 = 0; // Number of characters into the text2 string.
         // Recreate the patches to determine context info.
-        String prePatchText = text1;
-        String postPatchText = text1;
+        String prePatchText = source;
+        String postPatchText = source;
         Iterator iter = diffs.iterator();
         int x = 0;
         while (iter.hasNext())
@@ -128,21 +128,21 @@
             if (!patch.hasDifferences() && !EditType.EQUAL.equals(editType))
             {
                 // A new patch starts here.
-                patch.setLeftStart(charCount1);
-                patch.setRightStart(charCount2);
+                patch.setSourceStart(charCount1);
+                patch.setTargetStart(charCount2);
             }
 
             if (EditType.INSERT.equals(editType))
             {
                 // Insertion
                 patch.addDifference(diff);
-                patch.adjustLength2(len);
+                patch.adjustTargetLength(len);
                 postPatchText = postPatchText.substring(0, charCount2) + diffText + postPatchText.substring(charCount2);
             }
             else if (EditType.DELETE.equals(editType))
             {
                 // Deletion.
-                patch.adjustLength1(len);
+                patch.adjustSourceLength(len);
                 patch.addDifference(diff);
                 postPatchText = postPatchText.substring(0, charCount2) + postPatchText.substring(charCount2 + len);
             }
@@ -150,8 +150,8 @@
             {
                 // Small equality inside a patch.
                 patch.addDifference(diff);
-                patch.adjustLength1(len);
-                patch.adjustLength2(len);
+                patch.adjustSourceLength(len);
+                patch.adjustTargetLength(len);
             }
 
             // Time for a new patch.
@@ -213,8 +213,8 @@
         while (patchIter.hasNext())
         {
             PatchEntry aPatch = (PatchEntry) patchIter.next();
-            expectedLoc = aPatch.getRightStart() + delta;
-            text1 = aPatch.getLeftText();
+            expectedLoc = aPatch.getTargetStart() + delta;
+            text1 = aPatch.getSourceText();
             Match match = new Match(resultText, text1, expectedLoc);
             startLoc = match.locate();
             if (startLoc == -1)
@@ -231,7 +231,7 @@
                 if (text1.equals(text2))
                 {
                     // Perfect match, just shove the replacement text in.
-                    resultText = resultText.substring(0, startLoc) + aPatch.getRightText() + resultText.substring(startLoc + text1.length());
+                    resultText = resultText.substring(0, startLoc) + aPatch.getTargetText() + resultText.substring(startLoc + text1.length());
                 }
                 else
                 {
@@ -273,7 +273,6 @@
     /**
      * Look through the patches and break up any which are longer than the maximum
      * limit of the match algorithm.
-     * @param patches List of Patch objects.
      */
     public void splitMax()
     {
@@ -282,7 +281,7 @@
         PatchEntry bigPatch = pointer.hasNext() ? (PatchEntry) pointer.next() : null;
         while (bigPatch != null)
         {
-            if (bigPatch.getLeftLength() <= maxPatternLength)
+            if (bigPatch.getSourceLength() <= maxPatternLength)
             {
                 if (!pointer.hasNext())
                 {
@@ -295,8 +294,8 @@
             // Remove the big old patch.
             pointer.remove();
             int patchSize = maxPatternLength;
-            int start1 = bigPatch.getLeftStart();
-            int start2 = bigPatch.getRightStart();
+            int start1 = bigPatch.getSourceStart();
+            int start2 = bigPatch.getTargetStart();
             String preContext = ""; //$NON-NLS-1$
             while (bigPatch.hasDifferences())
             {
@@ -305,16 +304,16 @@
                 boolean empty = true;
 
                 int len = preContext.length();
-                patch.setLeftStart(start1 - len);
-                patch.setRightStart(start2 - len);
+                patch.setSourceStart(start1 - len);
+                patch.setTargetStart(start2 - len);
                 if (len > 0)
                 {
-                    patch.setLeftLength(len);
-                    patch.setRightLength(len);
+                    patch.setSourceLength(len);
+                    patch.setTargetLength(len);
                     patch.addDifference(new Difference(EditType.EQUAL, preContext));
                 }
 
-                while (bigPatch.hasDifferences() && patch.getLeftLength() < patchSize - margin)
+                while (bigPatch.hasDifferences() && patch.getSourceLength() < patchSize - margin)
                 {
                     Difference bigDiff = bigPatch.getFirstDifference();
                     EditType editType = bigDiff.getEditType();
@@ -323,7 +322,7 @@
                     {
                         // Insertions are harmless.
                         len = diffText.length();
-                        patch.adjustLength2(len);
+                        patch.adjustTargetLength(len);
                         start2 += len;
                         patch.addDifference(bigPatch.removeFirstDifference());
                         empty = false;
@@ -331,13 +330,13 @@
                     else
                     {
                         // Deletion or equality.  Only take as much as we can stomach.
-                        diffText = diffText.substring(0, Math.min(diffText.length(), patchSize - patch.getLeftLength() - margin));
+                        diffText = diffText.substring(0, Math.min(diffText.length(), patchSize - patch.getSourceLength() - margin));
                         len = diffText.length();
-                        patch.adjustLength1(len);
+                        patch.adjustSourceLength(len);
                         start1 += len;
                         if (EditType.EQUAL.equals(editType))
                         {
-                            patch.adjustLength2(len);
+                            patch.adjustTargetLength(len);
                             start2 += len;
                         }
                         else
@@ -359,23 +358,23 @@
                 }
 
                 // Compute the head context for the next patch.
-                preContext = patch.getRightText();
+                preContext = patch.getTargetText();
                 preContext = preContext.substring(Math.max(0, preContext.length() - margin));
 
                 // Append the end context for this patch.
                 String postcontext = null;
-                if (bigPatch.getLeftText().length() > margin)
+                if (bigPatch.getSourceText().length() > margin)
                 {
-                    postcontext = bigPatch.getLeftText().substring(0, margin);
+                    postcontext = bigPatch.getSourceText().substring(0, margin);
                 }
                 else
                 {
-                    postcontext = bigPatch.getLeftText();
+                    postcontext = bigPatch.getSourceText();
                 }
                 if (postcontext.length() > 0)
                 {
-                    patch.adjustLength1(postcontext.length());
-                    patch.adjustLength2(postcontext.length());
+                    patch.adjustSourceLength(postcontext.length());
+                    patch.adjustTargetLength(postcontext.length());
                     if (patch.getDifferenceCount() > 0 && EditType.EQUAL.equals(patch.getLastDifference().getEditType()))
                     {
                         Difference diff = patch.getLastDifference();
@@ -399,7 +398,6 @@
 
     /**
      * Take a list of patches and return a textual representation.
-     * @param patches List of Patch objects.
      * @return Text representation of patches.
      */
     public String toText()
@@ -416,7 +414,7 @@
     /**
      * Parse a textual representation of patches and return a List of Patch
      * objects.
-     * @param textline Text representation of patches
+     * @param input Text representation of patches
      * @return List of Patch objects
      */
     public Patch fromText(String input)

Modified: trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/diff/PatchEntry.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -44,10 +44,10 @@
     public PatchEntry()
     {
         this.diffs = new ArrayList();
-        this.leftStart = 0;
-        this.rightStart = 0;
-        this.leftLength = 0;
-        this.rightLength = 0;
+        this.sourceStart = 0;
+        this.targetStart = 0;
+        this.sourceLength = 0;
+        this.targetLength = 0;
     }
 
     //  Constructor for a patch object.
@@ -58,99 +58,99 @@
     }
 
     /**
-     * @return the leftStart
+     * @return the sourceStart
      */
-    public int getLeftStart()
+    public int getSourceStart()
     {
-        return leftStart;
+        return sourceStart;
     }
 
     /**
-     * @param leftStart the leftStart to set
+     * @param start the sourceStart to set
      */
-    public void setLeftStart(int start1)
+    public void setSourceStart(int start)
     {
-        this.leftStart = start1;
+        this.sourceStart = start;
     }
 
     /**
-     * @param adjustment the adjustment to leftStart
+     * @param adjustment the adjustment to sourceStart
      */
-    public void adjustLeftStart(int adjustment)
+    public void adjustSourceStart(int adjustment)
     {
-        this.leftStart += adjustment;
+        this.sourceStart += adjustment;
     }
 
     /**
-     * @return the rightStart
+     * @return the targetStart
      */
-    public int getRightStart()
+    public int getTargetStart()
     {
-        return rightStart;
+        return targetStart;
     }
 
     /**
-     * @param rightStart the rightStart to set
+     * @param start the targetStart to set
      */
-    public void setRightStart(int start2)
+    public void setTargetStart(int start)
     {
-        this.rightStart = start2;
+        this.targetStart = start;
     }
 
     /**
-     * @param adjustment the adjustment to rightStart
+     * @param adjustment the adjustment to targetStart
      */
-    public void adjustRightStart(int adjustment)
+    public void adjustTargetStart(int adjustment)
     {
-        this.rightStart += adjustment;
+        this.targetStart += adjustment;
     }
 
     /**
-     * @return the leftLength
+     * @return the sourceLength
      */
-    public int getLeftLength()
+    public int getSourceLength()
     {
-        return leftLength;
+        return sourceLength;
     }
 
     /**
-     * @param leftLength the leftLength to set
+     * @param length the sourceLength to set
      */
-    public void setLeftLength(int length1)
+    public void setSourceLength(int length)
     {
-        this.leftLength = length1;
+        this.sourceLength = length;
     }
 
     /**
-     * @param adjustment the adjustment to leftLength
+     * @param adjustment the adjustment to sourceLength
      */
-    public void adjustLength1(int adjustment)
+    public void adjustSourceLength(int adjustment)
     {
-        this.leftLength += adjustment;
+        this.sourceLength += adjustment;
     }
 
     /**
-     * @return the rightLength
+     * @return the targetLength
      */
-    public int getRightLength()
+    public int getTargetLength()
     {
-        return rightLength;
+        return targetLength;
     }
 
     /**
-     * @param rightLength the rightLength to set
+     * @param length the targetLength to set
      */
-    public void setRightLength(int length2)
+    public void setTargetLength(int length)
     {
-        this.rightLength = length2;
+        this.targetLength = length;
     }
 
     /**
-     * @param adjustment the adjustment to rightLength
+     * @param adjustment the adjustment to targetLength
      */
-    public void adjustLength2(int adjustment)
+    public void adjustTargetLength(int adjustment)
     {
-        this.rightLength += adjustment;
+        this.targetLength += adjustment;
     }
 
     //  Emmulate GNU diff's format.
@@ -160,9 +160,9 @@
     {
         StringBuffer txt = new StringBuffer();
         txt.append("@@ -"); //$NON-NLS-1$
-        txt.append(getCoordinates(leftStart, leftLength));
+        txt.append(getCoordinates(sourceStart, sourceLength));
         txt.append(" +"); //$NON-NLS-1$
-        txt.append(getCoordinates(rightStart, rightLength));
+        txt.append(getCoordinates(targetStart, targetLength));
         txt.append(" @@\n"); //$NON-NLS-1$
 
         Iterator iter = diffs.iterator();
@@ -175,6 +175,7 @@
         }
         return txt.toString();
     }
+
     /**
      * Parse a textual representation of a patch entry and populate this patch entry.
      * @param input Text representation of this patch entry
@@ -192,37 +193,37 @@
         assert matcher.groupCount() == 4 : "Invalid patch string:\n" + text[0]; //$NON-NLS-1$
         // m = text[0].match(/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/);
 
-        leftStart = Integer.parseInt(matcher.group(1));
+        sourceStart = Integer.parseInt(matcher.group(1));
 
         if (matcher.group(2).length() == 0)
         {
-            leftStart--;
-            leftLength = 1;
+            sourceStart--;
+            sourceLength = 1;
         }
         else if (matcher.group(2).charAt(0) == '0')
         {
-            setLeftLength(0);
+            setSourceLength(0);
         }
         else
         {
-            leftStart--;
-            leftLength = Integer.parseInt(matcher.group(2));
+            sourceStart--;
+            sourceLength = Integer.parseInt(matcher.group(2));
         }
 
-        rightStart = Integer.parseInt(matcher.group(3));
+        targetStart = Integer.parseInt(matcher.group(3));
         if (matcher.group(4).length() == 0)
         {
-            rightStart--;
-            rightLength = 1;
+            targetStart--;
+            targetLength = 1;
         }
         else if (matcher.group(4).charAt(0) == '0')
         {
-            rightLength = 0;
+            targetLength = 0;
         }
         else
         {
-            rightStart--;
-            rightLength = Integer.parseInt(matcher.group(4));
+            targetStart--;
+            targetLength = Integer.parseInt(matcher.group(4));
         }
 
         for (int lineCount = 1; lineCount < text.length; lineCount++)
@@ -238,7 +239,7 @@
     }
 
     //  Compute and return the source text (all equalities and deletions).
-    public String getLeftText()
+    public String getSourceText()
     {
         StringBuffer txt = new StringBuffer();
         Iterator iter = diffs.iterator();
@@ -254,7 +255,7 @@
     }
 
     // Compute and return the destination text (all equalities and insertions).
-    public String getRightText()
+    public String getTargetText()
     {
         StringBuffer txt = new StringBuffer();
         Iterator iter = diffs.iterator();
@@ -273,7 +274,7 @@
     {
         int maxPatternLength = new Match().maxPatternLength();
         int padding = 0;
-        String pattern = text.substring(rightStart, rightStart + leftLength);
+        String pattern = text.substring(targetStart, targetStart + sourceLength);
         int textLength = text.length();
 
         // Increase the context until we're unique
@@ -282,14 +283,14 @@
         while (text.indexOf(pattern) != text.lastIndexOf(pattern) && pattern.length() < end)
         {
             padding += PatchEntry.margin;
-            pattern = text.substring(Math.max(0, rightStart - padding), Math.min(textLength, rightStart + leftLength + padding));
+            pattern = text.substring(Math.max(0, targetStart - padding), Math.min(textLength, targetStart + sourceLength + padding));
         }
 
         // Add one chunk for good luck.
         padding += PatchEntry.margin;
 
         // Add the prefix.
-        String prefix = text.substring(Math.max(0, rightStart - padding), rightStart);
+        String prefix = text.substring(Math.max(0, targetStart - padding), targetStart);
         int prefixLength = prefix.length();
         if (prefixLength > 0)
         {
@@ -297,7 +298,7 @@
         }
 
         // Add the suffix
-        String suffix = text.substring(rightStart + leftLength, Math.min(textLength, rightStart + leftLength + padding));
+        String suffix = text.substring(targetStart + sourceLength, Math.min(textLength, targetStart + sourceLength + padding));
         int suffixLength = suffix.length();
         if (suffixLength > 0)
         {
@@ -305,12 +306,12 @@
         }
 
         // Roll back the start points.
-        leftStart -= prefixLength;
-        rightStart -= prefixLength;
+        sourceStart -= prefixLength;
+        targetStart -= prefixLength;
 
         // Extend the lengths.
-        leftLength += prefixLength + suffixLength;
-        rightLength += prefixLength + suffixLength;
+        sourceLength += prefixLength + suffixLength;
+        targetLength += prefixLength + suffixLength;
     }
 
     public void addDifference(Difference diff)
@@ -392,7 +393,7 @@
         }
         else if (length == 1)
         {
-            buf.append(leftStart + 1);
+            buf.append(sourceStart + 1);
         }
         else
         {
@@ -413,8 +414,8 @@
     private static Pattern patchPattern = Pattern.compile("^@@ -(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@$"); //$NON-NLS-1$
 
     private List diffs;
-    private int leftStart;
-    private int rightStart;
-    private int leftLength;
-    private int rightLength;
+    private int sourceStart;
+    private int targetStart;
+    private int sourceLength;
+    private int targetLength;
 }

Modified: trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/main/java/org/crosswire/common/util/StringUtil.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -527,11 +527,12 @@
      * be returned by <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt>
      * is <tt>null</tt>, in which case <tt>"null"</tt> is returned.
      *
+     * <p>This is borrowed from Java 1.5, but uses StringBuffer.
+     *
      * @param a the array whose string representation to return
      * @return a string representation of <tt>a</tt>
-     * @see #deepToString(Object[])
      * @since 1.5
-    */
+     */
     public static String toString(Object[] a)
     {
         if (a == null)
@@ -543,9 +544,9 @@
         {
             return "[]"; //$NON-NLS-1$
         }
- 
+
         StringBuffer buf = new StringBuffer();
- 
+
         for (int i = 0; i < a.length; i++)
         {
             if (i == 0)
@@ -556,10 +557,10 @@
             {
                 buf.append(", "); //$NON-NLS-1$
             }
- 
+
             buf.append(String.valueOf(a[i]));
         }
- 
+
         buf.append("]"); //$NON-NLS-1$
         return buf.toString();
     }

Modified: trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java	2007-06-20 00:02:33 UTC (rev 1417)
+++ trunk/common/src/test/java/org/crosswire/common/diff/PatchEntryTest.java	2007-06-20 12:00:38 UTC (rev 1418)
@@ -24,13 +24,13 @@
     {
         // Patch Object
         PatchEntry p = new PatchEntry();
-        p.setLeftStart(20);
-        p.setRightStart(21);
-        p.setLeftLength(18);
-        p.setRightLength(17);
+        p.setSourceStart(20);
+        p.setTargetStart(21);
+        p.setSourceLength(18);
+        p.setTargetLength(17);
         p.setDifferences(diffList(new Object[] { new Difference(EditType.EQUAL, "jump"), new Difference(EditType.DELETE, "s"), new Difference(EditType.INSERT, "ed"), new Difference(EditType.EQUAL, " over "), new Difference(EditType.DELETE, "the"), new Difference(EditType.INSERT, "a"), new Difference(EditType.EQUAL, " laz") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-        assertEquals("Patch: text1.", "jumps over the laz", p.getLeftText()); //$NON-NLS-1$ //$NON-NLS-2$
-        assertEquals("Patch: text2.", "jumped over a laz", p.getRightText()); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("Patch: text1.", "jumps over the laz", p.getSourceText()); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("Patch: text2.", "jumped over a laz", p.getTargetText()); //$NON-NLS-1$ //$NON-NLS-2$
         String strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n"; //$NON-NLS-1$
         assertEquals("Patch: toString.", strp, p.toString()); //$NON-NLS-1$
     }




More information about the jsword-svn mailing list