2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.lib.cvsclient.command.diff;
47
import org.netbeans.lib.cvsclient.command.*;
50
* Describes diff information for 2 fversions of a file. This is the result of doing a
51
* cvs diff command. The fields in instances of this object are populated
52
* by response handlers.
53
* @author Milos Kleint
55
public class DiffInformation extends FileInfoContainer {
58
private String repositoryFileName;
60
private String rightRevision;
62
private String leftRevision;
64
private String parameters;
67
* List of changes stored here
69
private final List changesList = new ArrayList();
71
private Iterator iterator;
73
public DiffInformation() {
77
* Getter for property file.
78
* @return Value of property file.
80
public File getFile() {
85
* Setter for property file.
86
* @param file New value of property file.
88
public void setFile(File file) {
93
* Getter for property repositoryFileName.
94
* @return Value of property repositoryFileName.
96
public String getRepositoryFileName() {
97
return repositoryFileName;
101
* Setter for property repositoryFileName.
102
* @param repositoryRevision New value of property repositoryFileName.
104
public void setRepositoryFileName(String repositoryFileName) {
105
this.repositoryFileName = repositoryFileName;
109
* Return a string representation of this object. Useful for debugging.
111
public String toString() {
112
StringBuffer buf = new StringBuffer(30);
113
buf.append("\nFile: " + ((file != null)?file.getAbsolutePath():"null")); //NOI18N
114
buf.append("\nRCS file: " + repositoryFileName); //NOI18N
115
buf.append("\nRevision: " + leftRevision); //NOI18N
116
if (rightRevision != null) {
117
buf.append("\nRevision: " + rightRevision); //NOI18N
119
buf.append("\nParameters: " + parameters); //NOI18N
120
// buf.append(differences.toString());
121
return buf.toString();
124
/** Getter for property rightRevision.
125
* @return Value of property rightRevision.
127
public String getRightRevision() {
128
return rightRevision;
131
/** Setter for property rightRevision.
132
* @param rightRevision New value of property rightRevision.
134
public void setRightRevision(String rightRevision) {
135
this.rightRevision = rightRevision;
138
/** Getter for property leftRevision.
139
* @return Value of property leftRevision.
141
public String getLeftRevision() {
145
/** Setter for property leftRevision.
146
* @param leftRevision New value of property leftRevision.
148
public void setLeftRevision(String leftRevision) {
149
this.leftRevision = leftRevision;
152
public String getParameters() {
156
public void setParameters(String parameters) {
157
this.parameters = parameters;
160
public DiffChange createDiffChange() {
161
return new DiffChange();
164
public void addChange(DiffChange change) {
165
changesList.add(change);
168
public DiffChange getFirstChange() {
169
iterator = changesList.iterator();
170
return getNextChange();
173
public DiffChange getNextChange() {
174
if (iterator == null) {
177
if (!iterator.hasNext()) {
180
return (DiffChange)iterator.next();
183
public class DiffChange {
184
public static final int ADD = 0;
185
public static final int DELETE = 1;
186
public static final int CHANGE = 2;
189
private int leftBeginning = -1;
190
private int leftEnd = -1;
191
private final List leftDiff = new ArrayList();
192
private int rightBeginning = -1;
193
private int rightEnd = -1;
194
private final List rightDiff = new ArrayList();
196
public DiffChange() {
199
public void setType(int typeChange) {
200
// System.out.println("type=" + typeChange);
204
public int getType() {
208
public void setLeftRange(int min, int max) {
209
// System.out.println("setLeftRange() min=" + min + " max=" +max);
214
public void setRightRange(int min, int max) {
215
// System.out.println("setRightRange() min=" + min + " max=" +max);
216
rightBeginning = min;
220
public int getMainBeginning() {
221
return rightBeginning;
224
public int getRightMin() {
225
return rightBeginning;
228
public int getRightMax() {
232
public int getLeftMin() {
233
return leftBeginning;
236
public int getLeftMax() {
240
public boolean isInRange(int number, boolean left) {
242
return (number >= leftBeginning && number <= leftEnd);
245
return (number >= rightBeginning && number <= rightEnd);
248
public String getLine(int number, boolean left) {
250
int index = number - leftBeginning;
251
if (index < 0 || index >= leftDiff.size()) {
254
String line = (String)leftDiff.get(index);
258
int index = number - rightBeginning;
259
if (index < 0 || index >= rightDiff.size()) {
262
String line = (String)rightDiff.get(index);
267
public void appendLeftLine(String diffLine) {
268
leftDiff.add(diffLine);
271
public void appendRightLine(String diffLine) {
272
rightDiff.add(diffLine);
b'\\ No newline at end of file'