blob: c5fd8ba2455a15a3edcb0f3011abdf46adaa24d4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.compare.internal.merge;
import java.io.*;
import java.util.ArrayList;
import org.eclipse.compare.rangedifferencer.IRangeComparator;
/**
* This implementation of IRangeComparator breaks an input stream into lines.
*/
class LineComparator implements IRangeComparator {
private String[] fLines;
public LineComparator(InputStream is, String encoding) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
String line;
ArrayList ar = new ArrayList();
while ((line = br.readLine()) != null) {
ar.add(line);
}
// It is the responsibility of the caller to close the stream
fLines = (String[]) ar.toArray(new String[ar.size()]);
}
String getLine(int ix) {
return fLines[ix];
}
/* (non-Javadoc)
* @see org.eclipse.compare.rangedifferencer.IRangeComparator#getRangeCount()
*/
public int getRangeCount() {
return fLines.length;
}
/* (non-Javadoc)
* @see org.eclipse.compare.rangedifferencer.IRangeComparator#rangesEqual(int, org.eclipse.compare.rangedifferencer.IRangeComparator, int)
*/
public boolean rangesEqual(int thisIndex, IRangeComparator other,
int otherIndex) {
String s1 = fLines[thisIndex];
String s2 = ((LineComparator) other).fLines[otherIndex];
return s1.equals(s2);
}
/* (non-Javadoc)
* @see org.eclipse.compare.rangedifferencer.IRangeComparator#skipRangeComparison(int, int, org.eclipse.compare.rangedifferencer.IRangeComparator)
*/
public boolean skipRangeComparison(int length, int maxLength, IRangeComparator other) {
return false;
}
}
|