KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > driver > diff > HunkDel


1 package org.enhydra.xml.driver.diff;
2
3 import java.util.Enumeration JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 /**
7   * The <code>HunkDel</code> class represents a bloc of difference that will
8   * be deleted.
9   */

10 public class HunkDel extends Hunk{
11
12   int ld1;
13   int lf1;
14   int ld2;
15
16   Vector JavaDoc a=new Vector JavaDoc();
17
18     public void accept(HunkVisitor visitor) {
19     visitor.visitHunkDel(this);
20     }
21
22
23     /**
24      * Returns string to delete.
25      */

26     public String JavaDoc getOldContents(){
27     String JavaDoc s=new String JavaDoc();
28     for (Enumeration JavaDoc e = a.elements() ; e.hasMoreElements() ;)
29         s=s.concat((String JavaDoc)e.nextElement());
30     return s;
31     }
32
33   /**
34    * Returns a string representation of the current hunk
35    * with normal format .
36    */

37   public String JavaDoc convert(){
38     String JavaDoc s=new String JavaDoc(Integer.toString(ld1));
39     if(ld1!=lf1)
40       s=s.concat(","+lf1);
41     s=s.concat("d"+ld2+"\n");
42     for (Enumeration JavaDoc e = a.elements() ; e.hasMoreElements() ;)
43     s=s.concat("< "+(String JavaDoc)e.nextElement());
44     return s;
45   }
46
47  /**
48    * Returns a string representation of the current hunk
49    * with ED_script format .
50    */

51   public String JavaDoc convert_ED(){
52     String JavaDoc s=new String JavaDoc(Integer.toString(ld1));
53     if(ld1!=lf1)
54       s=s.concat(","+lf1);
55     s=s.concat("d\n");
56     return s;
57   }
58
59   /**
60     * Returns a string representation of the current hunk
61     * with RCS_script format .
62     */

63   public String JavaDoc convert_RCS(){
64     String JavaDoc s=new String JavaDoc("d"+ld1+" "+(lf1-ld1+1)+"\n");
65     return s;
66   }
67
68   /**
69    * Returns the number of low line of file passed in argument .
70    * Lines are inclusif.
71    *
72    * @param filenum The number of file (the first file '0', or the second '1').
73    */

74   public int lowLine(int filenum){
75     if(filenum==0)
76       return ld1;
77     else
78       return ld2;
79   }
80
81  /**
82    * Returns the number of high line of file passed in argument .
83    * Lines are inclusif.
84    *
85    * @param filenum The number of file (the first file '0', or the second '1').
86    */

87   public int highLine(int filenum){
88     if(filenum==0)
89       return lf1;
90     else
91       return ld2;
92   }
93
94   /**
95    * Returns the number of lines consedered in this hunk and which
96    * came from file passed in argument .
97    *
98    * @param filenum The number of file (the first file '0', or the second '1').
99    */

100   public int numLines(int filenum){
101     if(filenum==0)
102       return (lf1 - ld1 +1);
103     else
104       return 1;
105   }
106
107  /**
108    * Returns a string representing the line in file and position
109    * passed in argument.
110    *
111    * @param filenum The number of file (the first file '0', or the second '1').
112    * @param linenum the number of line that will be returned.
113    */

114   public String JavaDoc relNum(int filenum,int linenum){
115     if(filenum==0)
116       return (String JavaDoc)a.elementAt(linenum);
117     else
118       return null;
119   }
120
121 }
122
Popular Tags