001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: SJDiff.java$
021: * $FileID: 4526$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 4/25/03 1:27 AM$
026: * $Comment: Implement JLibDiff.diff.$
027: */
028:
029: package JLibDiff;
030:
031: import java.util.*;
032: import java.io.*;
033: import org.sourcejammer.server.source.TextLineReader;
034: import org.sourcejammer.util.ConfigurationException;
035: import org.sourcejammer.server.make.EndOfSourceException;
036: import org.sourcejammer.server.source.TextLineIterator;
037:
038: /**
039: * Title: $FileName: SJDiff.java$
040: * @version $VerNum: 4$
041: * @author $AuthorName: Rob MacGrogan$<br><br>
042: *
043: * $Description: $<br>
044: * $KeyWordsOff: $<br/><br/>
045: *
046: * A modified implimentation of JLibDiff.diff. This version copies
047: * most of the code from JLibDiff.diff, but changes addes a method
048: * to allow a diff to be build from TextLineReader objects.
049: */
050: public class SJDiff extends diff {
051:
052: /**
053: * Constructor for SJDiff.
054: */
055: public SJDiff() {
056: super ();
057: }
058:
059: /**
060: * Constructor for SJDiff.
061: * @param d
062: */
063: public SJDiff(diff d) {
064: super (d);
065: }
066:
067: /**
068: * Constructor for SJDiff.
069: * @param v
070: */
071: public SJDiff(Vector v) {
072: super (v);
073: }
074:
075: /**
076: * Constructor for SJDiff.
077: * @param s1
078: * @param s2
079: * @throws IOException
080: */
081: public SJDiff(String s1, String s2) throws IOException {
082: super (s1, s2);
083: }
084:
085: /**
086: * Builds this diff from the two TextLineReader objects.
087: */
088: public void diffTextLineReader(TextLineReader current,
089: TextLineReader newFile) throws IOException,
090: EndOfSourceException {
091:
092: diffTextLineIterator(current, newFile);
093: }
094:
095: /**
096: * Builds this diff from the two TextLineIterator objects.
097: */
098: public void diffTextLineIterator(TextLineIterator current,
099: TextLineIterator newFile) throws IOException,
100: EndOfSourceException {
101:
102: String s;
103:
104: ArrayList al = new ArrayList();
105: while (current.hasMoreLines()) {
106: s = current.getNextLine();
107: al.add(s);
108: }
109: String[] A = new String[al.size()];
110: al.toArray(A);
111:
112: al = new ArrayList();
113: while (newFile.hasMoreLines()) {
114: s = newFile.getNextLine();
115: al.add(s);
116: }
117: String[] B = new String[al.size()];
118: al.toArray(B);
119:
120: makeDiff(A, B);
121:
122: }
123:
124: }
|