KickJava   Java API By Example, From Geeks To Geeks.

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


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>HunkChange</code> class represents a bloc of difference reliding
8   * change.
9   */

10 public class HunkChange extends Hunk{
11
12     int ld1;
13     int lf1;
14     int ld2;
15     int lf2;
16
17     Vector JavaDoc a=new Vector JavaDoc();
18     Vector JavaDoc b=new Vector JavaDoc();
19
20
21     public void accept(HunkVisitor visitor) {
22     visitor.visitHunkChange(this);
23     }
24
25
26     /**
27      * Returns update string.
28      */

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

40     public String JavaDoc convert(){
41     String JavaDoc s=new String JavaDoc(Integer.toString(ld1));
42     if(ld1!=lf1)
43         s=s.concat(","+lf1);
44     s=s.concat("c"+ld2);
45     if(ld2!=lf2)
46         s=s.concat(","+lf2);
47     s=s.concat("\n");
48     for (Enumeration JavaDoc e = a.elements() ; e.hasMoreElements() ;)
49         s=s.concat("< "+(String JavaDoc)e.nextElement());
50     s=s.concat("---\n");
51     for (Enumeration JavaDoc e = b.elements() ; e.hasMoreElements() ;)
52         s=s.concat("> "+(String JavaDoc)e.nextElement());
53     return s;
54     }
55
56     /**
57      * Returns a string representation of the current hunk
58      * with ED_script format .
59      */

60     public String JavaDoc convert_ED(){
61     String JavaDoc s=new String JavaDoc(Integer.toString(ld1));
62     if(ld1!=lf1)
63         s=s.concat(","+lf1);
64     s=s.concat("c\n");
65     for (Enumeration JavaDoc e = b.elements() ; e.hasMoreElements() ;)
66         s=s.concat((String JavaDoc)e.nextElement());
67     s=s.concat(".\n");
68     return s;
69     }
70
71     /**
72      * Returns a string representation of the current hunk
73      * with RCS_script format .
74      */

75     public String JavaDoc convert_RCS(){
76     String JavaDoc s=new String JavaDoc("d"+ld1+" "+(lf1-ld1+1)+"\n");
77     s=s.concat("a"+lf1+" "+(lf2-ld2+1)+"\n");
78     for (Enumeration JavaDoc e = b.elements() ; e.hasMoreElements() ;)
79         s=s.concat((String JavaDoc)e.nextElement());
80     return s;
81     }
82
83     /**
84      * Returns the number of low line of file passed in argument .
85      * Lines are inclusif.
86      *
87      * @param filenum The number of file (the first file '0', or the second '1').
88      */

89     public int lowLine(int filenum){
90     if(filenum==0)
91         return ld1;
92     else
93         return ld2;
94     }
95
96     /**
97      * Returns the number of high line of file passed in argument .
98      * Lines are inclusif.
99      *
100      * @param filenum The number of file (the first file '0', or the second '1').
101      */

102     public int highLine(int filenum){
103     if(filenum==0)
104         return lf1;
105     else
106         return lf2;
107     }
108
109     /**
110      * Returns the number of lines consedered in this hunk and which
111      * came from file passed in argument .
112      *
113      * @param filenum The number of file (the first file '0', or the second '1').
114      */

115     public int numLines(int filenum){
116     if(filenum==0)
117         return (lf1 - ld1 +1);
118     else
119         return(lf2 - ld2 + 1);
120     }
121
122     /**
123      * Returns a string representing the line in file and position passed
124      * in argument.
125      *
126      * @param filenum The number of file (the first file '0', or the second '1').
127      * @param linenum the number of line that will be returned.
128      */

129     public String JavaDoc relNum(int filenum,int linenum){
130     if(filenum==0)
131         return (String JavaDoc)a.elementAt(linenum);
132     else
133         return (String JavaDoc)b.elementAt(linenum);
134     }
135
136 }
137
Popular Tags