Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java')
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java
new file mode 100644
index 000000000..6cda1f25e
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/LineComparator.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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 UnsupportedEncodingException {
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
+ String line;
+ ArrayList ar = new ArrayList();
+ try {
+ while ((line = br.readLine()) != null)
+ ar.add(line);
+ } catch (IOException e) {
+ }
+ try {
+ is.close();
+ } catch (IOException e1) {
+ }
+ 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;
+ }
+}

Back to the top