juanco 02/03/03 11:12:32
Modified: src/java/org/apache/maven/jrcs/diff Diff.java
src/java/org/apache/maven/jrcs/util ToString.java
src/test/org/apache/maven/jrcs/rcs ArchiveTest.java
Log:
moved utility methods from diff.Diff to util.ToString
Revision Changes Path
1.8 +12 -35
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Diff.java
Index: Diff.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Diff.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Diff.java 3 Mar 2002 18:38:41 -0000 1.7
+++ Diff.java 3 Mar 2002 19:12:32 -0000 1.8
@@ -54,8 +54,6 @@
* <http://www.apache.org/>.
*/
-import java.io.BufferedReader;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -66,9 +64,11 @@
import java.util.Random;
import java.util.Set;
+import org.apache.maven.jrcs.util.ToString;
+
/**
- * Produces the "delta" differences between two sequences.
+ * Implements a differencing engine that works on arrays of {@link Object Object}.
*
* <p>Within this library, the word <i>text</i> means a unit of information
* subject to version control.
@@ -81,12 +81,13 @@
* correctly can be subject to differencing using this
* library.</p>
*
- * @version $Revision: 1.7 $ $Date: 2002/03/03 18:38:41 $
- * @author Juancarlo A�ez
+ * @version $Revision: 1.8 $ $Date: 2002/03/03 19:12:32 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Juanco Anez</a>
* @see org.apache.maven.jrcs.diff.Delta
*/
public class Diff
+ extends ToString
{
public static final String NL = System.getProperty("line.separator");
@@ -250,42 +251,18 @@
return result;
}
- public static Object[] stringToArray(String value)
- {
- BufferedReader reader = new BufferedReader(new StringReader(value));
- List l = new LinkedList();
- String s;
- try
- {
- while ((s = reader.readLine()) != null)
- {
- l.add(s);
- }
- }
- catch (java.io.IOException e)
- {
- }
- return l.toArray();
- }
-
+ /**
+ * Converts an array of {@link Object Object} to a string
+ * using {@link Diff#NL Diff.NL}
+ * as the line separator.
+ * @param o the array of objects.
+ */
public static String arrayToString(Object[] o)
{
return arrayToString(o, Diff.NL);
}
-
- public static String arrayToString(Object[] o, String EOL)
- {
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < o.length - 1; i++)
- {
- buf.append(o[i]);
- buf.append(EOL);
- }
- buf.append(o[o.length - 1]);
- return buf.toString();
- }
public static Object[] randomEdit(Object[] text)
1.5 +77 -2
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/util/ToString.java
Index: ToString.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/util/ToString.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ToString.java 23 Feb 2002 13:36:02 -0000 1.4
+++ ToString.java 3 Mar 2002 19:12:32 -0000 1.5
@@ -55,15 +55,29 @@
*/
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.List;
+import java.util.LinkedList;
+
/**
* This class delegates handling of the to a StringBuffer based version.
+ *
+ * @version $Revision: 1.5 $ $Date: 2002/03/03 19:12:32 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Juanco Anez</a>
*/
-public abstract class ToString
+public class ToString
{
public ToString()
{
}
+ /**
+ * Default implementation of the
+ * {@link java.lang.Object#toString toString() } method that
+ * delegates work to a {@link java.lang.StringBuffer StringBuffer}
+ * base version.
+ */
public String toString()
{
StringBuffer s = new StringBuffer();
@@ -71,7 +85,68 @@
return s.toString();
}
- public abstract void toString(StringBuffer s);
+ /**
+ * Place a string image of the object in a StringBuffer.
+ * @param s the string buffer.
+ */
+ public void toString(StringBuffer s)
+ {
+ s.append(super.toString());
+ }
+
+
+
+ /**
+ * Breaks a string into an array of strings.
+ * Use the value of the <code>line.separator</code> system property
+ * as the linebreak character.
+ * @param value the string to convert.
+ */
+ public static String[] stringToArray(String value)
+ {
+ BufferedReader reader = new BufferedReader(new StringReader(value));
+ List l = new LinkedList();
+ String s;
+ try
+ {
+ while ((s = reader.readLine()) != null)
+ {
+ l.add(s);
+ }
+ }
+ catch (java.io.IOException e)
+ {
+ }
+ return (String[]) l.toArray(new String[l.size()]);
+ }
+ /**
+ * Converts an array of {@link Object Object} to a string
+ * Use the value of the <code>line.separator</code> system property
+ * the line separator.
+ * @param o the array of objects.
+ */
+ public static String arrayToString(Object[] o)
+ {
+ return arrayToString(o, System.getProperty("line.separator"));
+ }
+
+ /**
+ * Converts an array of {@link Object Object} to a string
+ * using the given line separator.
+ * @param o the array of objects.
+ * @param EOL the string to use as line separator.
+ */
+ public static String arrayToString(Object[] o, String EOL)
+ {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < o.length - 1; i++)
+ {
+ buf.append(o[i]);
+ buf.append(EOL);
+ }
+ buf.append(o[o.length - 1]);
+ return buf.toString();
+ }
}
1.8 +4 -3
jakarta-turbine-maven/src/test/org/apache/maven/jrcs/rcs/ArchiveTest.java
Index: ArchiveTest.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/test/org/apache/maven/jrcs/rcs/ArchiveTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ArchiveTest.java 27 Feb 2002 02:10:50 -0000 1.7
+++ ArchiveTest.java 3 Mar 2002 19:12:32 -0000 1.8
@@ -59,6 +59,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.maven.jrcs.util.ToString;
import org.apache.maven.jrcs.diff.Diff;
import org.apache.maven.jrcs.diff.DiffException;
@@ -232,7 +233,7 @@
archive.addRevision(v1_2, "Added 3.1, deleted 6\n");
Object[] rev = archive.getRevision();
assertEquals("1.2", archive.head.version.toString());
- assertEquals(Diff.arrayToString(v1_2), Diff.arrayToString(rev));
+ assertEquals(ToString.arrayToString(v1_2), ToString.arrayToString(rev));
assertNull(archive.addRevision(v1_2, "should not be added"));
assertEquals(new Version("1.2"), archive.getRevisionVersion());
@@ -252,7 +253,7 @@
assertEquals("1.2", archive.head.version.toString());
- assertEquals(Diff.arrayToString(v1_2_with_expanded_keywords),
Diff.arrayToString(rev));
+ assertEquals(ToString.arrayToString(v1_2_with_expanded_keywords),
ToString.arrayToString(rev));
assertNull(archive.addRevision(v1_2_with_expanded_keywords, "should not be
added"));
assertEquals(new Version("1.2"), archive.getRevisionVersion());
@@ -288,7 +289,7 @@
String filestr = archive.toString();
Object[] file = Diff.stringToArray(filestr);
String diff = Diff.diff(file, sampleFile).toRCSString(Diff.NL);
- String delta = Diff.arrayToString(deltaOverDates) + Diff.NL;
+ String delta = ToString.arrayToString(deltaOverDates) + Diff.NL;
assertEquals("delta over dates", delta, diff);
Object[] rev = archive.getRevision("1.2.1");
assertTrue("diffs equal", Diff.compare(v1_2_1_1, rev));
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>