jvanzyl 02/02/21 06:09:00
Modified: src/java/org/apache/maven/jrcs jdiff.java rcsp.java
src/java/org/apache/maven/jrcs/diff AddDelta.java
ChangeDelta.java Chunk.java DeleteDelta.java
Delta.java Diff.java DiffException.java
DifferentiationFailedException.java
PatchFailedException.java Range.java Revision.java
src/java/org/apache/maven/jrcs/util ToString.java
Removed: src/java/org/apache/maven/jrcs README
Log:
- applying patches submitted by Stephane Bailliez
Revision Changes Path
1.4 +62 -56 jakarta-turbine-maven/src/java/org/apache/maven/jrcs/jdiff.java
Index: jdiff.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/jdiff.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jdiff.java 20 Feb 2002 22:25:51 -0000 1.3
+++ jdiff.java 21 Feb 2002 14:08:59 -0000 1.4
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,64 +54,70 @@
* <http://www.apache.org/>.
*/
-import java.util.*;
-import java.io.*;
-import org.apache.maven.jrcs.diff.*;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Vector;
+
+import org.apache.maven.jrcs.diff.Diff;
+import org.apache.maven.jrcs.diff.Revision;
+
public class jdiff {
- static final String[] loadFile(String name) throws IOException
- {
- BufferedReader data = new BufferedReader(new FileReader(name));
- Vector v = new Vector();
- String s;
-
- while ((s = data.readLine()) != null)
- v.addElement(s);
-
- String[] result = new String[v.size()];
- v.copyInto(result);
- return result;
- }
-
- static final void ussage(String name) {
- System.err.println("Ussage: " + name + " file1 file2");
- }
-
- public static void main(String[] argv) throws Exception
- {
- if (argv.length < 2)
- ussage("jdiff");
- else {
- Object[] orig = loadFile(argv[0]);
- Object[] rev = loadFile(argv[1]);
-
- System.err.println("---go!----");
- Diff df = new Diff(orig);
- Revision r = df.diff(rev);
- System.err.println("---end!---");
-
- System.err.println("------");
- System.out.print(r.toString());
- System.err.println("------" + new Date());
-
- try {
- Object[] reco = r.patch(orig);
- String recos = Diff.arrayToString(reco);
- if (!Diff.compare(rev, reco)) {
- /*
- System.err.println("**********");
- System.err.print(Diff.arrayToString(rev));
- System.err.println("**********");
- System.err.print(recos);
- System.err.println("**********");
- */
- System.err.println("files differ");
+ static final String[] loadFile(String name) throws IOException {
+ BufferedReader data = new BufferedReader(new FileReader(name));
+ Vector v = new Vector();
+ String s;
+
+ while ((s = data.readLine()) != null) {
+ v.addElement(s);
+ }
+
+ String[] result = new String[v.size()];
+ v.copyInto(result);
+ return result;
+ }
+
+ static final void ussage(String name) {
+ System.err.println("Ussage: " + name + " file1 file2");
+ }
+
+ public static void main(String[] argv) throws Exception {
+ if (argv.length < 2) {
+ ussage("jdiff");
+ } else {
+ Object[] orig = loadFile(argv[0]);
+ Object[] rev = loadFile(argv[1]);
+
+ System.err.println("---go!----");
+ Diff df = new Diff(orig);
+ Revision r = df.diff(rev);
+ System.err.println("---end!---");
+
+ System.err.println("------");
+ System.out.print(r.toString());
+ System.err.println("------" + new Date());
+
+ try {
+ Object[] reco = r.patch(orig);
+ String recos = Diff.arrayToString(reco);
+ if (!Diff.compare(rev, reco)) {
+ /*
+ System.err.println("**********");
+ System.err.print(Diff.arrayToString(rev));
+ System.err.println("**********");
+ System.err.print(recos);
+ System.err.println("**********");
+ */
+ System.err.println("files differ");
+ }
+ } catch (Throwable o) {
+ System.out.println("Patch failed");
}
- }
- catch(Throwable o) {
- System.out.println("Patch failed");
- }
+ }
}
- }
}
+
1.5 +84 -86 jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcsp.java
Index: rcsp.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/rcsp.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- rcsp.java 20 Feb 2002 22:25:51 -0000 1.4
+++ rcsp.java 21 Feb 2002 14:08:59 -0000 1.5
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,52 +54,50 @@
* <http://www.apache.org/>.
*/
-import org.apache.maven.jrcs.rcs.*;
-import org.apache.maven.jrcs.diff.*;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
+import org.apache.maven.jrcs.diff.Diff;
+import org.apache.maven.jrcs.rcs.*;
public class rcsp {
- static Archive arc;
- static Object[] orig;
+ static Archive arc;
+ static Object[] orig;
- static public void main(String[] args) throws Exception {
+ static public void main(String[] args) throws Exception {
// try {
- if (args.length > 2)
- System.out.println("WRONG USSAGE: need at most one parameter");
- else {
- if (args.length >= 1)
- arc = new Archive(args[0]);
- else
- arc = new Archive("test,v",System.in);
- System.err.println();
- System.err.println("==========================================");
- //System.out.println(arc.toString());
- //System.out.println(arc.getRevision("5.2.7.1"));
- //System.out.println(arc.getRevision(args[1], true));
- //arc.addRevision(new Object[]{}, args[1]);
- orig = arc.getRevision("1.3");
- System.out.println("*-orig-*********");
- System.out.print(Diff.arrayToString(orig));
- System.out.println("**********");
- Object[] other = arc.getRevision("1.2");
- //!! commented out because of package access error (jvz).
- //System.out.println(Diff.diff(arc.removeKeywords(orig),
arc.removeKeywords(other)).toRCSString());
- trywith("1.2.3.1");
- trywith("1.2.3.5");
- trywith("1.2.3.1.");
- trywith("1.2");
- trywith("1.2.2");
- /*
- trywith("1.2.2.2");
- trywith("1.2.2.1.1");
- trywith("1.2.2");
- trywith("1.2.3");
- trywith("1.2.3");
- */
+ if (args.length > 2) {
+ System.out.println("WRONG USSAGE: need at most one parameter");
+ } else {
+ if (args.length >= 1) {
+ arc = new Archive(args[0]);
+ } else {
+ arc = new Archive("test,v", System.in);
+ }
+ System.err.println();
+ System.err.println("==========================================");
+ //System.out.println(arc.toString());
+ //System.out.println(arc.getRevision("5.2.7.1"));
+ //System.out.println(arc.getRevision(args[1], true));
+ //arc.addRevision(new Object[]{}, args[1]);
+ orig = arc.getRevision("1.3");
+ System.out.println("*-orig-*********");
+ System.out.print(Diff.arrayToString(orig));
+ System.out.println("**********");
+ Object[] other = arc.getRevision("1.2");
+ //!! commented out because of package access error (jvz).
+ //System.out.println(Diff.diff(arc.removeKeywords(orig),
arc.removeKeywords(other)).toRCSString());
+ trywith("1.2.3.1");
+ trywith("1.2.3.5");
+ trywith("1.2.3.1.");
+ trywith("1.2");
+ trywith("1.2.2");
+ /*
+ trywith("1.2.2.2");
+ trywith("1.2.2.1.1");
+ trywith("1.2.2");
+ trywith("1.2.3");
+ trywith("1.2.3");
+ */
}
/* }
catch(java.io.IOException e) {
@@ -108,50 +106,50 @@
e.printStackTrace();
}
*/
- }
+ }
- static int n = 1;
- static void trywith(String ver) {
- try {
- System.out.println();
- System.out.println("-------------");
- System.out.println("Adding "+ ver);
-
- /*
- List editor = new ArrayList(Arrays.asList(orig));
- editor.subList(0,1).clear();
- editor.add(0, "hola!");
- Object[] rev = editor.toArray();
- */
- Object[] rev = Diff.randomEdit(orig, n++);
- //rev = Diff.stringToArray(arc.doKeywords(Diff.arrayToString(rev), null));
- //System.out.print(Archive.arrayToString(rev));
-
- Version newVer = arc.addRevision(rev, ver);
- System.out.println( newVer + " added");
-
- if (newVer != null) {
- Object[] rec = arc.getRevision(newVer);
- //System.out.print(Archive.arrayToString(rec));
-
- /* !! commented out because of package access errors (jvz).
- if (!Diff.compare(arc.removeKeywords(rec), arc.removeKeywords(rev))) {
- System.out.println("revisions differ!");
- System.out.println("**********");
- System.out.println(Diff.arrayToString(rec));
- System.out.println("**********");
- System.out.println(Diff.arrayToString(rev));
- System.out.println("**********");
- System.out.print(Diff.diff(rec, rev).toRCSString());
- System.out.println("**********");
- }
- */
- }
-
- System.out.println(ver + " OK");
- } catch(Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- }
- }
+ static int n = 1;
+
+ static void trywith(String ver) {
+ try {
+ System.out.println();
+ System.out.println("-------------");
+ System.out.println("Adding " + ver);
+
+ /*
+ List editor = new ArrayList(Arrays.asList(orig));
+ editor.subList(0,1).clear();
+ editor.add(0, "hola!");
+ Object[] rev = editor.toArray();
+ */
+ Object[] rev = Diff.randomEdit(orig, n++);
+ //rev = Diff.stringToArray(arc.doKeywords(Diff.arrayToString(rev),
null));
+ //System.out.print(Archive.arrayToString(rev));
+
+ Version newVer = arc.addRevision(rev, ver);
+ System.out.println(newVer + " added");
+
+ if (newVer != null) {
+ Object[] rec = arc.getRevision(newVer);
+ //System.out.print(Archive.arrayToString(rec));
+
+ /* !! commented out because of package access errors (jvz).
+ if (!Diff.compare(arc.removeKeywords(rec),
arc.removeKeywords(rev))) {
+ System.out.println("revisions differ!");
+ System.out.println("**********");
+ System.out.println(Diff.arrayToString(rec));
+ System.out.println("**********");
+ System.out.println(Diff.arrayToString(rev));
+ System.out.println("**********");
+ System.out.print(Diff.diff(rec, rev).toRCSString());
+ System.out.println("**********");
+ }
+ */
+ }
+ System.out.println(ver + " OK");
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
}
1.3 +20 -15
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/AddDelta.java
Index: AddDelta.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/AddDelta.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AddDelta.java 20 Feb 2002 22:12:14 -0000 1.2
+++ AddDelta.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@
import java.util.List;
public class AddDelta extends Delta {
+
AddDelta() {
super();
}
@@ -66,8 +67,9 @@
}
public void verify(List target) throws PatchFailedException {
- if (original.first() > target.size())
+ if (original.first() > target.size()) {
throw new PatchFailedException("original.first() > target.size()");
+ }
}
public void applyTo(List target) {
@@ -75,21 +77,24 @@
}
public void toString(StringBuffer s) {
- s.append(original.anchor());
- s.append("a");
- s.append(revised.range());
- s.append(Diff.NL);
- revised.toString(s, "> ", Diff.NL);
+ s.append(original.anchor());
+ s.append("a");
+ s.append(revised.range());
+ s.append(Diff.NL);
+ revised.toString(s, "> ", Diff.NL);
}
- public void toRCSString(StringBuffer s, String EOL) {
- s.append("a");
- s.append(original.anchor());
- s.append(" ");
- s.append(revised.range().length());
- s.append(EOL);
- revised.toString(s, "", EOL);
- }
+ public void toRCSString(StringBuffer s, String EOL) {
+ s.append("a");
+ s.append(original.anchor());
+ s.append(" ");
+ s.append(revised.range().length());
+ s.append(EOL);
+ revised.toString(s, "", EOL);
+ }
}
+
+
+
1.3 +31 -27
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/ChangeDelta.java
Index: ChangeDelta.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/ChangeDelta.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChangeDelta.java 20 Feb 2002 22:12:14 -0000 1.2
+++ ChangeDelta.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@
import java.util.List;
public class ChangeDelta extends Delta {
+
ChangeDelta() {
super();
}
@@ -66,11 +67,13 @@
}
public void verify(List target) throws PatchFailedException {
- if (!original.verify(target))
+ if (!original.verify(target)) {
throw new PatchFailedException();
- if (original.first() > target.size())
+ }
+ if (original.first() > target.size()) {
throw new PatchFailedException("original.first() > target.size()");
- }
+ }
+ }
public void applyTo(List target) {
original.applyDelete(target);
@@ -78,27 +81,28 @@
}
public void toString(StringBuffer s) {
- original.range().toString(s);
- s.append("c");
- revised.range().toString(s);
- s.append(Diff.NL);
- original.toString(s, "< ", "\n");
- s.append("---");
- s.append(Diff.NL);
- revised.toString(s, "> ", "\n");
- }
-
- public void toRCSString(StringBuffer s, String EOL) {
- s.append("d");
- s.append(original.extfrom());
- s.append(" ");
- s.append(original.range().length());
- s.append(EOL);
- s.append("a");
- s.append(original.extfrom());
- s.append(" ");
- s.append(revised.range().length());
- s.append(EOL);
- revised.toString(s, "", EOL);
- }
+ original.range().toString(s);
+ s.append("c");
+ revised.range().toString(s);
+ s.append(Diff.NL);
+ original.toString(s, "< ", "\n");
+ s.append("---");
+ s.append(Diff.NL);
+ revised.toString(s, "> ", "\n");
+ }
+
+ public void toRCSString(StringBuffer s, String EOL) {
+ s.append("d");
+ s.append(original.extfrom());
+ s.append(" ");
+ s.append(original.range().length());
+ s.append(EOL);
+ s.append("a");
+ s.append(original.extfrom());
+ s.append(" ");
+ s.append(revised.range().length());
+ s.append(EOL);
+ revised.toString(s, "", EOL);
+ }
}
+
1.3 +94 -80
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Chunk.java
Index: Chunk.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Chunk.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Chunk.java 20 Feb 2002 22:12:14 -0000 1.2
+++ Chunk.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,127 +54,141 @@
* <http://www.apache.org/>.
*/
-import java.util.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
/**
* Produces the "Chunk" differences between two sequences
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Juancarlo A�ez
* @see org.apache.maven.jrcs.diff.Diff
*/
+
public class Chunk
-extends org.apache.maven.jrcs.util.ToString
-{
- protected int _anchor;
- protected int _count;
- protected List _chunk;
-
- public Chunk(int pos, int count) {
- this._anchor = pos;
- this._count = (count >= 0 ? count : 0);
- }
-
- public Chunk(Object[] iseq, int pos, int count) {
- this(pos, count);
- _chunk = slice(iseq, pos, count);
- }
-
- public Chunk(Object[] iseq, int pos, int count, int offset) {
- this(offset, count);
- _chunk = slice(iseq, pos, count);
- }
-
- public Chunk(List iseq, int pos, int count) {
- this(pos, count);
- _chunk = slice(iseq, pos, count);
- }
-
- public Chunk(List iseq, int pos, int count, int offset) {
- this(offset, count);
- _chunk = slice(iseq, pos, count);
- }
-
- public int anchor() {
- return _anchor;
- }
-
- public int size() {
- return _count;
- }
-
- public int first() {
- return anchor();
- }
-
- public int last() {
- return anchor() + size() - 1;
- }
-
- public int extfrom() {
- return _anchor + 1;
- }
+ extends org.apache.maven.jrcs.util.ToString {
+
+ protected int _anchor;
+
+ protected int _count;
+
+ protected List _chunk;
+
+ public Chunk(int pos, int count) {
+ this._anchor = pos;
+ this._count = (count >= 0 ? count : 0);
+ }
+
+ public Chunk(Object[] iseq, int pos, int count) {
+ this(pos, count);
+ _chunk = slice(iseq, pos, count);
+ }
+
+ public Chunk(Object[] iseq, int pos, int count, int offset) {
+ this(offset, count);
+ _chunk = slice(iseq, pos, count);
+ }
+
+ public Chunk(List iseq, int pos, int count) {
+ this(pos, count);
+ _chunk = slice(iseq, pos, count);
+ }
+
+ public Chunk(List iseq, int pos, int count, int offset) {
+ this(offset, count);
+ _chunk = slice(iseq, pos, count);
+ }
+
+ public int anchor() {
+ return _anchor;
+ }
+
+ public int size() {
+ return _count;
+ }
+
+ public int first() {
+ return anchor();
+ }
- public int extto() {
+ public int last() {
+ return anchor() + size() - 1;
+ }
+
+ public int extfrom() {
+ return _anchor + 1;
+ }
+
+ public int extto() {
return _anchor + _count;
- }
+ }
- public Range range() {
+ public Range range() {
return new Range(first(), last());
- }
+ }
- public List chunk() {
- return _chunk;
- }
+ public List chunk() {
+ return _chunk;
+ }
- public boolean verify(List target) {
- if (_chunk == null)
+ public boolean verify(List target) {
+ if (_chunk == null) {
return true;
- if (last() > target.size())
+ }
+ if (last() > target.size()) {
return false;
- for(int i = 0; i < _count; i++) {
- if (!target.get(_anchor+i).equals(_chunk.get(i)))
+ }
+ for (int i = 0; i < _count; i++) {
+ if (!target.get(_anchor + i).equals(_chunk.get(i))) {
return false;
+ }
}
return true;
- }
+ }
public void applyDelete(List target) {
- for(int i = last(); i >= first(); i--)
- target.remove(i);
+ for (int i = last(); i >= first(); i--) {
+ target.remove(i);
+ }
}
public void applyAdd(int start, List target) {
Iterator i = _chunk.iterator();
- while (i.hasNext())
+ while (i.hasNext()) {
target.add(start++, i.next());
+ }
}
public void toString(StringBuffer s) {
- toString(s, "", "");
+ toString(s, "", "");
}
+
public StringBuffer toString(StringBuffer s, String prefix, String postfix) {
if (_chunk != null) {
Iterator i = _chunk.iterator();
- while(i.hasNext()) {
+ while (i.hasNext()) {
s.append(prefix);
s.append(i.next());
s.append(postfix);
}
}
return s;
- }
+ }
- public static List slice(List seq, int pos, int count) {
- if (count <= 0)
- return new ArrayList(seq.subList(pos,pos));
- else
- return new ArrayList(seq.subList(pos, pos+count));
- }
+ public static List slice(List seq, int pos, int count) {
+ if (count <= 0) {
+ return new ArrayList(seq.subList(pos, pos));
+ } else {
+ return new ArrayList(seq.subList(pos, pos + count));
+ }
+ }
- public static List slice(Object[] seq, int pos, int count) {
+ public static List slice(Object[] seq, int pos, int count) {
return slice(Arrays.asList(seq), pos, count);
- }
-
+ }
}
+
1.3 +19 -14
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DeleteDelta.java
Index: DeleteDelta.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DeleteDelta.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DeleteDelta.java 20 Feb 2002 22:12:14 -0000 1.2
+++ DeleteDelta.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,10 @@
* <http://www.apache.org/>.
*/
+
import java.util.List;
+
public class DeleteDelta extends Delta {
DeleteDelta() {
@@ -67,8 +69,9 @@
}
public void verify(List target) throws PatchFailedException {
- if (!original.verify(target))
+ if (!original.verify(target)) {
throw new PatchFailedException();
+ }
}
public void applyTo(List target) {
@@ -76,19 +79,21 @@
}
public void toString(StringBuffer s) {
- s.append(original.range());
- s.append("d");
- s.append(revised.extto());
- s.append(Diff.NL);
- original.toString(s, "< ", Diff.NL);
+ s.append(original.range());
+ s.append("d");
+ s.append(revised.extto());
+ s.append(Diff.NL);
+ original.toString(s, "< ", Diff.NL);
}
- public void toRCSString(StringBuffer s, String EOL) {
- s.append("d");
- s.append(original.extfrom());
- s.append(" ");
- s.append(original.range().length());
- s.append(EOL);
- }
+ public void toRCSString(StringBuffer s, String EOL) {
+ s.append("d");
+ s.append(original.extfrom());
+ s.append(" ");
+ s.append(original.range().length());
+ s.append(EOL);
+ }
}
+
+
1.3 +81 -72
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Delta.java
Index: Delta.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Delta.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Delta.java 20 Feb 2002 22:12:14 -0000 1.2
+++ Delta.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-import java.util.*;
+import java.util.List;
/**
* Produces the "delta" differences between two sequences
@@ -63,84 +63,93 @@
* @author Juancarlo A�ez
* @see org.apache.maven.jrcs.diff.Diff
*/
+
public abstract class Delta
-extends org.apache.maven.jrcs.util.ToString
-{
- protected Chunk original;
- protected Chunk revised;
-
- static Class[][] DeltaClass;
-
- static {
- DeltaClass = new Class[2][2];
- try {
- DeltaClass[0][0] = org.apache.maven.jrcs.diff.ChangeDelta.class;
- DeltaClass[0][1] = org.apache.maven.jrcs.diff.AddDelta.class;
- DeltaClass[1][0] = org.apache.maven.jrcs.diff.DeleteDelta.class;
- DeltaClass[1][1] = org.apache.maven.jrcs.diff.ChangeDelta.class;
- }
- catch(Throwable o) {
- }
- }
-
- public static Delta newDelta(Chunk orig, Chunk rev) {
- Class c = DeltaClass[ orig.size() > 0 ? 1 : 0]
- [ rev.size() > 0 ? 1 : 0];
- Delta result;
- try {
- result = (Delta) c.newInstance();
- } catch(Throwable e) {
- System.err.println(e);
- return null;
- }
- result.init(orig, rev);
- return result;
- }
-
-
- protected Delta() {
- }
-
- protected Delta(Chunk orig, Chunk rev) {
- init(orig, rev);
- }
-
- protected void init(Chunk orig, Chunk rev) {
- original = orig;
- revised = rev;
- }
+ extends org.apache.maven.jrcs.util.ToString {
- public abstract void verify(List target) throws PatchFailedException;
+ protected Chunk original;
- public final void patch(List target) throws PatchFailedException {
- verify(target);
+ protected Chunk revised;
+
+
+ static Class[][] DeltaClass;
+
+
+ static {
+ DeltaClass = new Class[2][2];
try {
- applyTo(target);
+ DeltaClass[0][0] = org.apache.maven.jrcs.diff.ChangeDelta.class;
+ DeltaClass[0][1] = org.apache.maven.jrcs.diff.AddDelta.class;
+ DeltaClass[1][0] = org.apache.maven.jrcs.diff.DeleteDelta.class;
+ DeltaClass[1][1] = org.apache.maven.jrcs.diff.ChangeDelta.class;
+ } catch (Throwable o) {
+
+ }
+ }
+
+
+ public static Delta newDelta(Chunk orig, Chunk rev) {
+ Class c = DeltaClass[orig.size() > 0 ? 1 : 0]
+ [rev.size() > 0 ? 1 : 0];
+ Delta result;
+ try {
+ result = (Delta) c.newInstance();
+ } catch (Throwable e) {
+ System.err.println(e);
+ return null;
}
- catch(Exception e) {
+ result.init(orig, rev);
+ return result;
+ }
+
+
+ protected Delta() {
+ }
+
+
+ protected Delta(Chunk orig, Chunk rev) {
+ init(orig, rev);
+ }
+
+
+ protected void init(Chunk orig, Chunk rev) {
+ original = orig;
+ revised = rev;
+ }
+
+
+ public abstract void verify(List target) throws PatchFailedException;
+
+ public final void patch(List target) throws PatchFailedException {
+ verify(target);
+ try {
+ applyTo(target);
+ } catch (Exception e) {
throw new PatchFailedException(e.getMessage());
}
- }
+ }
- public abstract void applyTo(List target);
+ public abstract void applyTo(List target);
- public void toString(StringBuffer s) {
- original.range().toString(s);
- s.append("x");
- revised.range().toString(s);
- s.append(Diff.NL);
- original.toString(s, "> ", "\n");
- s.append("---");
- s.append(Diff.NL);
- revised.toString(s, "< ", "\n");
- }
-
- public abstract void toRCSString(StringBuffer s, String EOL);
-
- public String toRCSString(String EOL) {
- StringBuffer s = new StringBuffer();
- toRCSString(s, EOL);
- return s.toString();
- }
+ public void toString(StringBuffer s) {
+ original.range().toString(s);
+ s.append("x");
+ revised.range().toString(s);
+ s.append(Diff.NL);
+ original.toString(s, "> ", "\n");
+ s.append("---");
+ s.append(Diff.NL);
+ revised.toString(s, "< ", "\n");
+ }
+
+ public abstract void toRCSString(StringBuffer s, String EOL);
+
+ public String toRCSString(String EOL) {
+ StringBuffer s = new StringBuffer();
+ toRCSString(s, EOL);
+ return s.toString();
+ }
}
+
+
1.3 +141 -118
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Diff.java 20 Feb 2002 22:12:14 -0000 1.2
+++ Diff.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,142 +54,155 @@
* <http://www.apache.org/>.
*/
-import java.util.List;
-import java.util.Arrays;
+import java.io.BufferedReader;
+import java.io.StringReader;
import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.Set;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
-import java.util.HashMap;
-
-import java.io.BufferedReader;
-import java.io.StringReader;
-
import java.util.Random;
+import java.util.Set;
+
/**
* Produces the "delta" differences between two sequences
*
- * @version $Revision: 1.2 $ $Date: 2002/02/20 22:12:14 $
+ * @version $Revision: 1.3 $ $Date: 2002/02/21 14:08:59 $
* @author Juancarlo A�ez
* @see org.apache.maven.jrcs.diff.Delta
*/
-public class Diff {
- public static final String NL = "\n";
- static final int NOT_FOUND_i = -2;
- static final int NOT_FOUND_j = -1;
- static final int EOS = Integer.MAX_VALUE;
+public class Diff {
- Object[] orig;
+ public static final String NL = "\n";
+ static final int NOT_FOUND_i = -2;
+
+ static final int NOT_FOUND_j = -1;
+
+ static final int EOS = Integer.MAX_VALUE;
+
+ Object[] orig;
+
public Diff(Object[] o) {
- if (o == null)
- throw new IllegalArgumentException();
- orig = o;
+ if (o == null) {
+ throw new IllegalArgumentException();
+ }
+ orig = o;
}
public static Revision diff(Object[] orig, Object[] rev)
- throws DifferentiationFailedException
- {
- if (orig == null || rev == null)
- throw new IllegalArgumentException();
+ throws DifferentiationFailedException {
+ if (orig == null || rev == null) {
+ throw new IllegalArgumentException();
+ }
return new Diff(orig).diff(rev);
}
public static boolean compare(Object[] orig, Object[] rev) {
- if (orig.length != rev.length)
- return false;
- else {
- for(int i = 0; i < orig.length; i++)
- if (! orig[i].equals(rev[i]))
- return false;
- return true;
- }
- }
+ if (orig.length != rev.length) {
+ return false;
+ } else {
+ for (int i = 0; i < orig.length; i++) {
+ if (!orig[i].equals(rev[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
protected int scan(int[] ndx, int i, int target) {
- while(ndx[i] < target)
- i++;
- return i;
+ while (ndx[i] < target) {
+ i++;
+ }
+ return i;
}
public Revision diff(Object[] rev) throws DifferentiationFailedException {
- Map eqs = buildEqSet(orig, rev);
- int[] indx = buildIndex(eqs, orig, NOT_FOUND_i);
- int[] jndx = buildIndex(eqs, rev, NOT_FOUND_j);
- eqs = null; // let gc know we're done with this
-
- Revision deltas = new Revision(); //!!! new Revision()
- int i = 0;
- int j = 0;
-
- // skip matching
- for(;indx[i] != EOS && indx[i] == jndx[j]; i++, j++)
- {/* void */}
-
- while (indx[i] != jndx[j]) { // only equal if both == EOS
- // they are different
- int ia = i;
- int ja = j;
-
- // size of this delta
- do {
- while(jndx[j] < 0 || jndx[j] < indx[i]) j++;
- while(indx[i] < 0 || indx[i] < jndx[j]) i++;
- } while(indx[i] != jndx[j]);
-
- // they are equal, reverse any exedent matches
- while(i > ia && j > ja && indx[i-1] == jndx[j-1]) {
- --i; --j;
- //System.err.println("************* reversing "+ i);
- }
-
- deltas.addDelta( Delta.newDelta( new Chunk(orig, ia, i-ia),
- new Chunk(rev, ja, j-ja)));
- // skip matching
- for(;indx[i] != EOS && indx[i] == jndx[j]; i++, j++)
- {/* void */}
- }
- try {
- if (!compare(deltas.patch(orig), rev))
- throw new DifferentiationFailedException();
- }
- catch(DiffException e) {
+ Map eqs = buildEqSet(orig, rev);
+ int[] indx = buildIndex(eqs, orig, NOT_FOUND_i);
+ int[] jndx = buildIndex(eqs, rev, NOT_FOUND_j);
+ eqs = null; // let gc know we're done with this
+
+ Revision deltas = new Revision(); //!!! new Revision()
+ int i = 0;
+ int j = 0;
+
+ // skip matching
+ for (; indx[i] != EOS && indx[i] == jndx[j]; i++, j++) {/* void */
+ }
+
+ while (indx[i] != jndx[j]) { // only equal if both == EOS
+ // they are different
+ int ia = i;
+ int ja = j;
+
+ // size of this delta
+ do {
+ while (jndx[j] < 0 || jndx[j] < indx[i]) {
+ j++;
+ }
+ while (indx[i] < 0 || indx[i] < jndx[j]) {
+ i++;
+ }
+ } while (indx[i] != jndx[j]);
+
+ // they are equal, reverse any exedent matches
+ while (i > ia && j > ja && indx[i - 1] == jndx[j - 1]) {
+ --i;
+ --j;
+ //System.err.println("************* reversing "+ i);
+ }
+
+ deltas.addDelta(Delta.newDelta(new Chunk(orig, ia, i - ia),
+ new Chunk(rev, ja, j - ja)));
+ // skip matching
+ for (; indx[i] != EOS && indx[i] == jndx[j]; i++, j++) {/* void */
+ }
+ }
+ try {
+ if (!compare(deltas.patch(orig), rev)) {
+ throw new DifferentiationFailedException();
+ }
+ } catch (DiffException e) {
throw new DifferentiationFailedException(e.getMessage());
- }
- return deltas;
+ }
+ return deltas;
}
+
protected Map buildEqSet(Object[] orig, Object[] rev) {
- Set items = new HashSet(Arrays.asList(orig));
- items.retainAll(Arrays.asList(rev));
+ Set items = new HashSet(Arrays.asList(orig));
+ items.retainAll(Arrays.asList(rev));
- Map eqs = new HashMap();
- for(int i = 0; i < orig.length; i++) {
- if (items.contains(orig[i])) {
- eqs.put(orig[i], new Integer(i));
- items.remove(orig[i]);
+ Map eqs = new HashMap();
+ for (int i = 0; i < orig.length; i++) {
+ if (items.contains(orig[i])) {
+ eqs.put(orig[i], new Integer(i));
+ items.remove(orig[i]);
+ }
}
- }
- return eqs;
+ return eqs;
}
protected int[] buildIndex(Map eqs, Object[] seq, int NF) {
- int[] result = new int[seq.length+1];
-
- for(int i = 0; i < seq.length; i++) {
- Integer value = (Integer) eqs.get(seq[i]);
- if (value == null || value.intValue() < 0)
- result[i] = NF;
- else
- result[i] = value.intValue();
- }
- result[seq.length] = EOS;
- return result;
+ int[] result = new int[seq.length + 1];
+ for (int i = 0; i < seq.length; i++) {
+ Integer value = (Integer) eqs.get(seq[i]);
+ if (value == null || value.intValue() < 0) {
+ result[i] = NF;
+ } else {
+ result[i] = value.intValue();
+ }
+ }
+ result[seq.length] = EOS;
+ return result;
}
public static Object[] stringToArray(String value) {
@@ -197,54 +210,62 @@
List l = new LinkedList();
String s;
try {
- while ((s = reader.readLine()) != null)
- l.add(s);
+ while ((s = reader.readLine()) != null) {
+ l.add(s);
+ }
+ } catch (java.io.IOException e) {
}
- catch(java.io.IOException e)
- {}
return l.toArray();
}
+
public static String arrayToString(Object[] o) {
- return arrayToString(o, Diff.NL);
+ 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);
+ for (int i = 0; i < o.length - 1; i++) {
+ buf.append(o[i]);
+ buf.append(EOL);
}
- buf.append(o[o.length-1]);
+ buf.append(o[o.length - 1]);
return buf.toString();
}
- public static Object[] randomEdit(Object [] text) {
+
+ public static Object[] randomEdit(Object[] text) {
return randomEdit(text, text.length);
}
- public static Object[] randomEdit(Object [] text, long seed) {
+
+ public static Object[] randomEdit(Object[] text, long seed) {
List result = new ArrayList(Arrays.asList(text));
Random r = new Random(seed);
int nops = r.nextInt(10);
for (int i = 0; i < nops; i++) {
- boolean del = r.nextBoolean();
- int pos = r.nextInt(result.size()+1);
- int len = Math.min(result.size() - pos, 1+r.nextInt(4));
- if (del && result.size() > 0) // delete
+ boolean del = r.nextBoolean();
+ int pos = r.nextInt(result.size() + 1);
+ int len = Math.min(result.size() - pos, 1 + r.nextInt(4));
+ if (del && result.size() > 0) { // delete
result.subList(pos, pos + len).clear();
- else
- for (int k = 0; k < len; k++, pos++)
- result.add(pos, "["+i+"] random edit[" + i + "][" + i + "]");
+ } else {
+ for (int k = 0; k < len; k++, pos++) {
+ result.add(pos, "[" + i + "] random edit[" + i + "][" + i +
"]");
+ }
+ }
}
return result.toArray();
}
- public static Object[] shuffle(Object [] text) {
+
+ public static Object[] shuffle(Object[] text) {
return randomEdit(text, text.length);
}
- public static Object[] shuffle(Object [] text, long seed) {
+
+ public static Object[] shuffle(Object[] text, long seed) {
List result = new ArrayList(Arrays.asList(text));
Random r = new Random(seed);
int nops = r.nextInt(10);
@@ -258,4 +279,6 @@
return result.toArray();
}
}
+
+
1.3 +2 -1
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DiffException.java
Index: DiffException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DiffException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DiffException.java 20 Feb 2002 22:12:14 -0000 1.2
+++ DiffException.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,3 +63,4 @@
super(msg);
}
}
+
1.3 +3 -1
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DifferentiationFailedException.java
Index: DifferentiationFailedException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/DifferentiationFailedException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DifferentiationFailedException.java 20 Feb 2002 22:12:14 -0000 1.2
+++ DifferentiationFailedException.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -55,6 +55,7 @@
*/
public class DifferentiationFailedException extends DiffException {
+
public DifferentiationFailedException() {
}
@@ -62,3 +63,4 @@
super(msg);
}
}
+
1.3 +5 -3
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/PatchFailedException.java
Index: PatchFailedException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/PatchFailedException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PatchFailedException.java 20 Feb 2002 22:12:14 -0000 1.2
+++ PatchFailedException.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,8 @@
* <http://www.apache.org/>.
*/
-public class PatchFailedException extends DiffException
-{
+public class PatchFailedException extends DiffException {
+
public PatchFailedException() {
}
@@ -63,4 +63,6 @@
super(msg);
}
}
+
+
1.3 +37 -36
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Range.java
Index: Range.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Range.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Range.java 20 Feb 2002 22:12:14 -0000 1.2
+++ Range.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,6 +54,8 @@
* <http://www.apache.org/>.
*/
+import org.apache.maven.jrcs.util.ToString;
+
/**
* Produces the "Range" differences between two sequences
*
@@ -62,39 +64,38 @@
* @see org.apache.maven.jrcs.diff.Diff
*/
public class Range
-extends org.apache.maven.jrcs.util.ToString
-{
- int _from;
- int _to;
-
- public Range(int from, int to) {
- _from = from;
- _to = to;
- }
-
- public int from() {
- return _from;
- }
-
- public int to() {
- return _to;
- }
-
- public int length() {
- return 1+_to-_from;
- }
-
- public void toString(StringBuffer s, String separ) {
- if (_from == _to)
- s.append(Integer.toString(1+_from));
- else {
- s.append(Integer.toString(1+_from));
- s.append(separ);
- s.append(Integer.toString(1+_to));
- }
- }
-
- public void toString(StringBuffer s) {
- toString(s, ",");
- }
+ extends ToString {
+ int _from;
+ int _to;
+
+ public Range(int from, int to) {
+ _from = from;
+ _to = to;
+ }
+
+ public int from() {
+ return _from;
+ }
+
+ public int to() {
+ return _to;
+ }
+
+ public int length() {
+ return 1 + _to - _from;
+ }
+
+ public void toString(StringBuffer s, String separ) {
+ if (_from == _to) {
+ s.append(Integer.toString(1 + _from));
+ } else {
+ s.append(Integer.toString(1 + _from));
+ s.append(separ);
+ s.append(Integer.toString(1 + _to));
+ }
+ }
+
+ public void toString(StringBuffer s) {
+ toString(s, ",");
+ }
}
1.3 +88 -76
jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Revision.java
Index: Revision.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jrcs/diff/Revision.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Revision.java 20 Feb 2002 22:12:14 -0000 1.2
+++ Revision.java 21 Feb 2002 14:08:59 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,81 +54,93 @@
* <http://www.apache.org/>.
*/
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.maven.jrcs.util.ToString;
+
public class Revision
-extends org.apache.maven.jrcs.util.ToString
-{
- List deltas_ = new LinkedList();
-
- public Revision() {
- }
-
- public synchronized void addDelta(Delta delta) {
- if (delta == null)
- throw new IllegalArgumentException("new delta is null");
- if (deltas_.size() > 0) {
- Delta prev = (Delta) deltas_.get(deltas_.size()-1);
-
- /*!!!
- if (prev.original != null && delta.original != null
- && (prev.original.from() > delta.original.from()))
- throw new IllegalArgumentException("original.from > new.from");
-
- if (prev.revised != null && delta.revised != null
- && (prev.revised.from() > delta.revised.from()))
- throw new IllegalArgumentException("revised.from > revised.to");
- */
- }
- deltas_.add(delta);
- }
-
- public Delta getDelta(int i) {
- return (Delta) deltas_.get(i);
- }
-
- public int size() {
- return deltas_.size();
- }
-
- public Object[] patch(Object[] src) throws PatchFailedException {
- List target = new ArrayList(Arrays.asList(src));
- applyTo(target);
- return target.toArray();
- }
-
- public synchronized void applyTo(List target) throws PatchFailedException {
- ListIterator i = deltas_.listIterator(deltas_.size());
- while (i.hasPrevious()) {
- Delta delta = (Delta) i.previous();
- delta.patch(target);
- }
- }
-
- public synchronized void toString(StringBuffer s){
- Iterator i = deltas_.iterator();
- while (i.hasNext())
- ((Delta)i.next()).toString(s);
- }
-
- public synchronized void toRCSString(StringBuffer s, String EOL){
- Iterator i = deltas_.iterator();
- while (i.hasNext())
- ((Delta) i.next()).toRCSString(s, EOL);
- }
-
- public void toRCSString(StringBuffer s){
- toRCSString(s, Diff.NL);
- }
-
- public String toRCSString(String EOL) {
- StringBuffer s = new StringBuffer();
- toRCSString(s, EOL);
- return s.toString();
- }
-
- public String toRCSString() {
- return toRCSString(Diff.NL);
- }
-}
+ extends ToString {
+
+ List deltas_ = new LinkedList();
+
+ public Revision() {
+ }
+
+
+ public synchronized void addDelta(Delta delta) {
+ if (delta == null) {
+ throw new IllegalArgumentException("new delta is null");
+ }
+ if (deltas_.size() > 0) {
+ Delta prev = (Delta) deltas_.get(deltas_.size() - 1);
+
+ /*!!!
+ if (prev.original != null && delta.original != null
+ && (prev.original.from() > delta.original.from()))
+ throw new IllegalArgumentException("original.from > new.from");
+
+ if (prev.revised != null && delta.revised != null
+ && (prev.revised.from() > delta.revised.from()))
+ throw new IllegalArgumentException("revised.from > revised.to");
+ */
+ }
+ deltas_.add(delta);
+ }
+
+ public Delta getDelta(int i) {
+ return (Delta) deltas_.get(i);
+ }
+
+ public int size() {
+ return deltas_.size();
+ }
+
+ public Object[] patch(Object[] src) throws PatchFailedException {
+ List target = new ArrayList(Arrays.asList(src));
+ applyTo(target);
+ return target.toArray();
+ }
+
+ public synchronized void applyTo(List target) throws PatchFailedException {
+ ListIterator i = deltas_.listIterator(deltas_.size());
+ while (i.hasPrevious()) {
+ Delta delta = (Delta) i.previous();
+ delta.patch(target);
+ }
+ }
+
+ public synchronized void toString(StringBuffer s) {
+ Iterator i = deltas_.iterator();
+ while (i.hasNext()) {
+ ((Delta) i.next()).toString(s);
+ }
+ }
+
+ public synchronized void toRCSString(StringBuffer s, String EOL) {
+ Iterator i = deltas_.iterator();
+ while (i.hasNext()) {
+ ((Delta) i.next()).toRCSString(s, EOL);
+ }
+ }
+ public void toRCSString(StringBuffer s) {
+ toRCSString(s, Diff.NL);
+ }
+
+ public String toRCSString(String EOL) {
+ StringBuffer s = new StringBuffer();
+ toRCSString(s, EOL);
+ return s.toString();
+ }
+
+ public String toRCSString() {
+ return toRCSString(Diff.NL);
+ }
+
+}
1.3 +23 -9
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ToString.java 20 Feb 2002 22:12:14 -0000 1.2
+++ ToString.java 21 Feb 2002 14:09:00 -0000 1.3
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,19 +54,33 @@
* <http://www.apache.org/>.
*/
+
/**
+
* This class delegates handling of the to a StringBuffer based version.
+
*/
+
public abstract class ToString {
- public ToString() {
- }
- public String toString() {
- StringBuffer s = new StringBuffer();
- toString(s);
- return s.toString();
- }
+ public ToString() {
+
+ }
+
+
+ public String toString() {
+
+ StringBuffer s = new StringBuffer();
+
+ toString(s);
+
+ return s.toString();
+
+ }
+
+
+ public abstract void toString(StringBuffer s);
- public abstract void toString(StringBuffer s);
}
+
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>