Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java98
1 files changed, 49 insertions, 49 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
index e42185a4c..57ecdefe9 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
@@ -41,7 +41,7 @@ import com.ibm.icu.text.MessageFormat;
* <LI><code>contentsEqual</code>: for comparing the content of leaf objects, that is, objects without children,
* <LI><code>visit</code>: for every pair of compared object the compare result is passed in.
* </UL>
- * Clients may use as is, or subclass to provide a custom implementation for the three hooks.
+ * Clients may use as is, or subclass to provide a custom implementation for the three hooks.
* However the default implementation already deals with the typical case:
* <UL>
* <LI><code>getChildren</code>: tries to apply the <code>IStructureComparator</code>
@@ -85,12 +85,12 @@ public class Differencer {
* Three-way change constant (value 4) indicating a change on left side.
*/
public static final int LEFT= 4;
-
+
/**
* Three-way change constant (value 8) indicating a change on right side.
*/
public static final int RIGHT= 8;
-
+
/**
* Three-way change constant (value 12) indicating a change on left and
* right sides.
@@ -103,19 +103,19 @@ public class Differencer {
public static final int DIRECTION_MASK= 12;
/**
- * Constant (value 16) indicating a change on left and
+ * Constant (value 16) indicating a change on left and
* right side (with respect to ancestor) but left and right are identical.
*/
public static final int PSEUDO_CONFLICT= 16;
-
+
static class Node {
List<Node> fChildren;
int fCode;
Object fAncestor;
Object fLeft;
Object fRight;
-
+
Node() {
// nothing to do
}
@@ -156,10 +156,10 @@ public class Differencer {
// name= ((ITypedElement)fRight).getName();
// if (name == null)
// name= "???"; //$NON-NLS-1$
-//
+//
// for (int i= 0; i < level; i++)
// System.out.print(" "); //$NON-NLS-1$
-//
+//
// System.out.println(getDiffType(fCode) + name);
// }
@@ -190,17 +190,17 @@ public class Differencer {
// }
// return dir + change + " "; //$NON-NLS-1$
// }
- }
-
+ }
+
/**
* Creates a new differencing engine.
*/
public Differencer() {
// nothing to do
}
-
+
/**
- * Starts the differencing engine on the three input objects. If threeWay is <code>true</code> a
+ * Starts the differencing engine on the three input objects. If threeWay is <code>true</code> a
* three-way comparison is performed, otherwise a two-way compare (in the latter case the ancestor argument is ignored).
* The progress monitor is passed to the method <code>updateProgress</code> which is called for every node or
* leaf compare. The method returns the object that was returned from the top-most call to method <code>visit</code>.
@@ -210,16 +210,16 @@ public class Differencer {
* @param pm a progress monitor which is passed to method <code>updateProgress</code>
* @param data a client data that is passed to the top-level call to <code>visit</code>
* @param ancestor the ancestor object of the compare (may be <code>null</code>)
- * @param left the left object of the compare
+ * @param left the left object of the compare
* @param right the right object of the compare
* @return the object returned from the top most call to method <code>visit</code>,
* possibly <code>null</code>
*/
public Object findDifferences(boolean threeWay, IProgressMonitor pm, Object data, Object ancestor, Object left, Object right) {
Node root= new Node();
-
+
int code= traverse(threeWay, root, pm, threeWay ? ancestor : null, left, right);
-
+
if (code != NO_CHANGE) {
List<Node> l= root.fChildren;
if (!l.isEmpty()) {
@@ -229,7 +229,7 @@ public class Differencer {
}
return null;
}
-
+
/*
* Traverse tree in postorder.
*/
@@ -238,23 +238,23 @@ public class Differencer {
Object[] ancestorChildren= getChildren(ancestor);
Object[] rightChildren= getChildren(right);
Object[] leftChildren= getChildren(left);
-
+
int code= NO_CHANGE;
-
+
Node node= new Node(parent, ancestor, left, right);
-
+
boolean content= true; // we reset this if we have at least one child
-
+
if (((threeWay && ancestorChildren != null) || !threeWay)
&& rightChildren != null && leftChildren != null) {
// we only recurse down if no leg is null
// a node
-
+
Set<Object> allSet= new HashSet<>(20);
Map<Object, Object> ancestorSet= null;
Map<Object, Object> rightSet= null;
Map<Object, Object> leftSet= null;
-
+
if (ancestorChildren != null) {
ancestorSet= new HashMap<>(10);
for (int i= 0; i < ancestorChildren.length; i++) {
@@ -281,21 +281,21 @@ public class Differencer {
allSet.add(leftChild);
}
}
-
+
for (Object keyChild : allSet) {
if (pm != null) {
if (pm.isCanceled())
throw new OperationCanceledException();
-
+
updateProgress(pm, keyChild);
}
-
+
Object ancestorChild= ancestorSet != null ? ancestorSet.get(keyChild) : null;
Object leftChild= leftSet != null ? leftSet.get(keyChild) : null;
Object rightChild= rightSet != null ? rightSet.get(keyChild) : null;
-
+
int c= traverse(threeWay, node, pm, ancestorChild, leftChild, rightChild);
-
+
if ((c & CHANGE_TYPE_MASK) != NO_CHANGE) {
code|= CHANGE; // deletions and additions of child result in a change of the container
code|= (c & DIRECTION_MASK); // incoming & outgoing are just ored
@@ -306,12 +306,12 @@ public class Differencer {
if (content) // a leaf
code= compare(threeWay, ancestor, left, right);
-
+
node.fCode= code;
-
+
return code;
}
-
+
/**
* Called for every node or leaf comparison.
* The differencing engine passes in the input objects of the compare and the result of the compare.
@@ -333,15 +333,15 @@ public class Differencer {
protected Object visit(Object data, int result, Object ancestor, Object left, Object right) {
return new DiffNode((IDiffContainer) data, result, (ITypedElement)ancestor, (ITypedElement)left, (ITypedElement)right);
}
-
+
/*
* Performs a 2-way or 3-way compare of the given leaf elements and returns an integer
* describing the kind of difference.
*/
private int compare(boolean threeway, Object ancestor, Object left, Object right) {
-
+
int description= NO_CHANGE;
-
+
if (threeway) {
if (ancestor == null) {
if (left == null) {
@@ -368,18 +368,18 @@ public class Differencer {
if (contentsEqual(ancestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR, right, MergeViewerContentProvider.RIGHT_CONTRIBUTOR))
description= LEFT | DELETION;
else
- description= CONFLICTING | CHANGE;
+ description= CONFLICTING | CHANGE;
}
} else {
if (right == null) {
if (contentsEqual(ancestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR, left, MergeViewerContentProvider.LEFT_CONTRIBUTOR))
description= RIGHT | DELETION;
else
- description= CONFLICTING | CHANGE;
+ description= CONFLICTING | CHANGE;
} else {
boolean ay= contentsEqual(ancestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR, left, MergeViewerContentProvider.LEFT_CONTRIBUTOR);
boolean am= contentsEqual(ancestor, MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR, right, MergeViewerContentProvider.RIGHT_CONTRIBUTOR);
-
+
if (ay && am) {
// empty
} else if (ay && !am) {
@@ -411,7 +411,7 @@ public class Differencer {
}
}
}
-
+
return description;
}
@@ -422,7 +422,7 @@ public class Differencer {
* <code>contentsEqual(Object input1, Object input2)</code>. Subclasses may
* override to implement a different content compare on the given inputs.
* </p>
- *
+ *
* @param input1
* first input to contents compare
* @param contributor1
@@ -445,7 +445,7 @@ public class Differencer {
* <p>
* The <code>Differencer</code> implementation
* returns <code>true</code> if both inputs implement <code>IStreamContentAccessor</code>
- * and their byte contents is identical. Subclasses may override to implement
+ * and their byte contents is identical. Subclasses may override to implement
* a different content compare on the given inputs.
* </p>
*
@@ -454,20 +454,20 @@ public class Differencer {
* @return <code>true</code> if content is equal
*/
protected boolean contentsEqual(Object input1, Object input2) {
-
+
if (input1 == input2)
return true;
-
+
InputStream is1= getStream(input1);
InputStream is2= getStream(input2);
-
+
if (is1 == null && is2 == null) // no byte contents
return true;
-
+
try {
if (is1 == null || is2 == null) // only one has contents
return false;
-
+
while (true) {
int c1= is1.read();
int c2= is2.read();
@@ -475,7 +475,7 @@ public class Differencer {
return true;
if (c1 != c2)
break;
-
+
}
} catch (IOException ex) {
// NeedWork
@@ -497,7 +497,7 @@ public class Differencer {
}
return false;
}
-
+
/*
* Tries to return an InputStream for the given object.
* Returns <code>null</code> if the object not an IStreamContentAccessor
@@ -513,11 +513,11 @@ public class Differencer {
}
return null;
}
-
+
/**
* Returns the children of the given input or <code>null</code> if there are no children.
* <p>
- * The <code>Differencer</code> implementation checks whether the input
+ * The <code>Differencer</code> implementation checks whether the input
* implements the <code>IStructureComparator</code> interface. If yes it is used
* to return an array containing all children. Otherwise <code>null</code> is returned.
* Subclasses may override to implement a different strategy to enumerate children.
@@ -531,7 +531,7 @@ public class Differencer {
return ((IStructureComparator) input).getChildren();
return null;
}
-
+
/**
* Called for every leaf or node compare to update progress information.
* <p>

Back to the top