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: HunkAdd.java$
021: * $FileID: 4284$
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>HunkAdd</code> class represents a bloc of difference reliding
037: * addition(insertion).
038: */
039: public class HunkAdd extends Hunk implements java.io.Serializable {
040:
041: int ld1;
042: int ld2;
043: int lf2;
044:
045: Vector b = new Vector();
046:
047: public void accept(HunkVisitor visitor) {
048: visitor.visitHunkAdd(this );
049: }
050:
051: /**
052: * Returns string to append.
053: */
054: public String getNewContents() {
055: String s = new String();
056: for (Enumeration e = b.elements(); e.hasMoreElements();)
057: s = s.concat((String) e.nextElement());
058: return s;
059: }
060:
061: /**
062: * Returns a string representation of the current hunk
063: * with normal format .
064: */
065: public String convert() {
066: String s = new String(+ld1 + "a" + ld2);
067: if (ld2 != lf2)
068: s = s.concat("," + lf2);
069: s = s.concat("\n");
070: for (Enumeration e = b.elements(); e.hasMoreElements();)
071: s = s.concat("> " + (String) e.nextElement());
072: return s;
073: }
074:
075: /**
076: * Returns a string representation of the current hunk
077: * with ED_script format .
078: */
079: public String convert_ED() {
080: String s = new String(+ld1 + "a\n");
081: for (Enumeration e = b.elements(); e.hasMoreElements();)
082: s = s.concat((String) e.nextElement());
083: s = s.concat(".\n");
084: return s;
085: }
086:
087: /**
088: * Returns a string representation of the current hunk
089: * with RCS_script format .
090: */
091: public String convert_RCS() {
092: String s = new String("a" + ld1 + " " + (lf2 - ld2 + 1) + "\n");
093: for (Enumeration e = b.elements(); e.hasMoreElements();)
094: s = s.concat((String) e.nextElement());
095: return s;
096: }
097:
098: /**
099: * Returns the number of low line of file passed in argument .
100: * Lines are inclusif.
101: *
102: * @param filenum The number of file (the first file '0', or the second '1').
103: */
104: public int lowLine(int filenum) {
105: if (filenum == 0)
106: return ld1;
107: else
108: return ld2;
109: }
110:
111: /**
112: * Returns the number of high line of file passed in argument .
113: * Lines are inclusif.
114: *
115: * @param filenum The number of file (the first file '0', or the second '1').
116: */
117: public int highLine(int filenum) {
118: if (filenum == 0)
119: return ld1;
120: else
121: return lf2;
122: }
123:
124: /**
125: * Returns the number of lines consedered in this hunk and which
126: * came from file passed in argument .
127: *
128: * @param filenum The number of file (the first file '0', or the second '1').
129: */
130: public int numLines(int filenum) {
131: if (filenum == 0)
132: return 1;
133: else
134: return (lf2 - ld2 + 1);
135: }
136:
137: /**
138: * Returns a string representing the line in file and position
139: * passed in argument.
140: *
141: * @param filenum The number of file (the first file '0', or the second '1').
142: * @param linenum the number of line that will be returned.
143: */
144: public String relNum(int filenum, int linenum) {
145: if (filenum == 0)
146: return null;
147: else
148: return (String) b.elementAt(linenum);
149: }
150:
151: }
|