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: HunkChange.java$
021: * $FileID: 4294$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 4/23/03 5:23 PM$
026: * $Comment: Replaced GPL header with LGPL header.$
027: *
028: * $KeyWordsOff: $
029: */
030:
031: package JLibDiff;
032:
033: import java.util.*;
034:
035: /**
036: * The <code>HunkChange</code> class represents a bloc of difference reliding
037: * change.
038: */
039: public class HunkChange extends Hunk implements java.io.Serializable {
040:
041: int ld1;
042: int lf1;
043: int ld2;
044: int lf2;
045:
046: Vector a = new Vector();
047: Vector b = new Vector();
048:
049: public void accept(HunkVisitor visitor) {
050: visitor.visitHunkChange(this );
051: }
052:
053: /**
054: * Returns update string.
055: */
056: public String getNewContents() {
057: String s = new String();
058: for (Enumeration e = b.elements(); e.hasMoreElements();)
059: s = s.concat((String) e.nextElement());
060: return s;
061: }
062:
063: /**
064: * Returns a string representation of the current hunk
065: * with normal format .
066: */
067: public String convert() {
068: String s = new String(Integer.toString(ld1));
069: if (ld1 != lf1)
070: s = s.concat("," + lf1);
071: s = s.concat("c" + ld2);
072: if (ld2 != lf2)
073: s = s.concat("," + lf2);
074: s = s.concat("\n");
075: for (Enumeration e = a.elements(); e.hasMoreElements();)
076: s = s.concat("< " + (String) e.nextElement());
077: s = s.concat("---\n");
078: for (Enumeration e = b.elements(); e.hasMoreElements();)
079: s = s.concat("> " + (String) e.nextElement());
080: return s;
081: }
082:
083: /**
084: * Returns a string representation of the current hunk
085: * with ED_script format .
086: */
087: public String convert_ED() {
088: String s = new String(Integer.toString(ld1));
089: if (ld1 != lf1)
090: s = s.concat("," + lf1);
091: s = s.concat("c\n");
092: for (Enumeration e = b.elements(); e.hasMoreElements();)
093: s = s.concat((String) e.nextElement());
094: s = s.concat(".\n");
095: return s;
096: }
097:
098: /**
099: * Returns a string representation of the current hunk
100: * with RCS_script format .
101: */
102: public String convert_RCS() {
103: String s = new String("d" + ld1 + " " + (lf1 - ld1 + 1) + "\n");
104: s = s.concat("a" + lf1 + " " + (lf2 - ld2 + 1) + "\n");
105: for (Enumeration e = b.elements(); e.hasMoreElements();)
106: s = s.concat((String) e.nextElement());
107: return s;
108: }
109:
110: /**
111: * Returns the number of low line of file passed in argument .
112: * Lines are inclusif.
113: *
114: * @param filenum The number of file (the first file '0', or the second '1').
115: */
116: public int lowLine(int filenum) {
117: if (filenum == 0)
118: return ld1;
119: else
120: return ld2;
121: }
122:
123: /**
124: * Returns the number of high line of file passed in argument .
125: * Lines are inclusif.
126: *
127: * @param filenum The number of file (the first file '0', or the second '1').
128: */
129: public int highLine(int filenum) {
130: if (filenum == 0)
131: return lf1;
132: else
133: return lf2;
134: }
135:
136: /**
137: * Returns the number of lines consedered in this hunk and which
138: * came from file passed in argument .
139: *
140: * @param filenum The number of file (the first file '0', or the second '1').
141: */
142: public int numLines(int filenum) {
143: if (filenum == 0)
144: return (lf1 - ld1 + 1);
145: else
146: return (lf2 - ld2 + 1);
147: }
148:
149: /**
150: * Returns a string representing the line in file and position passed
151: * in argument.
152: *
153: * @param filenum The number of file (the first file '0', or the second '1').
154: * @param linenum the number of line that will be returned.
155: */
156: public String relNum(int filenum, int linenum) {
157: if (filenum == 0)
158: return (String) a.elementAt(linenum);
159: else
160: return (String) b.elementAt(linenum);
161: }
162:
163: }
|