KickJava   Java API By Example, From Geeks To Geeks.

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


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>HunkAdd</code> class represents a bloc of difference reliding
8   * addition(insertion).
9   */

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

26     public String JavaDoc getNewContents(){
27     String JavaDoc s=new String JavaDoc();
28     for (Enumeration JavaDoc e = b.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(+ld1+"a"+ld2);
39     if(ld2!=lf2)
40         s=s.concat(","+lf2);
41     s=s.concat("\n");
42     for (Enumeration JavaDoc e = b.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(+ld1+"a\n");
53     for (Enumeration JavaDoc e = b.elements() ; e.hasMoreElements() ;)
54         s=s.concat((String JavaDoc)e.nextElement());
55     s=s.concat(".\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("a"+ld1+" "+(lf2-ld2+1)+"\n");
65     for (Enumeration JavaDoc e = b.elements() ; e.hasMoreElements() ;)
66         s=s.concat((String JavaDoc)e.nextElement());
67     return s;
68     }
69
70     /**
71      * Returns the number of low line of file passed in argument .
72      * Lines are inclusif.
73      *
74      * @param filenum The number of file (the first file '0', or the second '1').
75      */

76     public int lowLine(int filenum){
77     if(filenum==0)
78         return ld1;
79     else
80         return ld2;
81     }
82
83     /**
84      * Returns the number of high 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 highLine(int filenum){
90     if(filenum==0)
91         return ld1;
92     else
93         return lf2;
94     }
95
96     /**
97      * Returns the number of lines consedered in this hunk and which
98      * came from file passed in argument .
99      *
100      * @param filenum The number of file (the first file '0', or the second '1').
101      */

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

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