1 19 20 package org.netbeans.lib.cvsclient.command.diff; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.netbeans.lib.cvsclient.command.*; 26 27 33 public class DiffInformation extends FileInfoContainer { 34 private File file; 35 36 private String repositoryFileName; 37 38 private String rightRevision; 39 40 private String leftRevision; 41 42 private String parameters; 43 44 47 private final List changesList = new ArrayList(); 48 49 private Iterator iterator; 50 51 public DiffInformation() { 52 } 53 54 58 public File getFile() { 59 return file; 60 } 61 62 66 public void setFile(File file) { 67 this.file = file; 68 } 69 70 74 public String getRepositoryFileName() { 75 return repositoryFileName; 76 } 77 78 82 public void setRepositoryFileName(String repositoryFileName) { 83 this.repositoryFileName = repositoryFileName; 84 } 85 86 89 public String toString() { 90 StringBuffer buf = new StringBuffer (30); 91 buf.append("\nFile: " + ((file != null)?file.getAbsolutePath():"null")); buf.append("\nRCS file: " + repositoryFileName); buf.append("\nRevision: " + leftRevision); if (rightRevision != null) { 95 buf.append("\nRevision: " + rightRevision); } 97 buf.append("\nParameters: " + parameters); return buf.toString(); 100 } 101 102 105 public String getRightRevision() { 106 return rightRevision; 107 } 108 109 112 public void setRightRevision(String rightRevision) { 113 this.rightRevision = rightRevision; 114 } 115 116 119 public String getLeftRevision() { 120 return leftRevision; 121 } 122 123 126 public void setLeftRevision(String leftRevision) { 127 this.leftRevision = leftRevision; 128 } 129 130 public String getParameters() { 131 return parameters; 132 } 133 134 public void setParameters(String parameters) { 135 this.parameters = parameters; 136 } 137 138 public DiffChange createDiffChange() { 139 return new DiffChange(); 140 } 141 142 public void addChange(DiffChange change) { 143 changesList.add(change); 144 } 145 146 public DiffChange getFirstChange() { 147 iterator = changesList.iterator(); 148 return getNextChange(); 149 } 150 151 public DiffChange getNextChange() { 152 if (iterator == null) { 153 return null; 154 } 155 if (!iterator.hasNext()) { 156 return null; 157 } 158 return (DiffChange)iterator.next(); 159 } 160 161 public class DiffChange { 162 public static final int ADD = 0; 163 public static final int DELETE = 1; 164 public static final int CHANGE = 2; 165 166 protected int type; 167 private int leftBeginning = -1; 168 private int leftEnd = -1; 169 private final List leftDiff = new ArrayList(); 170 private int rightBeginning = -1; 171 private int rightEnd = -1; 172 private final List rightDiff = new ArrayList(); 173 174 public DiffChange() { 175 } 176 177 public void setType(int typeChange) { 178 type = typeChange; 180 } 181 182 public int getType() { 183 return type; 184 } 185 186 public void setLeftRange(int min, int max) { 187 leftBeginning = min; 189 leftEnd = max; 190 } 191 192 public void setRightRange(int min, int max) { 193 rightBeginning = min; 195 rightEnd = max; 196 } 197 198 public int getMainBeginning() { 199 return rightBeginning; 200 } 201 202 public int getRightMin() { 203 return rightBeginning; 204 } 205 206 public int getRightMax() { 207 return rightEnd; 208 } 209 210 public int getLeftMin() { 211 return leftBeginning; 212 } 213 214 public int getLeftMax() { 215 return leftEnd; 216 } 217 218 public boolean isInRange(int number, boolean left) { 219 if (left) { 220 return (number >= leftBeginning && number <= leftEnd); 221 } 222 223 return (number >= rightBeginning && number <= rightEnd); 224 } 225 226 public String getLine(int number, boolean left) { 227 if (left) { 228 int index = number - leftBeginning; 229 if (index < 0 || index >= leftDiff.size()) { 230 return null; 231 } 232 String line = (String )leftDiff.get(index); 233 return line; 234 } 235 else { 236 int index = number - rightBeginning; 237 if (index < 0 || index >= rightDiff.size()) { 238 return null; 239 } 240 String line = (String )rightDiff.get(index); 241 return line; 242 } 243 } 244 245 public void appendLeftLine(String diffLine) { 246 leftDiff.add(diffLine); 247 } 248 249 public void appendRightLine(String diffLine) { 250 rightDiff.add(diffLine); 251 } 252 } 253 } | Popular Tags |