cleanup and compiler warnings fixed
diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java
index e1faaed..d5b86e0 100644
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java
+++ b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java
@@ -41,7 +41,7 @@
if (ordered != null && !ordered.isEmpty()) {
fUseOrdered= true;
fOrdered= new String[ordered.size()];
- int i=0;
+ int i= 0;
for (Iterator iter= ordered.iterator(); iter.hasNext(); i++) {
fOrdered[i]= (String) iter.next();
}
@@ -53,17 +53,25 @@
}
//x and y have children xc_orig and yc_orig, respectively
- protected int unorderedMatch(XMLNode x, XMLNode y, Object[] xc_orig, Object[] yc_orig) {
- ArrayList DTMatching = new ArrayList();//Mathing Entry in fDT_Matchings
- int distance = 0;//distance
-
- Vector xc_vect = new Vector();
- Vector yc_vect = new Vector();
- for (int i=0; i<xc_orig.length; i++) {
- if ( ((XMLNode)xc_orig[i]).usesIDMAP() ) {
+ protected int unorderedMatch(
+ XMLNode x,
+ XMLNode y,
+ Object[] xc_orig,
+ Object[] yc_orig) {
+ ArrayList DTMatching= new ArrayList(); //Mathing Entry in fDT_Matchings
+ int distance= 0; //distance
+
+ Vector xc_vect= new Vector();
+ Vector yc_vect= new Vector();
+ for (int i= 0; i < xc_orig.length; i++) {
+ if (((XMLNode) xc_orig[i]).usesIDMAP()) {
int j;
- for (j=0; j<yc_orig.length && !((XMLNode)yc_orig[j]).getOrigId().equals(((XMLNode)xc_orig[i]).getOrigId()); j++);
- if ( j<yc_orig.length ) {
+ for (j= 0;
+ j < yc_orig.length
+ && !((XMLNode) yc_orig[j]).getOrigId().equals(
+ ((XMLNode) xc_orig[i]).getOrigId());
+ j++);
+ if (j < yc_orig.length) {
/* not calculating their distance and adding it to variable "distance" to save time,
* as matching of subtrees is not performed.
* but better result might be achieved if this were done.
@@ -71,57 +79,59 @@
//int d= dist( (XMLNode)xc_orig[i], (XMLNode)yc_orig[j] );
//distance += d;
//fDT[indexOfLN((XMLNode)xc_orig[i])][indexOfRN((XMLNode)yc_orig[j])]= d;
- DTMatching.add(new Match( (XMLNode)xc_orig[i], (XMLNode)yc_orig[j] ));
+ DTMatching.add(
+ new Match((XMLNode) xc_orig[i], (XMLNode) yc_orig[j]));
}
} else
xc_vect.add(xc_orig[i]);
}
XMLNode[] xc= (XMLNode[]) xc_vect.toArray(new XMLNode[xc_vect.size()]);
- for (int j=0; j<yc_orig.length; j++) {
- if ( !((XMLNode)yc_orig[j]).usesIDMAP() )
+ for (int j= 0; j < yc_orig.length; j++) {
+ if (!((XMLNode) yc_orig[j]).usesIDMAP())
yc_vect.add(yc_orig[j]);
}
XMLNode[] yc= (XMLNode[]) yc_vect.toArray(new XMLNode[yc_vect.size()]);
- if ( xc.length == 0 || yc.length == 0) {
+ if (xc.length == 0 || yc.length == 0) {
if (xc.length == 0) {
- for (int j=0; j<yc.length; j++) {
- distance += countNodes((XMLNode)yc[j]);
+ for (int j= 0; j < yc.length; j++) {
+ distance += countNodes(yc[j]);
}
- } else {//yc.length == 0
- for (int i=0; i<xc.length; i++) {
- distance += countNodes((XMLNode)xc[i]);
+ } else { //yc.length == 0
+ for (int i= 0; i < xc.length; i++) {
+ distance += countNodes(xc[i]);
}
}
} else {
- for (int i=0; i<xc.length; i++) {
- for (int j=0; j<yc.length; j++) {
- if (fDT[indexOfLN( xc[i] )][indexOfRN( yc[j] )] == NO_ENTRY)
+ for (int i= 0; i < xc.length; i++) {
+ for (int j= 0; j < yc.length; j++) {
+ if (fDT[indexOfLN(xc[i])][indexOfRN(yc[j])] == NO_ENTRY)
dist(xc[i], yc[j]);
}
}
-
+
/* look for Wmin (p.11)
* xc and yc are the two partitions that have to be mapped.
* But, they may not have same number of nodes
* HungarianMethod.java solves weighted matching only on complete bipatite graphs
* We must add nodes and edges to make graph complete
*/
- final int array_size = (xc.length > yc.length)?xc.length:yc.length;
- final int array_rowsize = array_size+1;
- final int array_colsize = array_size+2;
- int[][] A = new int[array_rowsize][array_colsize];
- for (int j=0; j<array_colsize; j++) {
- A[0][j] = 0;
+ final int array_size=
+ (xc.length > yc.length) ? xc.length : yc.length;
+ final int array_rowsize= array_size + 1;
+ final int array_colsize= array_size + 2;
+ int[][] A= new int[array_rowsize][array_colsize];
+ for (int j= 0; j < array_colsize; j++) {
+ A[0][j]= 0;
}
/* now: A[0] = new int[] {0,0,0, ... ,0}. This first row is not used by HungarianMethod
* (Fortran77 counts Array index from 1)
*/
- for (int i=1; i<array_rowsize; i++) {
- A[i][0] = 0;
- for (int j=1; j<array_colsize-1; j++) {
- A[i][j] = -1;
+ for (int i= 1; i < array_rowsize; i++) {
+ A[i][0]= 0;
+ for (int j= 1; j < array_colsize - 1; j++) {
+ A[i][j]= -1;
}
- A[i][array_colsize-1] = 0;
+ A[i][array_colsize - 1]= 0;
}
/* now A = 0, 0, 0, ... 0,0
* 0,-1,-1, ... -1,0
@@ -129,129 +139,137 @@
* ...
* 0,-1,-1, ... -1,0
*/
- for (int i_xc = 0; i_xc < xc.length; i_xc++) {
- for (int i_yc = 0; i_yc < yc.length; i_yc++) {
- A[i_xc+1][i_yc+1] = fDT[indexOfLN( xc[i_xc] )][indexOfRN( yc[i_yc] )];
+ for (int i_xc= 0; i_xc < xc.length; i_xc++) {
+ for (int i_yc= 0; i_yc < yc.length; i_yc++) {
+ A[i_xc + 1][i_yc + 1]=
+ fDT[indexOfLN(xc[i_xc])][indexOfRN(yc[i_yc])];
}
}
- int dummyCost=0;
+ int dummyCost= 0;
/* cost of dummy nodes not associated with a node in Tree, but needed
* to have a complete bipartite graph
*/
-
+
//set dummyCost to larger than any cost in A
if (xc.length > yc.length) {
- for (int i=1; i<array_rowsize; i++) {
- for (int j=1; j<=yc.length; j++)
- if (A[i][j] > dummyCost) dummyCost = A[i][j];
+ for (int i= 1; i < array_rowsize; i++) {
+ for (int j= 1; j <= yc.length; j++)
+ if (A[i][j] > dummyCost)
+ dummyCost= A[i][j];
}
} else if (xc.length < yc.length) {
- for (int i=1; i<=xc.length; i++) {
- for (int j=1; j<array_colsize-1; j++)
- if (A[i][j] > dummyCost) dummyCost = A[i][j];
+ for (int i= 1; i <= xc.length; i++) {
+ for (int j= 1; j < array_colsize - 1; j++)
+ if (A[i][j] > dummyCost)
+ dummyCost= A[i][j];
}
- } else {//xc.length == yc.length
- dummyCost = Integer.MAX_VALUE-1;
+ } else { //xc.length == yc.length
+ dummyCost= Integer.MAX_VALUE - 1;
}
dummyCost += 1;
-
+
if (xc.length > yc.length) {
- for (int i=1; i<array_rowsize; i++) {
- for (int j=yc.length+1; j<array_colsize-1; j++) {
- A[i][j] = dummyCost;
+ for (int i= 1; i < array_rowsize; i++) {
+ for (int j= yc.length + 1; j < array_colsize - 1; j++) {
+ A[i][j]= dummyCost;
}
}
} else if (xc.length < yc.length) {
- for (int j=1; j<array_colsize-1; j++) {
- for (int i=xc.length+1; i<array_rowsize; i++) {
- A[i][j] = dummyCost;
+ for (int j= 1; j < array_colsize - 1; j++) {
+ for (int i= xc.length + 1; i < array_rowsize; i++) {
+ A[i][j]= dummyCost;
}
}
}
-
+
//A is built. Now perform matching
- int[] Matching = new int[array_rowsize];
- int[][] A2 = new int[array_rowsize][array_colsize];
- for (int i=0; i<array_rowsize; i++) {
- for (int j=0; j<array_colsize; j++)
- A2[i][j] = A[i][j];
+ int[] Matching= new int[array_rowsize];
+ int[][] A2= new int[array_rowsize][array_colsize];
+ for (int i= 0; i < array_rowsize; i++) {
+ for (int j= 0; j < array_colsize; j++)
+ A2[i][j]= A[i][j];
}
- fH.solve( A2,Matching);
+ fH.solve(A2, Matching);
//now Matching contains the min-cost matching of A
-
- for (int m=1; m<Matching.length; m++) {
+
+ for (int m= 1; m < Matching.length; m++) {
if (A[Matching[m]][m] == dummyCost) {
if (xc.length > yc.length) {
- distance += countNodes( xc[Matching[m]-1] );
+ distance += countNodes(xc[Matching[m] - 1]);
//added here
- DTMatching.add(new Match( (XMLNode)xc[Matching[m]-1] , null));
+ DTMatching.add(new Match(xc[Matching[m] - 1], null));
} else if (xc.length < yc.length) {
- distance += countNodes( yc[m-1] );
+ distance += countNodes(yc[m - 1]);
//added here
- DTMatching.add(new Match( null , yc[m-1]));
+ DTMatching.add(new Match(null, yc[m - 1]));
}
} else {
- int index_x = indexOfLN( xc[Matching[m]-1] );
- int index_y = indexOfRN( yc[m-1]);
- distance += fDT[ index_x ][ index_y ];
- if ( (xc[Matching[m]-1]).getSignature().equals( (yc[m-1]).getSignature() ))
- DTMatching.add(new Match( xc[Matching[m]-1] , yc[m-1] ));
- else {
- DTMatching.add(new Match( xc[Matching[m]-1] , null));
- DTMatching.add(new Match( null , yc[m-1] ));
- }
+ int index_x= indexOfLN(xc[Matching[m] - 1]);
+ int index_y= indexOfRN(yc[m - 1]);
+ distance += fDT[index_x][index_y];
+ if ((xc[Matching[m] - 1])
+ .getSignature()
+ .equals((yc[m - 1]).getSignature()))
+ DTMatching.add(
+ new Match(xc[Matching[m] - 1], yc[m - 1]));
+ else {
+ DTMatching.add(new Match(xc[Matching[m] - 1], null));
+ DTMatching.add(new Match(null, yc[m - 1]));
+ }
}
}
}
- fDT[indexOfLN(x)][indexOfRN(y)] = distance;
- fDT_Matchings[indexOfLN(x)][indexOfRN(y)] = DTMatching;
+ fDT[indexOfLN(x)][indexOfRN(y)]= distance;
+ fDT_Matchings[indexOfLN(x)][indexOfRN(y)]= DTMatching;
return distance;
}
-
-
+
protected int orderedMath(XMLNode x, XMLNode y) {
//assumes x and y have children
boolean old_isw= fIgnoreStartsWith;
fIgnoreStartsWith= true;
-
+
//both x and y have children
- Object[] xc = x.getChildren();
- Object[] yc = y.getChildren();
-
+ Object[] xc= x.getChildren();
+ Object[] yc= y.getChildren();
+
ArrayList xc_elementsAL= new ArrayList();
ArrayList xc_attrsAL= new ArrayList();
ArrayList yc_elementsAL= new ArrayList();
ArrayList yc_attrsAL= new ArrayList();
-
+
//find attributes and elements and put them in xc_elementsAL and xc_attrsAL, respectively
for (int i= 0; i < xc.length; i++) {
XMLNode x_i= (XMLNode) xc[i];
if (x_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) {
xc_elementsAL.add(x_i);
- } else if (x_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) {
+ } else if (
+ x_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) {
xc_attrsAL.add(x_i);
}
}
//do the same for yc
for (int i= 0; i < yc.length; i++) {
- XMLNode y_i= (XMLNode) yc[i];
+ XMLNode y_i= (XMLNode) yc[i];
if (y_i.getXMLType().equals(XMLStructureCreator.TYPE_ELEMENT)) {
yc_elementsAL.add(y_i);
- } else if (y_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) {
+ } else if (
+ y_i.getXMLType().equals(XMLStructureCreator.TYPE_ATTRIBUTE)) {
yc_attrsAL.add(y_i);
}
}
-
+
Object[] xc_elements= xc_elementsAL.toArray();
Object[] yc_elements= yc_elementsAL.toArray();
Object[] xc_attrs= xc_attrsAL.toArray();
Object[] yc_attrs= yc_attrsAL.toArray();
- ArrayList DTMatching= null;//Mathing to be added to Entry in fDT_Matchings
- int distance = 0;//distance to be added to entry in fDT
+ ArrayList DTMatching= null;
+ //Mathing to be added to Entry in fDT_Matchings
+ int distance= 0; //distance to be added to entry in fDT
//perform unordered matching on attributes
//this updates fDT and fDT_Matchings
@@ -269,139 +287,163 @@
if (DTMatching == null)
DTMatching= new ArrayList();
//perform ordered matching on element children, i.e. number them in order of appearance
-
+
/* start new */
- distance= handleRangeDifferencer(xc_elements, yc_elements, DTMatching, distance);
+ distance=
+ handleRangeDifferencer(
+ xc_elements,
+ yc_elements,
+ DTMatching,
+ distance);
/* end new */
-
+
/* start: Naive ordered compare /*
-// int minlength= (xc_elements.length > yc_elements.length)?yc_elements.length:xc_elements.length;
-// for (int i= 0; i < minlength; i++) {
-// distance += dist((XMLNode) xc_elements[i], (XMLNode) yc_elements[i]);
-// DTMatching.add(new Match( (XMLNode)xc_elements[i], (XMLNode)yc_elements[i]));
-// }
-// if (xc_elements.length > yc_elements.length) {
-// for (int i= minlength; i < xc_elements.length; i++) {
-// distance += countNodes((XMLNode) xc_elements[i]);
-// }
-// } else if (xc_elements.length < yc_elements.length) {
-// for (int i= minlength; i < yc_elements.length; i++) {
-// distance += countNodes((XMLNode) yc_elements[i]);
-// }
-// }
+ // int minlength= (xc_elements.length > yc_elements.length)?yc_elements.length:xc_elements.length;
+ // for (int i= 0; i < minlength; i++) {
+ // distance += dist((XMLNode) xc_elements[i], (XMLNode) yc_elements[i]);
+ // DTMatching.add(new Match( (XMLNode)xc_elements[i], (XMLNode)yc_elements[i]));
+ // }
+ // if (xc_elements.length > yc_elements.length) {
+ // for (int i= minlength; i < xc_elements.length; i++) {
+ // distance += countNodes((XMLNode) xc_elements[i]);
+ // }
+ // } else if (xc_elements.length < yc_elements.length) {
+ // for (int i= minlength; i < yc_elements.length; i++) {
+ // distance += countNodes((XMLNode) yc_elements[i]);
+ // }
+ // }
/* end: Naive ordered compare */
-
+
fIgnoreStartsWith= old_isw;
-
- fDT[indexOfLN(x)][indexOfRN(y)] = distance;
- fDT_Matchings[indexOfLN(x)][indexOfRN(y)] = DTMatching;
+
+ fDT[indexOfLN(x)][indexOfRN(y)]= distance;
+ fDT_Matchings[indexOfLN(x)][indexOfRN(y)]= DTMatching;
return distance;
}
-
-
/* matches two trees according to paper "X-Diff", p. 16 */
- public void match(XMLNode LeftTree, XMLNode RightTree, boolean rightTreeIsAncestor, IProgressMonitor monitor) throws InterruptedException {
+ public void match(
+ XMLNode LeftTree,
+ XMLNode RightTree,
+ boolean rightTreeIsAncestor,
+ IProgressMonitor monitor)
+ throws InterruptedException {
//if (monitor != null) monitor.beginTask("",10);
- fH = new HungarianMethod();
- fNLeft = new Vector();//numbering LeftTree: Mapping nodes in LeftTree to numbers to be used as array indexes
- fNRight = new Vector();//numbering RightTree: Mapping nodes in RightTree to numbers to be used as array indexes
+ fH= new HungarianMethod();
+ fNLeft= new Vector();
+ //numbering LeftTree: Mapping nodes in LeftTree to numbers to be used as array indexes
+ fNRight= new Vector();
+ //numbering RightTree: Mapping nodes in RightTree to numbers to be used as array indexes
numberNodes(LeftTree, fNLeft);
numberNodes(RightTree, fNRight);
- fDT = new int[fNLeft.size()][fNRight.size()];
- fDT_Matchings = new ArrayList[fNLeft.size()][fNRight.size()];
- for (int i=0; i<fDT.length; i++) {
- fDT[i] = new int[fNRight.size()];
- for (int j=0; j<fDT[0].length; j++) {
- fDT[i][j] = NO_ENTRY;
+ fDT= new int[fNLeft.size()][fNRight.size()];
+ fDT_Matchings= new ArrayList[fNLeft.size()][fNRight.size()];
+ for (int i= 0; i < fDT.length; i++) {
+ fDT[i]= new int[fNRight.size()];
+ for (int j= 0; j < fDT[0].length; j++) {
+ fDT[i][j]= NO_ENTRY;
}
}
-
- ArrayList NLeft = new ArrayList();
- ArrayList NRight = new ArrayList();
+
+ ArrayList NLeft= new ArrayList();
+ ArrayList NRight= new ArrayList();
findLeaves(LeftTree, NLeft);
findLeaves(RightTree, NRight);
-
+
/* Matching Algorithm */
/* Step 1: Compute editing distance for (LeftTree -> RightTree)*/
while (!NLeft.isEmpty() || !NRight.isEmpty()) {
- for (ListIterator itNLeft=NLeft.listIterator(); itNLeft.hasNext(); ) {
- XMLNode x = (XMLNode) itNLeft.next();
- for (ListIterator itNRight=NRight.listIterator(); itNRight.hasNext(); ) {
- XMLNode y = (XMLNode) itNRight.next();
- if ( x.getSignature().equals(y.getSignature()) ) {
-// System.out.println("x: "+x.getName());
-// System.out.println("y: "+y.getName());
+ for (ListIterator itNLeft= NLeft.listIterator();
+ itNLeft.hasNext();
+ ) {
+ XMLNode x= (XMLNode) itNLeft.next();
+ for (ListIterator itNRight= NRight.listIterator();
+ itNRight.hasNext();
+ ) {
+ XMLNode y= (XMLNode) itNRight.next();
+ if (x.getSignature().equals(y.getSignature())) {
+ // System.out.println("x: "+x.getName());
+ // System.out.println("y: "+y.getName());
if (monitor != null && monitor.isCanceled()) {
-// throw new OperationCanceledException();
+ // throw new OperationCanceledException();
throw new InterruptedException();
-// return;
+ // return;
}
//if signature starts with root>project
//do not calculate dist
-
+
//if signature is root>project
//do ordered search on children
//do unordered search on childrenb
-
- dist(x,y);
+
+ dist(x, y);
}
}
}
- ArrayList NLeft_new = new ArrayList();
- ArrayList NRight_new = new ArrayList();
- for (ListIterator itNLeft=NLeft.listIterator(); itNLeft.hasNext(); ) {
- XMLNode node = (XMLNode) itNLeft.next();
- if ( node.getParent() != null && !NLeft_new.contains(node.getParent()) )
+ ArrayList NLeft_new= new ArrayList();
+ ArrayList NRight_new= new ArrayList();
+ for (ListIterator itNLeft= NLeft.listIterator();
+ itNLeft.hasNext();
+ ) {
+ XMLNode node= (XMLNode) itNLeft.next();
+ if (node.getParent() != null
+ && !NLeft_new.contains(node.getParent()))
NLeft_new.add(node.getParent());
}
- for (ListIterator itNRight=NRight.listIterator(); itNRight.hasNext(); ) {
- XMLNode node = (XMLNode) itNRight.next();
- if ( node.getParent() != null && !NRight_new.contains(node.getParent()) )
+ for (ListIterator itNRight= NRight.listIterator();
+ itNRight.hasNext();
+ ) {
+ XMLNode node= (XMLNode) itNRight.next();
+ if (node.getParent() != null
+ && !NRight_new.contains(node.getParent()))
NRight_new.add(node.getParent());
}
- NLeft = NLeft_new;
- NRight = NRight_new;
+ NLeft= NLeft_new;
+ NRight= NRight_new;
}
//end of Step1
/* Step 2: mark matchings on LeftTree and RightTree */
- fMatches = new Vector();
- if ( !LeftTree.getSignature().equals(RightTree.getSignature()) ) {
+ fMatches= new Vector();
+ if (!LeftTree.getSignature().equals(RightTree.getSignature())) {
//matching is empty
} else {
- fMatches.add(new Match(LeftTree,RightTree));
- for (int i_M = 0; i_M<fMatches.size(); i_M++) {
- Match m = (Match) fMatches.elementAt(i_M);
- if ( !isLeaf(m.fx) && !isLeaf(m.fy) ) {
-// if (fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ] == null)
-// System.out.println("Error: ID not unique for " + m.fx.getId());
-// else
-// fMatches.addAll(fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ]);
- if (fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ] != null)
- fMatches.addAll(fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ]);
+ fMatches.add(new Match(LeftTree, RightTree));
+ for (int i_M= 0; i_M < fMatches.size(); i_M++) {
+ Match m= (Match) fMatches.elementAt(i_M);
+ if (!isLeaf(m.fx) && !isLeaf(m.fy)) {
+ // if (fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ] == null)
+ // System.out.println("Error: ID not unique for " + m.fx.getId());
+ // else
+ // fMatches.addAll(fDT_Matchings[ indexOfLN(m.fx) ][ indexOfRN(m.fy) ]);
+ if (fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)]
+ != null)
+ fMatches.addAll(
+ fDT_Matchings[indexOfLN(m.fx)][indexOfRN(m.fy)]);
}
}
}
//end of Step2
/* Renumber Id of Nodes to follow Matches. Or for ancestor, copy over Id to ancestor */
if (rightTreeIsAncestor) {
- for (ListIterator it_M = fMatches.listIterator(); it_M.hasNext(); ) {
- Match m = (Match) it_M.next();
+ for (ListIterator it_M= fMatches.listIterator(); it_M.hasNext();) {
+ Match m= (Match) it_M.next();
if (m.fx != null && m.fy != null)
m.fy.setId(m.fx.getId());
}
} else {
- int newId = 0;
- for (ListIterator it_M = fMatches.listIterator(); it_M.hasNext(); newId++) {
- Match m = (Match) it_M.next();
+ int newId= 0;
+ for (ListIterator it_M= fMatches.listIterator();
+ it_M.hasNext();
+ newId++) {
+ Match m= (Match) it_M.next();
if (m.fx != null)
m.fx.setId(Integer.toString(newId));
if (m.fy != null)
m.fy.setId(Integer.toString(newId));
-// System.out.println("Matching: "+ ((m.fx != null)?m.fx.getOrigId():"null")+" -> "+((m.fx != null)?m.fx.getId():"null")+" , "+((m.fy != null)?m.fy.getOrigId():"null")+" -> "+((m.fy != null)?m.fy.getId():"null")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ // System.out.println("Matching: "+ ((m.fx != null)?m.fx.getOrigId():"null")+" -> "+((m.fx != null)?m.fx.getId():"null")+" , "+((m.fy != null)?m.fy.getOrigId():"null")+" -> "+((m.fy != null)?m.fy.getId():"null")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
//if (monitor != null) monitor.done();
@@ -409,8 +451,8 @@
protected int handleXandYnotLeaves(XMLNode x, XMLNode y) {
int ret= NO_ENTRY;
- Object[] xc_orig = x.getChildren();
- Object[] yc_orig = y.getChildren();
+ Object[] xc_orig= x.getChildren();
+ Object[] yc_orig= y.getChildren();
/* handle ordered entries */
if (fUseOrdered) {
@@ -418,9 +460,9 @@
boolean equals_sig= false;
String x_sig= x.getSignature();
String y_sig= y.getSignature();
-
+
int i_ordered;
-
+
if (!fIgnoreStartsWith) {
/* Normal case when algorithm runs.
* Algorithm runs bottom up from leaves to root.
@@ -432,11 +474,16 @@
* Thus, we exit the procedure dist() if this is the case.
*/
for (i_ordered= 0; i_ordered < fOrdered.length; i_ordered++) {
- if (x_sig.startsWith(fOrdered[i_ordered]) || y_sig.startsWith(fOrdered[i_ordered])) {
+ if (x_sig.startsWith(fOrdered[i_ordered])
+ || y_sig.startsWith(fOrdered[i_ordered])) {
starts_with_sig= true;
if (x_sig.equals(y_sig)) {
- for (int j_ordered=i_ordered ; j_ordered<fOrdered.length; j_ordered++) {
- if (x_sig.equals(fOrdered[j_ordered]+SIGN_ELEMENT)) {
+ for (int j_ordered= i_ordered;
+ j_ordered < fOrdered.length;
+ j_ordered++) {
+ if (x_sig
+ .equals(
+ fOrdered[j_ordered] + SIGN_ELEMENT)) {
equals_sig= true;
break;
}
@@ -460,11 +507,13 @@
* In this case we do not check x_sig.startsWith(fOrdered[i_ordered]) || y_sig.startsWith(fOrdered[i_ordered])
*/
if (x_sig.equals(y_sig)) {
- for (i_ordered= 0; i_ordered < fOrdered.length; i_ordered++) {
- if (x_sig.equals(fOrdered[i_ordered]+SIGN_ELEMENT)) {
- equals_sig= true;
- break;
- }
+ for (i_ordered= 0;
+ i_ordered < fOrdered.length;
+ i_ordered++) {
+ if (x_sig.equals(fOrdered[i_ordered] + SIGN_ELEMENT)) {
+ equals_sig= true;
+ break;
+ }
}
}
@@ -472,13 +521,11 @@
return orderedMath(x, y);
}
}
-
+
}
/* end of handle ordered entries */
-
return unorderedMatch(x, y, xc_orig, yc_orig);
}
-
-}
+}
diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java
index 26ad0be..b879996 100644
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java
+++ b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureCreator.java
@@ -457,7 +457,7 @@
} // getLocationString(SAXParseException):String
- };
+ }
public XMLStructureCreator() {
//set default idmap
diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java
index 205fb28..f67caca 100644
--- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java
+++ b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java
@@ -57,14 +57,15 @@
public class XMLStructureViewer extends StructureDiffViewer {
private CompareViewerSwitchingPane fParent;
-
+
private HashMap fIdMapsInternal;
private HashMap fIdMaps;
private HashMap fOrderedElementsInternal;
private HashMap fOrderedElements;
- protected static final char SIGN_SEPARATOR= XMLStructureCreator.SIGN_SEPARATOR;
-
+ protected static final char SIGN_SEPARATOR=
+ XMLStructureCreator.SIGN_SEPARATOR;
+
/**
* Creates a new viewer for the given SWT tree control with the specified configuration.
*
@@ -72,7 +73,7 @@
* @param configuration the configuration for this viewer
*/
class XMLSorter extends ViewerSorter {
-
+
ArrayList fOrdered;
boolean fAlwaysOrderSort;
@@ -84,38 +85,52 @@
public void setOrdered(ArrayList ordered) {
fOrdered= ordered;
}
-
+
public void setAlwaysOrderSort(boolean alwaysOrderSort) {
fAlwaysOrderSort= alwaysOrderSort;
}
-
+
public int category(Object node) {
if (node instanceof DiffNode) {
Object o= ((DiffNode) node).getId();
if (o instanceof XMLNode) {
String xmlType= ((XMLNode) o).getXMLType();
- if (xmlType.equals(XMLStructureCreator.TYPE_ATTRIBUTE) ) return 1;
- if (xmlType.equals(XMLStructureCreator.TYPE_ELEMENT) ) return 2;
- if (xmlType.equals(XMLStructureCreator.TYPE_TEXT) ) return 2;
+ if (xmlType.equals(XMLStructureCreator.TYPE_ATTRIBUTE))
+ return 1;
+ if (xmlType.equals(XMLStructureCreator.TYPE_ELEMENT))
+ return 2;
+ if (xmlType.equals(XMLStructureCreator.TYPE_TEXT))
+ return 2;
}
}
return 0;
}
-
+
public void sort(final Viewer viewer, Object[] elements) {
- if ( (fOrdered != null || fAlwaysOrderSort)
- && elements != null && elements.length > 0 && elements[0] instanceof DiffNode) {
+ if ((fOrdered != null || fAlwaysOrderSort)
+ && elements != null
+ && elements.length > 0
+ && elements[0] instanceof DiffNode) {
Object o= ((DiffNode) elements[0]).getId();
if (o instanceof XMLNode) {
XMLNode parent= ((XMLNode) o).getParent();
String sig= parent.getSignature();
if (sig.endsWith(XMLStructureCreator.SIGN_ELEMENT)) {
- String newSig= sig.substring(0, sig.length() - XMLStructureCreator.SIGN_ELEMENT.length());
+ String newSig=
+ sig.substring(
+ 0,
+ sig.length()
+ - XMLStructureCreator.SIGN_ELEMENT.length());
if (fAlwaysOrderSort || fOrdered.contains(newSig)) {
- final ArrayList originalTree= new ArrayList(Arrays.asList(parent.getChildren()));
+ final ArrayList originalTree=
+ new ArrayList(
+ Arrays.asList(parent.getChildren()));
Arrays.sort(elements, new Comparator() {
public int compare(Object a, Object b) {
- return XMLSorter.this.compare((DiffNode) a, (DiffNode) b, originalTree);
+ return XMLSorter.this.compare(
+ (DiffNode) a,
+ (DiffNode) b,
+ originalTree);
}
});
return;
@@ -127,41 +142,43 @@
}
private int compare(DiffNode a, DiffNode b, ArrayList originalTree) {
-
- int index_a= originalTree.indexOf( (XMLNode)a.getId() );
- int index_b= originalTree.indexOf( (XMLNode)b.getId() );
+
+ int index_a= originalTree.indexOf(a.getId());
+ int index_b= originalTree.indexOf(b.getId());
if (index_a < index_b)
return -1;
else
return 1;
- }
- }
+ }
+ }
public XMLStructureViewer(Tree tree, CompareConfiguration configuration) {
super(tree, configuration);
initialize();
}
-
+
/**
* Creates a new viewer under the given SWT parent with the specified configuration.
*
* @param parent the SWT control under which to create the viewer
* @param configuration the configuration for this viewer
*/
- public XMLStructureViewer(Composite parent, CompareConfiguration configuration) {
+ public XMLStructureViewer(
+ Composite parent,
+ CompareConfiguration configuration) {
super(parent, configuration);
if (parent instanceof CompareViewerSwitchingPane) {
fParent= (CompareViewerSwitchingPane) parent;
}
initialize();
}
-
+
private void initialize() {
setStructureCreator(new XMLStructureCreator());
XMLPlugin plugin= XMLPlugin.getDefault();
plugin.getViewers().add(this);
-
+
fIdMaps= plugin.getIdMaps();
fIdMapsInternal= plugin.getIdMapsInternal();
fOrderedElements= plugin.getOrderedElements();
@@ -171,7 +188,7 @@
setSorter(sorter);
}
-
+
protected XMLStructureCreator getXMLStructureCreator() {
return (XMLStructureCreator) getStructureCreator();
}
@@ -180,12 +197,12 @@
* Overridden to unregister all listeners.
*/
protected void handleDispose(DisposeEvent event) {
-
+
XMLPlugin.getDefault().getViewers().remove(this);
-
+
super.handleDispose(event);
}
-
+
/**
* Recreates the comparable structures for the input sides.
*/
@@ -196,7 +213,7 @@
String fileExtension= t.getType();
getXMLStructureCreator().setFileExtension(fileExtension);
}
- }
+ }
getXMLStructureCreator().initIdMaps();
super.compareInputChanged(input);
@@ -204,16 +221,17 @@
if (input != null && fParent.getTitleArgument() == null)
appendToTitle(getXMLStructureCreator().getIdMap());
}
-
+
/**
* Calls <code>diff</code> whenever the byte contents changes.
*/
protected void contentChanged() {
- fIdMaps = XMLPlugin.getDefault().getIdMaps();
+ fIdMaps= XMLPlugin.getDefault().getIdMaps();
fOrderedElements= XMLPlugin.getDefault().getOrderedElements();
getXMLStructureCreator().updateIdMaps();
if (isIdMapRemoved()) {
- getXMLStructureCreator().setIdMap(XMLStructureCreator.DEFAULT_IDMAP);
+ getXMLStructureCreator().setIdMap(
+ XMLStructureCreator.DEFAULT_IDMAP);
}
getXMLStructureCreator().initIdMaps();
@@ -224,10 +242,17 @@
appendToTitle(getXMLStructureCreator().getIdMap());
}
-
- public IRunnableWithProgress getMatchingRunnable(final XMLNode left, final XMLNode right, final XMLNode ancestor) {
+
+ public IRunnableWithProgress getMatchingRunnable(
+ final XMLNode left,
+ final XMLNode right,
+ final XMLNode ancestor) {
return new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, OperationCanceledException {
+ public void run(IProgressMonitor monitor)
+ throws
+ InvocationTargetException,
+ InterruptedException,
+ OperationCanceledException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
@@ -236,55 +261,81 @@
totalWork= 1;
else
totalWork= 3;
- monitor.beginTask(XMLCompareMessages.getString("XMLStructureViewer.matching.beginTask"),totalWork); //$NON-NLS-1$
+ monitor.beginTask(XMLCompareMessages.getString("XMLStructureViewer.matching.beginTask"), totalWork); //$NON-NLS-1$
ArrayList ordered= null;
- if (!getXMLStructureCreator().getIdMap().equals(XMLStructureCreator.USE_UNORDERED)
- && !getXMLStructureCreator().getIdMap().equals(XMLStructureCreator.USE_ORDERED) ) {
- ordered= (ArrayList) fOrderedElements.get(getXMLStructureCreator().getIdMap());
+ if (!getXMLStructureCreator()
+ .getIdMap()
+ .equals(XMLStructureCreator.USE_UNORDERED)
+ && !getXMLStructureCreator().getIdMap().equals(
+ XMLStructureCreator.USE_ORDERED)) {
+ ordered=
+ (ArrayList) fOrderedElements.get(
+ getXMLStructureCreator().getIdMap());
if (ordered == null)
- ordered= (ArrayList) fOrderedElementsInternal.get(getXMLStructureCreator().getIdMap());
+ ordered=
+ (ArrayList) fOrderedElementsInternal.get(
+ getXMLStructureCreator().getIdMap());
}
if (getSorter() instanceof XMLSorter)
- ((XMLSorter)getSorter()).setOrdered(ordered);
+ ((XMLSorter) getSorter()).setOrdered(ordered);
AbstractMatching m;
- if (getXMLStructureCreator().getIdMap().equals(XMLStructureCreator.USE_ORDERED)) {
+ if (getXMLStructureCreator()
+ .getIdMap()
+ .equals(XMLStructureCreator.USE_ORDERED)) {
m= new OrderedMatching();
- if (getSorter() instanceof XMLSorter)
- ((XMLSorter)getSorter()).setAlwaysOrderSort(true);
+ if (getSorter() instanceof XMLSorter)
+ ((XMLSorter) getSorter()).setAlwaysOrderSort(true);
} else {
m= new GeneralMatching(ordered);
if (getSorter() instanceof XMLSorter)
- ((XMLSorter)getSorter()).setAlwaysOrderSort(false);
+ ((XMLSorter) getSorter()).setAlwaysOrderSort(false);
}
try {
- m.match((XMLNode) left, (XMLNode) right, false, monitor);
- if (ancestor != null) {
- m.match((XMLNode) left, (XMLNode) ancestor, true, new SubProgressMonitor(monitor,1));
- m.match((XMLNode) right, (XMLNode) ancestor, true, new SubProgressMonitor(monitor,1));
- }
-// } catch (InterruptedException e) {
-// System.out.println("in run");
-// e.printStackTrace();
+ m.match(left, right, false, monitor);
+ if (ancestor != null) {
+ m.match(
+ left,
+ ancestor,
+ true,
+ new SubProgressMonitor(monitor, 1));
+ m.match(
+ right,
+ ancestor,
+ true,
+ new SubProgressMonitor(monitor, 1));
+ }
+ // } catch (InterruptedException e) {
+ // System.out.println("in run");
+ // e.printStackTrace();
} finally {
- monitor.done();
+ monitor.done();
}
}
};
}
-
-
- protected void preDiffHook(IStructureComparator ancestor, IStructureComparator left, IStructureComparator right) {
+
+ protected void preDiffHook(
+ IStructureComparator ancestor,
+ IStructureComparator left,
+ IStructureComparator right) {
// if (!xsc.getIdMap().equals(XMLStructureCreator.USE_ORDERED)) {
- //TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable);
+ //TimeoutContext.run(true, TIMEOUT, getControl().getShell(), runnable);
if (left != null && right != null) {
try {
- TimeoutContext.run(true, 500, XMLPlugin.getActiveWorkbenchShell(), getMatchingRunnable((XMLNode) left, (XMLNode) right, (XMLNode) ancestor));
+ TimeoutContext.run(
+ true,
+ 500,
+ XMLPlugin.getActiveWorkbenchShell(),
+ getMatchingRunnable(
+ (XMLNode) left,
+ (XMLNode) right,
+ (XMLNode) ancestor));
} catch (Exception e) {
XMLPlugin.log(e);
}
}
}
-
+
/**
* Overriden to create buttons in the viewer's pane control bar.
* <p>
@@ -302,41 +353,66 @@
* <p>
*
* @param manager the menu manager for which to add menu items
- */
+ */
protected void fillContextMenu(IMenuManager manager) {
super.fillContextMenu(manager);
ISelection s= getSelection();
if (s instanceof StructuredSelection
&& ((StructuredSelection) s).getFirstElement() instanceof DiffNode
- && ((DiffNode)((StructuredSelection) s).getFirstElement()).getId() instanceof XMLNode) {
- DiffNode diffnode = (DiffNode) ((StructuredSelection) s).getFirstElement();
- String diffnodeIdSig = ((XMLNode)diffnode.getId()).getSignature();
- fIdMaps = XMLPlugin.getDefault().getIdMaps();
- String idmap_name = getXMLStructureCreator().getIdMap();
- if ( diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ATTRIBUTE) || (diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_TEXT) && ((XMLNode)diffnode.getId()).getOrigId().endsWith("(1)")) ) { //$NON-NLS-1$
- Action action = new SetAsIdAction(diffnode);
+ && ((DiffNode) ((StructuredSelection) s).getFirstElement()).getId()
+ instanceof XMLNode) {
+ DiffNode diffnode=
+ (DiffNode) ((StructuredSelection) s).getFirstElement();
+ String diffnodeIdSig= ((XMLNode) diffnode.getId()).getSignature();
+ fIdMaps= XMLPlugin.getDefault().getIdMaps();
+ String idmap_name= getXMLStructureCreator().getIdMap();
+ if (diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ATTRIBUTE) || (diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_TEXT) && ((XMLNode) diffnode.getId()).getOrigId().endsWith("(1)"))) { //$NON-NLS-1$
+ Action action= new SetAsIdAction(diffnode);
if (!fIdMaps.containsKey(idmap_name)) {
action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.notUserIdMap")); //$NON-NLS-1$
action.setEnabled(false);
- }
- else {
- HashMap idmapHM = (HashMap)fIdMaps.get(idmap_name);
- XMLNode idNode = (XMLNode) diffnode.getId();
- String signature = idNode.getSignature();
- String idname = ""; //$NON-NLS-1$
- if ( idNode.getSignature().endsWith(XMLStructureCreator.SIGN_ATTRIBUTE) ) {
- signature = signature.substring(0,signature.indexOf(XMLStructureCreator.SIGN_ATTRIBUTE));
- int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR,signature.length()-2);
- idname = signature.substring(end_of_signature+1,signature.length()-1);
- signature = signature.substring(0,end_of_signature+1);
- } else if ( idNode.getSignature().endsWith(XMLStructureCreator.SIGN_TEXT) ) {
- XMLNode textNode = (XMLNode) diffnode.getId();
- XMLNode idelem = textNode.getParent();
- XMLNode elem = idelem.getParent();
- signature = elem.getSignature().substring(0,elem.getSignature().indexOf(XMLStructureCreator.SIGN_ELEMENT));
+ } else {
+ HashMap idmapHM= (HashMap) fIdMaps.get(idmap_name);
+ XMLNode idNode= (XMLNode) diffnode.getId();
+ String signature= idNode.getSignature();
+ String idname= ""; //$NON-NLS-1$
+ if (idNode
+ .getSignature()
+ .endsWith(XMLStructureCreator.SIGN_ATTRIBUTE)) {
+ signature=
+ signature.substring(
+ 0,
+ signature.indexOf(
+ XMLStructureCreator.SIGN_ATTRIBUTE));
+ int end_of_signature=
+ signature.lastIndexOf(
+ SIGN_SEPARATOR,
+ signature.length() - 2);
+ idname=
+ signature.substring(
+ end_of_signature + 1,
+ signature.length() - 1);
+ signature= signature.substring(0, end_of_signature + 1);
+ } else if (
+ idNode.getSignature().endsWith(
+ XMLStructureCreator.SIGN_TEXT)) {
+ XMLNode textNode= (XMLNode) diffnode.getId();
+ XMLNode idelem= textNode.getParent();
+ XMLNode elem= idelem.getParent();
+ signature=
+ elem.getSignature().substring(
+ 0,
+ elem.getSignature().indexOf(
+ XMLStructureCreator.SIGN_ELEMENT));
idname= idelem.getOrigId();
- idname= idname.substring(0,idname.indexOf(XMLStructureCreator.ID_SEPARATOR));
- idname= new Character(XMLStructureCreator.ID_TYPE_BODY) + idname;
+ idname=
+ idname.substring(
+ 0,
+ idname.indexOf(
+ XMLStructureCreator.ID_SEPARATOR));
+ idname=
+ new Character(XMLStructureCreator.ID_TYPE_BODY)
+ + idname;
}
if (idmapHM.containsKey(signature)) {
if (idmapHM.get(signature).equals(idname)) {
@@ -344,9 +420,13 @@
action.setEnabled(false);
} else {
String oldId= (String) idmapHM.get(signature);
- if (oldId.startsWith((new Character(XMLStructureCreator.ID_TYPE_BODY)).toString()))
+ if (oldId
+ .startsWith(
+ (new Character(XMLStructureCreator
+ .ID_TYPE_BODY))
+ .toString()))
oldId= oldId.substring(1);
- action.setText(MessageFormat.format("{0} {1}",new String[] {XMLCompareMessages.getString("XMLStructureViewer.action.setId.text2"),oldId})); //$NON-NLS-2$ //$NON-NLS-1$
+ action.setText(MessageFormat.format("{0} {1}", new String[] { XMLCompareMessages.getString("XMLStructureViewer.action.setId.text2"), oldId })); //$NON-NLS-2$ //$NON-NLS-1$
action.setEnabled(true);
}
} else {
@@ -355,19 +435,25 @@
}
}
manager.add(action);
- } else if ( diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ELEMENT) ) {
- SetOrderedAction action = new SetOrderedAction(idmap_name);
+ } else if (
+ diffnodeIdSig.endsWith(XMLStructureCreator.SIGN_ELEMENT)) {
+ SetOrderedAction action= new SetOrderedAction(idmap_name);
if (!fIdMaps.containsKey(idmap_name)) {
action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.notUserIdMap")); //$NON-NLS-1$
action.setEnabled(false);
- }
- else {
- ArrayList idmapOrdered= (ArrayList) fOrderedElements.get(idmap_name);
+ } else {
+ ArrayList idmapOrdered=
+ (ArrayList) fOrderedElements.get(idmap_name);
XMLNode idNode= (XMLNode) diffnode.getId();
String signature= idNode.getSignature();
-// String idname= "";
- signature = signature.substring(0,signature.indexOf(XMLStructureCreator.SIGN_ELEMENT));
- if (idmapOrdered != null && idmapOrdered.contains(signature)) {
+ // String idname= "";
+ signature=
+ signature.substring(
+ 0,
+ signature.indexOf(
+ XMLStructureCreator.SIGN_ELEMENT));
+ if (idmapOrdered != null
+ && idmapOrdered.contains(signature)) {
action.setText(XMLCompareMessages.getString("XMLStructureViewer.action.setOrdered.exists")); //$NON-NLS-1$
action.setEnabled(false);
} else {
@@ -381,13 +467,13 @@
}
}
}
-
+
protected void appendToTitle(String idmap_name) {
if (fParent != null) {
getXMLStructureCreator().setIdMap(idmap_name);
fParent.setTitleArgument(idmap_name);
}
- }
+ }
/**
* Returns true if the current Id Map scheme has been removed.
@@ -396,66 +482,97 @@
XMLStructureCreator xsc= getXMLStructureCreator();
String IdMapName= xsc.getIdMap();
return !IdMapName.equals(XMLStructureCreator.USE_UNORDERED)
- && !IdMapName.equals(XMLStructureCreator.USE_ORDERED)
- && !fIdMaps.containsKey(IdMapName)
- && !fIdMapsInternal.containsKey(IdMapName)
- && !fOrderedElements.containsKey(IdMapName);
+ && !IdMapName.equals(XMLStructureCreator.USE_ORDERED)
+ && !fIdMaps.containsKey(IdMapName)
+ && !fIdMapsInternal.containsKey(IdMapName)
+ && !fOrderedElements.containsKey(IdMapName);
}
-
+
protected class SetAsIdAction extends Action {
-
+
DiffNode fDiffNode;
-
+
public SetAsIdAction(DiffNode diffnode) {
fDiffNode= diffnode;
}
-
+
public void run() {
- XMLStructureCreator sc = getXMLStructureCreator();
-// DiffNode diffnode = (DiffNode) ((StructuredSelection) getSelection()).getFirstElement();
- String idmap_name = sc.getIdMap();
+ XMLStructureCreator sc= getXMLStructureCreator();
+ // DiffNode diffnode = (DiffNode) ((StructuredSelection) getSelection()).getFirstElement();
+ String idmap_name= sc.getIdMap();
if (fIdMaps.containsKey(idmap_name)) {
- HashMap idmapHM = (HashMap)fIdMaps.get(idmap_name);
- if ( ((XMLNode)fDiffNode.getId()).getSignature().endsWith(XMLStructureCreator.SIGN_ATTRIBUTE) ) {
- XMLNode attrNode = (XMLNode) fDiffNode.getId();
- String signature = attrNode.getSignature();
- signature = signature.substring(0,signature.indexOf(XMLStructureCreator.SIGN_ATTRIBUTE));
- int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR,signature.length()-2);
- String idattr = signature.substring(end_of_signature+1,signature.length()-1);
- signature = signature.substring(0,end_of_signature+1);
- idmapHM.put(signature,idattr);
- XMLPlugin.getDefault().setIdMaps(fIdMaps,null,null,false);
+ HashMap idmapHM= (HashMap) fIdMaps.get(idmap_name);
+ if (((XMLNode) fDiffNode.getId())
+ .getSignature()
+ .endsWith(XMLStructureCreator.SIGN_ATTRIBUTE)) {
+ XMLNode attrNode= (XMLNode) fDiffNode.getId();
+ String signature= attrNode.getSignature();
+ signature=
+ signature.substring(
+ 0,
+ signature.indexOf(
+ XMLStructureCreator.SIGN_ATTRIBUTE));
+ int end_of_signature=
+ signature.lastIndexOf(
+ SIGN_SEPARATOR,
+ signature.length() - 2);
+ String idattr=
+ signature.substring(
+ end_of_signature + 1,
+ signature.length() - 1);
+ signature= signature.substring(0, end_of_signature + 1);
+ idmapHM.put(signature, idattr);
+ XMLPlugin.getDefault().setIdMaps(
+ fIdMaps,
+ null,
+ null,
+ false);
//contentChanged();
- } else if ( ((XMLNode)fDiffNode.getId()).getSignature().endsWith(XMLStructureCreator.SIGN_TEXT) ) {
- XMLNode textNode = (XMLNode) fDiffNode.getId();
- XMLNode idelem = textNode.getParent();
- XMLNode elem = idelem.getParent();
- String signature = elem.getSignature().substring(0,elem.getSignature().indexOf(XMLStructureCreator.SIGN_ELEMENT));
+ } else if (
+ ((XMLNode) fDiffNode.getId()).getSignature().endsWith(
+ XMLStructureCreator.SIGN_TEXT)) {
+ XMLNode textNode= (XMLNode) fDiffNode.getId();
+ XMLNode idelem= textNode.getParent();
+ XMLNode elem= idelem.getParent();
+ String signature=
+ elem.getSignature().substring(
+ 0,
+ elem.getSignature().indexOf(
+ XMLStructureCreator.SIGN_ELEMENT));
String idname= idelem.getOrigId();
- idname= idname.substring(0,idname.indexOf(XMLStructureCreator.ID_SEPARATOR));
- idname= new Character(XMLStructureCreator.ID_TYPE_BODY) + idname;
- idmapHM.put(signature,idname);
- XMLPlugin.getDefault().setIdMaps(fIdMaps,null,null,false);
+ idname=
+ idname.substring(
+ 0,
+ idname.indexOf(XMLStructureCreator.ID_SEPARATOR));
+ idname=
+ new Character(XMLStructureCreator.ID_TYPE_BODY)
+ + idname;
+ idmapHM.put(signature, idname);
+ XMLPlugin.getDefault().setIdMaps(
+ fIdMaps,
+ null,
+ null,
+ false);
//contentChanged();
}
}
}
}
-
+
protected class SetOrderedAction extends Action {
String fIdMapName;
String fSignature;
-
-
+
public SetOrderedAction(String idmap_name) {
fIdMapName= idmap_name;
}
-
+
public void run() {
//String idmap_name= getXMLStructureCreator().getIdMap();
if (fSignature != null) {
- ArrayList idmapOrdered= (ArrayList) fOrderedElements.get(fIdMapName);
+ ArrayList idmapOrdered=
+ (ArrayList) fOrderedElements.get(fIdMapName);
if (idmapOrdered == null) {
idmapOrdered= new ArrayList();
fOrderedElements.put(fIdMapName, idmapOrdered);
@@ -463,16 +580,16 @@
idmapOrdered.add(fSignature);
}
}
-
+
public void setSignature(String signature) {
fSignature= signature;
}
}
-
+
protected void updateIdMaps() {
getXMLStructureCreator().updateIdMaps();
}
-
+
/**
* Tracks property changes of the configuration object.
* Clients may override to track their own property changes.
@@ -481,11 +598,11 @@
protected void propertyChange(PropertyChangeEvent event) {
String key= event.getProperty();
if (key.equals(CompareConfiguration.IGNORE_WHITESPACE)) {
- getXMLStructureCreator().setRemoveWhiteSpace(!getXMLStructureCreator().getRemoveWhiteSpace());
+ getXMLStructureCreator().setRemoveWhiteSpace(
+ !getXMLStructureCreator().getRemoveWhiteSpace());
contentChanged();
}
-// else
-// super.propertyChange(event);
+ // else
+ // super.propertyChange(event);
}
}
-
diff --git a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestMinCostBipartiteMatching.java b/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestMinCostBipartiteMatching.java
index 6ee2e47..e3254ef 100644
--- a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestMinCostBipartiteMatching.java
+++ b/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestMinCostBipartiteMatching.java
@@ -52,7 +52,6 @@
0, 8, 4, 7, 4, 8, 0 }
};
fC= new int[6];
- ;
fT2= 15;
//optimal matching: {(1,3), (2,5), (3,1), (4,4), (5,2)}