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: HunkDel.java$
021: * $FileID: 4280$
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>HunkDel</code> class represents a bloc of difference that will
037: * be deleted.
038: */
039: public class HunkDel extends Hunk implements java.io.Serializable {
040:
041: int ld1;
042: int lf1;
043: int ld2;
044:
045: Vector a = new Vector();
046:
047: public void accept(HunkVisitor visitor) {
048: visitor.visitHunkDel(this );
049: }
050:
051: /**
052: * Returns string to delete.
053: */
054: public String getOldContents() {
055: String s = new String();
056: for (Enumeration e = a.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(Integer.toString(ld1));
067: if (ld1 != lf1)
068: s = s.concat("," + lf1);
069: s = s.concat("d" + ld2 + "\n");
070: for (Enumeration e = a.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(Integer.toString(ld1));
081: if (ld1 != lf1)
082: s = s.concat("," + lf1);
083: s = s.concat("d\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("d" + ld1 + " " + (lf1 - ld1 + 1) + "\n");
093: return s;
094: }
095:
096: /**
097: * Returns the number of low line of file passed in argument .
098: * Lines are inclusif.
099: *
100: * @param filenum The number of file (the first file '0', or the second '1').
101: */
102: public int lowLine(int filenum) {
103: if (filenum == 0)
104: return ld1;
105: else
106: return ld2;
107: }
108:
109: /**
110: * Returns the number of high line of file passed in argument .
111: * Lines are inclusif.
112: *
113: * @param filenum The number of file (the first file '0', or the second '1').
114: */
115: public int highLine(int filenum) {
116: if (filenum == 0)
117: return lf1;
118: else
119: return ld2;
120: }
121:
122: /**
123: * Returns the number of lines consedered in this hunk and which
124: * came from file passed in argument .
125: *
126: * @param filenum The number of file (the first file '0', or the second '1').
127: */
128: public int numLines(int filenum) {
129: if (filenum == 0)
130: return (lf1 - ld1 + 1);
131: else
132: return 1;
133: }
134:
135: /**
136: * Returns a string representing the line in file and position
137: * passed in argument.
138: *
139: * @param filenum The number of file (the first file '0', or the second '1').
140: * @param linenum the number of line that will be returned.
141: */
142: public String relNum(int filenum, int linenum) {
143: if (filenum == 0)
144: return (String) a.elementAt(linenum);
145: else
146: return null;
147: }
148:
149: }
|