Source Code Cross Referenced for DiffProcessor.java in  » Source-Control » gruntspud » allensoft » diff » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Source Control » gruntspud » allensoft.diff 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:           Copyright 2001 Nicholas Allen (nallen@freenet.co.uk)
003:           This file is part of JavaCVS.
004:           JavaCVS is free software; you can redistribute it and/or modify
005:           it under the terms of the GNU General Public License as published by
006:           the Free Software Foundation; either version 2 of the License, or
007:           (at your option) any later version.
008:           JavaCVS is distributed in the hope that it will be useful,
009:           but WITHOUT ANY WARRANTY; without even the implied warranty of
010:           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011:           GNU General Public License for more details.
012:           You should have received a copy of the GNU General Public License
013:           along with JavaCVS; if not, write to the Free Software
014:           Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
015:         */
016:        package allensoft.diff;
017:
018:        import java.io.BufferedReader;
019:        import java.io.EOFException;
020:        import java.io.IOException;
021:        import java.io.Reader;
022:
023:        /** Proceses differences and applies them to a Reader. The output is controlled by overridable
024:         printXXXX methods. By default these methods simply output the result of applying the
025:         differences to System.out. */
026:        public class DiffProcessor {
027:            private BufferedReader m_In;
028:            private DiffParser m_DiffParser;
029:
030:            /** Creates a new DiffProcessor that applies the differnces returned from <code>diffParser</code>
031:               to <code>file1</code>. */
032:            public DiffProcessor(Reader file1, DiffParser diffParser) {
033:                m_In = new BufferedReader(file1);
034:                m_DiffParser = diffParser;
035:            }
036:
037:            /** Runs this DiffProcessor. */
038:            public void run() throws IOException, DiffException {
039:                int nLineNumInFile1 = 1;
040:                int nLineNumInFile2 = 1;
041:                String sLine;
042:
043:                while (true) {
044:                    Difference d = m_DiffParser.getNextDifference();
045:
046:                    if (d == null) {
047:                        while ((sLine = m_In.readLine()) != null) {
048:                            printLineInFile1(nLineNumInFile1, DiffType.NONE,
049:                                    sLine);
050:                            printLineInFile2(nLineNumInFile2, DiffType.NONE,
051:                                    sLine);
052:                            nLineNumInFile1++;
053:                            nLineNumInFile2++;
054:                        }
055:
056:                        break;
057:                    }
058:
059:                    if (d instanceof  Insertion) {
060:                        Insertion insertion = (Insertion) d;
061:
062:                        while (nLineNumInFile1 <= insertion
063:                                .getStartLineInFile1()) {
064:                            sLine = m_In.readLine();
065:
066:                            if (sLine == null)
067:                                throw new EOFException();
068:
069:                            printLineInFile1(nLineNumInFile1, DiffType.NONE,
070:                                    sLine);
071:                            printLineInFile2(nLineNumInFile2, DiffType.NONE,
072:                                    sLine);
073:                            nLineNumInFile1++;
074:                            nLineNumInFile2++;
075:                        }
076:
077:                        nLineNumInFile2 = insertion.getStartLineInFile2();
078:
079:                        String sInsertedText = insertion.getInsertedText();
080:                        int i = 0;
081:
082:                        while (i < sInsertedText.length()) {
083:                            int nStartOfNextLine = sInsertedText.indexOf('\n',
084:                                    i);
085:                            sLine = (nStartOfNextLine == -1) ? sInsertedText
086:                                    .substring(i) : sInsertedText.substring(i,
087:                                    nStartOfNextLine);
088:
089:                            printNonExistantLineInFile1();
090:                            printLineInFile2(nLineNumInFile2,
091:                                    DiffType.INSERTION, sLine);
092:                            nLineNumInFile2++;
093:
094:                            if (nStartOfNextLine == -1)
095:                                break;
096:
097:                            i = nStartOfNextLine + 1;
098:                        }
099:                    } else if (d instanceof  Change) {
100:                        Change change = (Change) d;
101:
102:                        while (nLineNumInFile1 < change.getStartLineInFile1()) {
103:                            sLine = m_In.readLine();
104:
105:                            if (sLine == null)
106:                                throw new EOFException();
107:
108:                            printLineInFile1(nLineNumInFile1, DiffType.NONE,
109:                                    sLine);
110:                            printLineInFile2(nLineNumInFile2, DiffType.NONE,
111:                                    sLine);
112:                            nLineNumInFile1++;
113:                            nLineNumInFile2++;
114:                        }
115:
116:                        int nNumLinesPrintedInFile1 = 0;
117:                        int nNumLinesPrintedInFile2 = 0;
118:
119:                        while (nLineNumInFile1 <= change.getEndLineInFile1()) {
120:                            sLine = m_In.readLine();
121:
122:                            if (sLine == null)
123:                                throw new EOFException();
124:
125:                            printLineInFile1(nLineNumInFile1, DiffType.CHANGE,
126:                                    sLine);
127:                            nLineNumInFile1++;
128:                            nNumLinesPrintedInFile1++;
129:                        }
130:
131:                        nLineNumInFile2 = change.getStartLineInFile2();
132:
133:                        String sChangedText = change.getToText();
134:                        int i = 0;
135:
136:                        while (i < sChangedText.length()) {
137:                            int nStartOfNextLine = sChangedText
138:                                    .indexOf('\n', i);
139:                            sLine = (nStartOfNextLine == -1) ? sChangedText
140:                                    .substring(i) : sChangedText.substring(i,
141:                                    nStartOfNextLine);
142:
143:                            printLineInFile2(nLineNumInFile2, DiffType.CHANGE,
144:                                    sLine);
145:                            nLineNumInFile2++;
146:                            nNumLinesPrintedInFile2++;
147:
148:                            if (nStartOfNextLine == -1)
149:                                break;
150:
151:                            i = nStartOfNextLine + 1;
152:                        }
153:
154:                        if (nNumLinesPrintedInFile1 > nNumLinesPrintedInFile2) {
155:                            for (int j = nNumLinesPrintedInFile2; j < nNumLinesPrintedInFile1; j++)
156:                                printNonExistantLineInFile2();
157:                        } else if (nNumLinesPrintedInFile2 > nNumLinesPrintedInFile1) {
158:                            for (int j = nNumLinesPrintedInFile1; j < nNumLinesPrintedInFile2; j++)
159:                                printNonExistantLineInFile1();
160:                        }
161:                    } else if (d instanceof  Deletion) {
162:                        Deletion deletion = (Deletion) d;
163:
164:                        while (nLineNumInFile1 < deletion.getStartLineInFile1()) {
165:                            sLine = m_In.readLine();
166:
167:                            if (sLine == null)
168:                                throw new EOFException();
169:
170:                            printLineInFile1(nLineNumInFile1, DiffType.NONE,
171:                                    sLine);
172:                            printLineInFile2(nLineNumInFile2, DiffType.NONE,
173:                                    sLine);
174:                            nLineNumInFile1++;
175:                            nLineNumInFile2++;
176:                        }
177:
178:                        while (nLineNumInFile1 <= deletion.getEndLineInFile1()) {
179:                            sLine = m_In.readLine();
180:
181:                            if (sLine == null)
182:                                throw new EOFException();
183:
184:                            printLineInFile1(nLineNumInFile1,
185:                                    DiffType.DELETION, sLine);
186:                            printNonExistantLineInFile2();
187:                            nLineNumInFile1++;
188:                        }
189:                    }
190:                }
191:            }
192:
193:            /** Displays a line in File1. File1 is the file provided by the Reader supplied at construction time. */
194:            protected void printLineInFile1(int nLineNum, DiffType type,
195:                    String sLine) {
196:            }
197:
198:            /** Displays a non-existant line in File1. File1 is the file provided by the Reader supplied at construction time. */
199:            protected void printNonExistantLineInFile1() {
200:            }
201:
202:            /** Displays a line in File2. File2 is the file resulting from applying the differences to File1. */
203:            protected void printLineInFile2(int nLineNum, DiffType type,
204:                    String sLine) {
205:                System.out.println(sLine);
206:            }
207:
208:            /** Displays a non-existant line in File2. File2 is the file resulting from applying the differences to File1. */
209:            protected void printNonExistantLineInFile2() {
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.