diff options
author | Andre Weinand | 2004-03-23 11:52:09 +0000 |
---|---|---|
committer | Andre Weinand | 2004-03-23 11:52:09 +0000 |
commit | 9de372230805b96b224796016867adcf3ccdb920 (patch) | |
tree | cf1b43cada09d86d22ebd901dd4c1b2277fd5ffe | |
parent | a0bbffde4cc5fc27897214920f5cbcb55f78e113 (diff) | |
download | eclipse.platform.team-9de372230805b96b224796016867adcf3ccdb920.tar.gz eclipse.platform.team-9de372230805b96b224796016867adcf3ccdb920.tar.xz eclipse.platform.team-9de372230805b96b224796016867adcf3ccdb920.zip |
removed dead codev20040323
6 files changed, 18 insertions, 3761 deletions
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 deleted file mode 100644 index 43d7bb1c6..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/GeneralMatching.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.examples.xml; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.core.runtime.IProgressMonitor; - -/** This class is used to find a mapping between the nodes of two xml parse trees - * When an identifier for a specific node is known, it will be used. - * Otherwise a min-cost bipartite matching must be solved. - * This algorithm uses the algorithm described in the paper - * "X-Diff: A Fast Change Detection Algorithm for XML Documents" - */ -public class GeneralMatching extends AbstractMatching { - - HungarianMethod fH; - - boolean fUseOrdered; - String[] fOrdered; - boolean fIgnoreStartsWith; - - public GeneralMatching() { - fOrdered= null; - fUseOrdered= false; - fIgnoreStartsWith= false; - } - - public GeneralMatching(ArrayList ordered) { - if (ordered != null && !ordered.isEmpty()) { - fUseOrdered= true; - fOrdered= new String[ordered.size()]; - int i= 0; - for (Iterator iter= ordered.iterator(); iter.hasNext(); i++) { - fOrdered[i]= (String) iter.next(); - } - } else { - fUseOrdered= false; - fOrdered= null; - } - //fOrderedElements= XMLPlugin.getDefault().getOrderedElements(); - } - - //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()) { - 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) { - /* 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. - */ - //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])); - } - } 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()) - 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) { - 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(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) - 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; - } - /* 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; - } - A[i][array_colsize - 1]= 0; - } - /* now A = 0, 0, 0, ... 0,0 - * 0,-1,-1, ... -1,0 - * 0,-1,-1, ... -1,0 - * ... - * 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])]; - } - } - 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]; - } - } 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]; - } - } 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; - } - } - } 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; - } - } - } - - //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]; - } - fH.solve(A2, Matching); - //now Matching contains the min-cost matching of A - - 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]); - //added here - DTMatching.add(new Match(xc[Matching[m] - 1], null)); - } else if (xc.length < yc.length) { - distance += countNodes(yc[m - 1]); - //added here - 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])); - } - } - } - } - 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(); - - 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)) { - xc_attrsAL.add(x_i); - } - } - - //do the same for yc - for (int i= 0; i < yc.length; 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)) { - 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 - - //perform unordered matching on attributes - //this updates fDT and fDT_Matchings - if (xc_attrs.length > 0 || yc_attrs.length > 0) { - if (xc_attrs.length == 0) - distance += yc_attrs.length; - else if (yc_attrs.length == 0) - distance += xc_attrs.length; - else { - unorderedMatch(x, y, xc_attrs, yc_attrs); - distance += fDT[indexOfLN(x)][indexOfRN(y)]; - DTMatching= fDT_Matchings[indexOfLN(x)][indexOfRN(y)]; - } - } - 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); - /* 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]); - // } - // } - /* end: Naive ordered compare */ - - fIgnoreStartsWith= old_isw; - - 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 { - - //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 - 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; - } - } - - 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()); - if (monitor != null && monitor.isCanceled()) { - // throw new OperationCanceledException(); - throw new InterruptedException(); - // 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); - } - } - } - 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())) - NRight_new.add(node.getParent()); - } - 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())) { - //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)]); - } - } - } - //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(); - 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(); - 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$ - } - } - //if (monitor != null) monitor.done(); - } - - protected int handleXandYnotLeaves(XMLNode x, XMLNode y) { - int ret= NO_ENTRY; - Object[] xc_orig= x.getChildren(); - Object[] yc_orig= y.getChildren(); - - /* handle ordered entries */ - if (fUseOrdered) { - boolean starts_with_sig= false; - 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. - * check x_sig.startsWith(fOrdered[i_ordered]) || y_sig.startsWith(fOrdered[i_ordered]) - * because if this is the case and - * !(x_sig.equals(fOrdered[j_ordered]+SIGN_ELEMENT) && y_sig.equals(fOrdered[j_ordered]+SIGN_ELEMENT)) - * i.e. the nodes are not marked for an ordered compare but x and/or y has an ancestor that is, - * then nodes x and/or y will be handled by that ancestor in orderedMatch(), which is a top-down algorithm. - * 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])) { - 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)) { - equals_sig= true; - break; - } - break; - } - } - } - } - - if (starts_with_sig) { - if (equals_sig) { - return orderedMath(x, y); - } else { - return ret; - } - } - - } else { - /* when inside orderedMatch(x, y), algorithm runs recursively from a node to the leaves of the - * subtree rooted at this node. - * 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; - } - } - } - - if (equals_sig) { - 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/HungarianMethod.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/HungarianMethod.java deleted file mode 100644 index c464d82a6..000000000 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/HungarianMethod.java +++ /dev/null @@ -1,479 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.examples.xml; - -/** This algorithm solves the assignment problem. - * It was translated from Fortran to Java. - * The original algorithm was taken from http://www.netlib.no/netlib/toms/548 - */ -public class HungarianMethod { - - public int solve(int[][] A, int[] C) { - - final int N = A.length-1; - final int NP1 = A[0].length-1; - int[] CH = new int[A.length]; - int[] LC = new int[A.length]; - int[] LR = new int[A.length]; - int[] LZ = new int[A.length]; - int[] NZ = new int[A.length]; - int[] RH = new int[A[0].length]; - int[] SLC = new int[A.length]; - int[] SLR = new int[A.length]; - int[] U = new int[A[0].length]; - int H, Q, R, S, T; - boolean while100goto120 = false; - -// SUBROUTINE ASSCT ( N, A, C, T ) 10 -// INTEGER A(130,131), C(130), CH(130), LC(130), LR(130), -// * LZ(130), NZ(130), RH(131), SLC(130), SLR(130), -// * U(131) -// INTEGER H, Q, R, S, T -// EQUIVALENCE (LZ,RH), (NZ,CH) -// C -// C THIS SUBROUTINE SOLVES THE SQUARE ASSIGNMENT PROBLEM -// C THE MEANING OF THE INPUT PARAMETERS IS -// C N = NUMBER OF ROWS AND COLUMNS OF THE COST MATRIX, WITH -// C THE CURRENT DIMENSIONS THE MAXIMUM VALUE OF N IS 130 -// C A(I,J) = ELEMENT IN ROW I AND COLUMN J OF THE COST MATRIX -// C ( AT THE END OF COMPUTATION THE ELEMENTS OF A ARE CHANGED) -// C THE MEANING OF THE OUTPUT PARAMETERS IS -// C C(J) = ROW ASSIGNED TO COLUMN J (J=1,N) -// C T = COST OF THE OPTIMAL ASSIGNMENT -// C ALL PARAMETERS ARE INTEGER -// C THE MEANING OF THE LOCAL VARIABLES IS -// C A(I,J) = ELEMENT OF THE COST MATRIX IF A(I,J) IS POSITIVE, -// C COLUMN OF THE UNASSIGNED ZERO FOLLOWING IN ROW I -// C (I=1,N) THE UNASSIGNED ZERO OF COLUMN J (J=1,N) -// C IF A(I,J) IS NOT POSITIVE -// C A(I,N+1) = COLUMN OF THE FIRST UNASSIGNED ZERO OF ROW I -// C (I=1,N) -// C CH(I) = COLUMN OF THE NEXT UNEXPLORED AND UNASSIGNED ZERO -// C OF ROW I (I=1,N) -// C LC(J) = LABEL OF COLUMN J (J=1,N) -// C LR(I) = LABEL OF ROW I (I=1,N) -// C LZ(I) = COLUMN OF THE LAST UNASSIGNED ZERO OF ROW I(I=1,N) -// C NZ(I) = COLUMN OF THE NEXT UNASSIGNED ZERO OF ROW I(I=1,N) -// C RH(I) = UNEXPLORED ROW FOLLOWING THE UNEXPLORED ROW I -// C (I=1,N) -// C RH(N+1) = FIRST UNEXPLORED ROW -// C SLC(K) = K-TH ELEMENT CONTAINED IN THE SET OF THE LABELLED -// C COLUMNS -// C SLR(K) = K-TH ELEMENT CONTAINED IN THE SET OF THE LABELLED -// C ROWS -// C U(I) = UNASSIGNED ROW FOLLOWING THE UNASSIGNED ROW I -// C (I=1,N) -// C U(N+1) = FIRST UNASSIGNED ROW -// C -// C THE VECTORS C,CH,LC,LR,LZ,NZ,SLC,SLR MUST BE DIMENSIONED -// C AT LEAST AT (N), THE VECTORS RH,U AT LEAST AT (N+1), -// C THE MATRIX A AT LEAST AT (N,N+1) -// C -// C INITIALIZATION - - int KSLC = -1; - int L = -1; - int I = -1; - int M = -1; - int J = -1; - int K = -1; - int LJ = -1; - int LM = -1; - int KSLR = -1; - int NL = -1; - int NM = -1; - - //N = N-1; - //NP1 = NP1-1; - // NP1 = N+1 - - for (J=1; J<=N; J++) { - // DO 10 J=1,N - C[J] = 0; - LZ[J] = 0; - NZ[J] = 0; - U[J] = 0; - }//for (int J=0; J<N; J++) - //10 CONTINUE - U[NP1] = 0; - T = 0; - //C REDUCTION OF THE INITIAL COST MATRIX - - for (J=1; J<=N; J++) { - // DO 40 J=1,N - S = A[1][J]; - for (L=2; L<=N; L++) { - //DO 20 L=2,N - if (A[L][J] < S) S = A[L][J]; - //IF ( A(L,J) .LT. S ) S = A(L,J) - }//for (int L=1; L<N; L++) - //20 CONTINUE - T = T+S; - for (I=1; I<=N; I++) { - //DO 30 I=1,N - A[I][J] = A[I][J]-S; - }//for (int I=0; I<N; I++) - //30 CONTINUE - - }//for (int J=0; J<N; J++) - // 40 CONTINUE - for (I=1; I<=N; I++) { - //DO 70 I=1,N - Q = A[I][1]; - for (L=2; L<=N; L++) { - //DO 50 L=2,N - //System.out.println("I="+I+" L="+L); - if (A[I][L] < Q) Q = A[I][L]; - //IF ( A(I,L) .LT. Q ) Q = A(I,L) - }//for (int L=1; L<N; L++) - //50 CONTINUE - T = T+Q; - L = NP1; - for (J=1; J<=N; J++) { - //DO 60 J=1,N - A[I][J] = A[I][J]-Q; - if (A[I][J] != 0) continue; - //IF ( A[I,J] .NE. 0 ) GO TO 60 - A[I][L] = -J; - L = J; - }//for (int J=0; J<N; J++) - //60 CONTINUE - }//for (int I=0; I<N; N++) - //70 CONTINUE - //C CHOICE OF THE INITIAL SOLUTION - - - K = NP1; - for140: - for (I=1; I<=N; I++) { - // DO 140 I=1,N - LJ = NP1; - J = -A[I][NP1]; - - do { - if (C[J] == 0) { - // 80 IF ( C(J) .EQ. 0 ) { GO TO 130 - - C[J] = I; - A[I][LJ] = A[I][J]; - NZ[I] = -A[I][J]; - LZ[I] = LJ; - A[I][J] = 0; - continue for140; //break?? - } - - LJ = J; - J = -A[I][J]; - - } while (J != 0); - // IF ( J .NE. 0 ) GO TO 80 - LJ = NP1; - J = -A[I][NP1]; - - do90: - do { - R = C[J]; - LM = LZ[R]; - M = NZ[R]; - - while100goto120 = false; - while100: - while (true) { - if (M == 0) break while100; - // 100 IF ( M .EQ. 0 ) GO TO 110 - if (C[M] == 0){ - while100goto120 = true; - break do90; - } - // IF ( C(M) .EQ. 0 ) GO TO 120// M != 0 && C[m] == 0 - LM = M; - M = -A[R][M]; - } - // GO TO 100 - - //110 - LJ = J; - J = -A[I][J]; - } while (J != 0); - // IF ( J .NE. 0 ) GO TO 90 - - if ( !while100goto120 ) { - U[K] = I; - K = I; - continue for140; - // GO TO 140 - } - // 120 - while100goto120 = false; - NZ[R] = -A[R][M]; - LZ[R] = J; - A[R][LM] = -J; - A[R][J] = A[R][M]; - A[R][M] = 0; - C[M] = R; - - //130 - C[J] = I; - A[I][LJ] = A[I][J]; - NZ[I] = -A[I][J]; - LZ[I] = LJ; - A[I][J] = 0; - - - // 140 CONTINUE - } - //C RESEARCH OF A NEW ASSIGNMENT - while392: - while (true) { - if (U[NP1] == 0) return T; - // 150 IF ( U(NP1) .EQ. 0 ) RETURN - - for (I=1; I<=N; I++) { - // DO 160 I=1,N - CH[I] = 0; - LC[I] = 0; - LR[I] = 0; - RH[I] = 0; - } - // 160 CONTINUE - RH[NP1] = -1; - KSLC = 0; - KSLR = 1; - R = U[NP1]; - //System.out.println("R: "+R); - LR[R] = -1; - SLR[1] = R; - - boolean goto190 = false; - while360: - while(true) { - do350: - do { - //System.out.println("R: "+R+" NP1: "+NP1); - if (goto190 || A[R][NP1] != 0) { - // IF ( A(R,NP1) .EQ. 0 ) GO TO 220 - - - do200: - do { - if (!goto190) { - // 170 - L = -A[R][NP1]; - - if (A[R][L] != 0) { - // IF ( A(R,L) .EQ. 0 ) GO TO 180 - if (RH[R] == 0) { - // IF ( RH(R) .NE. 0 ) GO TO 180 - RH[R] = RH[NP1]; - CH[R] = -A[R][L]; - RH[NP1] = R; - } - } - }// if (!goto190) - //boolean goto210 = false; - while190: - while (true) { - if (!goto190) { - if (LC[L] ==0) break while190; - //180 IF ( LC(L) .EQ. 0 ) GO TO 200 - - if (RH[R] == 0) { - break do200; - // goto210 = true; - //break; - } - // IF ( RH(R) .EQ. 0 ) GO TO 210 - }// if (!goto190) - goto190 = false; - // 190 - L = CH[R]; - CH[R] = -A[R][L]; - if (A[R][L] != 0) continue while190; - //IF ( A(R,L) .NE. 0 ) GO TO 180 - RH[NP1] = RH[R]; - RH[R] = 0; - - //GO TO 180 - - }//end while190 - - //if (!goto210) { - //200 - LC[L] = R; - - if (C[L] == 0) break while360; - //IF ( C(L) .EQ. 0 ) GO TO 360 - - KSLC = KSLC+1; - SLC[KSLC] = L; - R = C[L]; - LR[R] = L; - KSLR = KSLR+1; - SLR[KSLR] = R; - //} - } while (A[R][NP1] != 0); //do200 - // IF ( A(R,NP1) .NE. 0 ) GO TO 170 - //}// if (!goto210) - // goto210 = false; - // 210 CONTINUE - - if (RH[NP1] > 0) break do350; - //IF ( RH(NP1) .GT. 0 ) GO TO 350 - - }// if (A[R,L] != 0) - //C REDUCTION OF THE CURRENT COST MATRIX - // 220 - H = Integer.MAX_VALUE; - - for240: - for (J=1; J<=N; J++) { - // DO 240 J=1,N - - if (LC[J] != 0) continue for240; - // IF ( LC(J) .NE. 0 ) GO TO 240 - - for (K=1; K<=KSLR; K++) { - // DO 230 K=1,KSLR - I = SLR[K]; - if (A[I][J] < H) H = A[I][J]; - // IF ( A(I,J) .LT. H ) H = A(I,J) - }// for (int K=0; K<KSLR; K++) - // 230 CONTINUE - - }// for (int J; J<N; J++) - // 240 CONTINUE - - T = T+H; - - for290: - for (J=1; J<=N; J++) { - // DO 290 J=1,N - - if (LC[J] != 0 ) continue for290; - // IF ( LC(J) .NE. 0 ) GO TO 290 - - for280: - for (K=1; K<=KSLR; K++) { - // DO 280 K=1,KSLR - I = SLR[K]; - A[I][J] = A[I][J]-H; - if (A[I][J] != 0) continue for280; - // IF ( A(I,J) .NE. 0 ) GO TO 280 - - if (RH[I] == 0) { - // IF ( RH(I) .NE. 0 ) GO TO 250 - RH[I] = RH[NP1]; - CH[I] = J; - RH[NP1] = I; - }// if (RH[I] == 0) - //250 - L = NP1; - //260 - while (true) { - NL = -A[I][L]; - if (NL == 0) break; - // IF ( NL .EQ. 0 ) GO TO 270 - L = NL; - }// while (true) - // GO TO 260 - //270 - A[I][L] = -J; - - }// for (int K=0; K<KSLR; K++) - // 280 CONTINUE - - }// for (int J=0; J<N; J++) - // 290 CONTINUE - - if (KSLC != 0) { - //IF ( KSLC .EQ. 0 ) GO TO 350 - - for340: - for (I=1; I<=N; I++) { - // DO 340 I=1,N - - if (LR[I] != 0) continue for340; - //IF ( LR(I) .NE. 0 ) GO TO 340 - - for330: - for (K=1; K<=KSLC; K++) { - //DO 330 K=1,KSLC - J = SLC[K]; - - boolean enter_if = false; - if (A[I][J] <= 0) { - //IF ( A(I,J) .GT. 0 ) GO TO 320 - L = NP1; - //300 - while (true) { - NL = - A[I][L]; - if (NL == J) break; - //IF ( NL .EQ. J ) GO TO 310 - L = NL; - }//while (true) - //GO TO 300 - //310 - A[I][L] = A[I][J]; - A[I][J] = H; - //GO TO 330 - enter_if = true; - }//if (A[I,J] <=0) - if (!enter_if) { - //320 - A[I][J] = A[I][J]+H; - } - }//for (int K=0; K<KSLC; K++) - // 330 CONTINUE - }//for (int I=0; I<N; I++) - // 340 CONTINUE - }// if (KSLC != 0) - - } while (false);//do350 - //350 - R = RH[NP1]; - //System.out.println("R: "+R+" at 350"); - goto190 = true; - }//while360 - // GO TO 190 - //C ASSIGNMENT OF A NEW ROW - while389: - while (true) { - //360 - C[L] = R; - M = NP1; - //370 - while (true) { - NM = -A[R][M]; - if (NM == L) break; - // IF ( NM .EQ. L ) GO TO 380 - M = NM; - }//while (true) - // GO TO 370 - //380 - A[R][M] = A[R][L]; - A[R][L] = 0; - if (LR[R] < 0) break while389; - // IF ( LR(R) .LT. 0 ) GO TO 390 - L = LR[R]; - A[R][L] = A[R][NP1]; - A[R][NP1] = -L; - R = LC[L]; - }//while389 - // GO TO 360 - //390 - U[NP1] = U[R]; - U[R] = 0; - } - // GO TO 150 - //END - } - -} 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 938a520df..6372ddbdf 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 @@ -278,35 +278,33 @@ public class XMLStructureViewer extends StructureDiffViewer { } if (getSorter() instanceof XMLSorter) ((XMLSorter) getSorter()).setOrdered(ordered); - AbstractMatching m; + AbstractMatching m= null; if (getXMLStructureCreator() .getIdMap() .equals(XMLStructureCreator.USE_ORDERED)) { m= new OrderedMatching(); if (getSorter() instanceof XMLSorter) ((XMLSorter) getSorter()).setAlwaysOrderSort(true); - } else { - m= new GeneralMatching(ordered); - if (getSorter() instanceof XMLSorter) - ((XMLSorter) getSorter()).setAlwaysOrderSort(false); } try { - 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)); + if (m != null) { + 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(); } - // } catch (InterruptedException e) { - // System.out.println("in run"); - // e.printStackTrace(); } finally { monitor.done(); } diff --git a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/AllXMLCompareTests.java b/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/AllXMLCompareTests.java index de9066dd3..e97c067f2 100644 --- a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/AllXMLCompareTests.java +++ b/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/AllXMLCompareTests.java @@ -23,8 +23,6 @@ public class AllXMLCompareTests { public static Test suite ( ) { TestSuite suite= new TestSuite("All XML Compare Tests"); //$NON-NLS-1$ - suite.addTest(TestMinCostBipartiteMatching.suite()); - suite.addTest(TestGeneralMatching.suite()); suite.addTest(TestXMLStructureCreator.suite()); return suite; } diff --git a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestGeneralMatching.java b/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestGeneralMatching.java deleted file mode 100644 index 36c37029c..000000000 --- a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestGeneralMatching.java +++ /dev/null @@ -1,2378 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.examples.xml; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.ListIterator; -import java.util.Vector; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.compare.examples.xml.GeneralMatching; -import org.eclipse.compare.examples.xml.XMLChildren; -import org.eclipse.compare.examples.xml.AbstractMatching.Match; -import org.eclipse.jface.text.Document; - -/** - * Runs General Matching algorithm in GeneralMatching.java, which uses a distance table - * which is filled using the min cost bipartite matching algorithm - */ -public class TestGeneralMatching extends TestCase { - - GeneralMatching fGM; - Document fdoc; - - class Pair { - int fx; - int fy; - - Pair(int x, int y) { - fx= x; - fy= y; - } - - public boolean equals(Object obj) { - if (obj instanceof Pair) { - Pair p= (Pair) obj; - return fx == p.fx && fy == p.fy; - } - return false; - } - - public String toString() { - return "(" + fx + "," + fy + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - } - - public TestGeneralMatching(String name) { - super(name); - } - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - //TestRunner.run(suite()); - } - - protected void setUp() { - System.out.println("TestGeneralMatching.name()==" + getName()); //$NON-NLS-1$ - fGM= new GeneralMatching(); - fdoc= new Document(); - } - - protected void tearDown() throws Exception { - //remove set-up - } - - public static Test suite() { - return new TestSuite(TestGeneralMatching.class); - } - - //General case without ids - public void test0() { - XMLChildren LeftTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - XMLChildren RightTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - //create Left Tree - XMLChildren parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(1)); - LeftTree.addChild(parent); - parent.setParent(LeftTree); - XMLChildren current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(2)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(3)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b1" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(4)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(5)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[3]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(6)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(7)); - parent.addChild(current); - current.setParent(parent); - parent= current; - XMLNode attr= - new XMLNode( - XMLStructureCreator.TYPE_ATTRIBUTE, - "attr", //$NON-NLS-1$ - "hello", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "attr" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - attr.setName(Integer.toString(8)); - parent.addChild(attr); - attr.setParent(parent); - - //create Right Tree - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(1)); - RightTree.addChild(parent); - parent.setParent(RightTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(2)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(3)); - parent.addChild(current); - current.setParent(parent); - parent= current; - attr= - new XMLNode( - XMLStructureCreator.TYPE_ATTRIBUTE, - "attr", //$NON-NLS-1$ - "hello", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "attr" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - attr.setName(Integer.toString(4)); - parent.addChild(attr); - attr.setParent(parent); - parent= (XMLChildren) parent.getParent().getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(5)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[3]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(6)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(7)); - parent.addChild(current); - current.setParent(parent); - - //run matching algorithm - try { - fGM.match(LeftTree, RightTree, false, null); - } catch (InterruptedException e) { - } - Vector expected= new Vector(8); - expected.add(new Pair(0, 0)); - expected.add(new Pair(1, 1)); - expected.add(new Pair(6, 2)); - expected.add(new Pair(5, 5)); - expected.add(new Pair(2, 6)); - expected.add(new Pair(4, -1)); - expected.add(new Pair(7, 3)); - expected.add(new Pair(3, 7)); - expected.add(new Pair(8, 4)); - Vector Matches= fGM.getMatches(); - Vector MatchingPairs= new Vector(); - for (ListIterator it_M= Matches.listIterator(); it_M.hasNext();) { - Match m= (Match) it_M.next(); - MatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) ? -1 : Integer.parseInt(m.fy.getName()))); - } - // for (Enumeration enum = MatchingPairs.elements(); enum.hasMoreElements(); ) { - // System.out.print(enum.nextElement() + " "); - // } - // System.out.println(); - assertTrue(expected.size() == MatchingPairs.size()); - for (Enumeration enum= expected.elements(); enum.hasMoreElements();) { - assertTrue(MatchingPairs.contains(enum.nextElement())); - } - } - - //Simulate plugin.xml with ids - public void test1() { - XMLChildren LeftTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - LeftTree.setName(Integer.toString(0)); - XMLChildren RightTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - RightTree.setName(Integer.toString(0)); - int numbering= 1; - //create Left Tree - XMLChildren parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setUsesIDMAP(true); - parent.setName(Integer.toString(numbering++)); - LeftTree.addChild(parent); - parent.setParent(LeftTree); - XMLChildren current= - new XMLChildren( - XMLStructureCreator.TYPE_ATTRIBUTE, - "id", //$NON-NLS-1$ - "org.eclipse.ui", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "runtime<[1]", //$NON-NLS-1$ - "runtime<[1]", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "runtime<[2]", //$NON-NLS-1$ - "runtime<[2]", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "library<workbench.jar", //$NON-NLS-1$ - "library<workbench.jar", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "export<*", //$NON-NLS-1$ - "export<*", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "export" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent().getParent(); - //parent is now plugin - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<importWizards", //$NON-NLS-1$ - "extension-point<importWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "export" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<popupMenus", //$NON-NLS-1$ - "extension-point<popupMenus", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension<org.eclipse.ui.newWizards", //$NON-NLS-1$ - "extension<org.eclipse.ui.newWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= parent; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "wizard<org.eclipse.ui.wizards.new.project.addedsomething", //$NON-NLS-1$ - "wizard<org.eclipse.ui.wizards.new.project.addedsomething", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "wizard" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "wizard<org.eclipse.ui.wizards.new.folder", //$NON-NLS-1$ - "wizard<org.eclipse.ui.wizards.new.folder", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "wizard" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - - //showNodeNames(LeftTree); - - //create Right Tree - numbering= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setUsesIDMAP(true); - parent.setName(Integer.toString(numbering++)); - RightTree.addChild(parent); - parent.setParent(RightTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ATTRIBUTE, - "id", //$NON-NLS-1$ - "org.eclipse.ui", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "runtime<[1]", //$NON-NLS-1$ - "runtime<[1]", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "library<workbench.jar", //$NON-NLS-1$ - "library<workbench.jar", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "export<*", //$NON-NLS-1$ - "export<*", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "export" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent().getParent(); - //parent is now plugin - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<popupMenus", //$NON-NLS-1$ - "extension-point<popupMenus", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<exportWizards", //$NON-NLS-1$ - "extension-point<importWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "export" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension<org.eclipse.ui.newWizards", //$NON-NLS-1$ - "extension<org.eclipse.ui.newWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= parent; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "wizard<org.eclipse.ui.wizards.new.project", //$NON-NLS-1$ - "wizard<org.eclipse.ui.wizards.new.project.addedsomething", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "wizard" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "wizard<org.eclipse.ui.wizards.new.folder", //$NON-NLS-1$ - "wizard<org.eclipse.ui.wizards.new.folder", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "wizard" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - - //showNodeNames(RightTree); - - //run matching algorithm - try { - fGM.match(LeftTree, RightTree, false, null); - } catch (InterruptedException e) { - } - Vector expected= new Vector(); - expected.add(new Pair(0, 0)); - expected.add(new Pair(1, 1)); - expected.add(new Pair(8, 6)); - expected.add(new Pair(9, 8)); - expected.add(new Pair(11, 10)); - expected.add(new Pair(2, 2)); - expected.add(new Pair(4, 3)); - expected.add(new Pair(3, -1)); - expected.add(new Pair(5, 4)); - expected.add(new Pair(6, 5)); - Vector Matches= fGM.getMatches(); - Vector MatchingPairs= new Vector(); - for (ListIterator it_M= Matches.listIterator(); it_M.hasNext();) { - Match m= (Match) it_M.next(); - MatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) ? -1 : Integer.parseInt(m.fy.getName()))); - } - // for (Enumeration enum = MatchingPairs.elements(); enum.hasMoreElements(); ) { - // System.out.print(enum.nextElement() + " "); - // } - // System.out.println(); - assertTrue(expected.size() == MatchingPairs.size()); - for (Enumeration enum= expected.elements(); enum.hasMoreElements();) { - assertTrue(MatchingPairs.contains(enum.nextElement())); - } - } - - //Three-way compare, general case without ids - public void test2() { - XMLChildren AncestorTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - XMLChildren LeftTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - XMLChildren RightTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - int numbering= 1; - //create Ancestor Tree - XMLChildren parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(numbering++)); - AncestorTree.addChild(parent); - parent.setParent(AncestorTree); - XMLChildren current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - XMLNode attr= - new XMLNode( - XMLStructureCreator.TYPE_ATTRIBUTE, - "attr", //$NON-NLS-1$ - "world", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "attr" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - attr.setName(Integer.toString(numbering++)); - parent.addChild(attr); - attr.setParent(parent); - - //create Left Tree - numbering= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(numbering++)); - LeftTree.addChild(parent); - parent.setParent(LeftTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - attr= - new XMLNode( - XMLStructureCreator.TYPE_ATTRIBUTE, - "attr", //$NON-NLS-1$ - "hello", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "attr" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - attr.setName(Integer.toString(numbering++)); - parent.addChild(attr); - attr.setParent(parent); - - //create Right Tree - numbering= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(numbering++)); - RightTree.addChild(parent); - parent.setParent(RightTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "e_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - attr= - new XMLNode( - XMLStructureCreator.TYPE_ATTRIBUTE, - "attr", //$NON-NLS-1$ - "world", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "attr" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - attr.setName(Integer.toString(numbering++)); - parent.addChild(attr); - attr.setParent(parent); - - //run matching algorithm - try { - fGM.match(LeftTree, RightTree, false, null); - Vector LRMatches= fGM.getMatches(); - Vector LRMatchingPairs= new Vector(); - for (ListIterator it_M= LRMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - LRMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - } - fGM.match(LeftTree, AncestorTree, true, null); - Vector LAMatches= fGM.getMatches(); - Vector LAMatchingPairs= new Vector(); - for (ListIterator it_M= LAMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - LAMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - - } - fGM.match(RightTree, AncestorTree, true, null); - Vector RAMatches= fGM.getMatches(); - Vector RAMatchingPairs= new Vector(); - for (ListIterator it_M= RAMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - RAMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - } - Vector LRexpected= new Vector(); - LRexpected.add(new Pair(0, 0)); - LRexpected.add(new Pair(1, 1)); - LRexpected.add(new Pair(2, 2)); - LRexpected.add(new Pair(-1, 4)); - LRexpected.add(new Pair(4, 6)); - LRexpected.add(new Pair(3, 3)); - LRexpected.add(new Pair(5, 7)); - Vector LAexpected= new Vector(); - LAexpected.add(new Pair(0, 0)); - LAexpected.add(new Pair(1, 1)); - LAexpected.add(new Pair(2, 2)); - LAexpected.add(new Pair(3, 3)); - LAexpected.add(new Pair(4, 4)); - LAexpected.add(new Pair(5, 5)); - Vector RAexpected= new Vector(); - RAexpected.add(new Pair(0, 0)); - RAexpected.add(new Pair(1, 1)); - RAexpected.add(new Pair(2, 2)); - RAexpected.add(new Pair(6, 4)); - RAexpected.add(new Pair(4, -1)); - RAexpected.add(new Pair(3, 3)); - RAexpected.add(new Pair(7, 5)); - - assertTrue(LRexpected.size() == LRMatchingPairs.size()); - for (Enumeration enum= LRexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(LRMatchingPairs.contains(enum.nextElement())); - } - assertTrue(LAexpected.size() == LAMatchingPairs.size()); - for (Enumeration enum= LAexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(LAMatchingPairs.contains(enum.nextElement())); - } - assertTrue(RAexpected.size() == RAMatchingPairs.size()); - for (Enumeration enum= RAexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(RAMatchingPairs.contains(enum.nextElement())); - } - } catch (InterruptedException e) { - } - - } - - //Three-way compare of plugin.xml with ids - public void test3() { - XMLChildren AncestorTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - AncestorTree.setName(Integer.toString(0)); - XMLChildren LeftTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - LeftTree.setName(Integer.toString(0)); - XMLChildren RightTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - RightTree.setName(Integer.toString(0)); - int numbering= 1; - //create Ancestor Tree - XMLChildren parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setUsesIDMAP(true); - parent.setName(Integer.toString(numbering++)); - AncestorTree.addChild(parent); - parent.setParent(AncestorTree); - XMLChildren current= - new XMLChildren( - XMLStructureCreator.TYPE_ATTRIBUTE, - "id", //$NON-NLS-1$ - "org.eclipse.ui", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - //parent is plugin - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<importWizards", //$NON-NLS-1$ - "extension-point<importWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "library" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "export" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<editorActions", //$NON-NLS-1$ - "extension-point<editorActions", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<popupMenus", //$NON-NLS-1$ - "extension-point<popupMenus", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<exportWizards", //$NON-NLS-1$ - "extension-point<exportWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - - //create LeftTree Tree - numbering= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setUsesIDMAP(true); - parent.setName(Integer.toString(numbering++)); - LeftTree.addChild(parent); - parent.setParent(LeftTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ATTRIBUTE, - "id", //$NON-NLS-1$ - "org.eclipse.ui", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - //parent is plugin - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<editorActions", //$NON-NLS-1$ - "extension-point<editorActions", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<popupMenus", //$NON-NLS-1$ - "extension-point<popupMenus", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<exportWizards", //$NON-NLS-1$ - "extension-point<exportWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - - //create RightTree Tree - numbering= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - "plugin" + XMLStructureCreator.ID_SEPARATOR + "org.eclipse.ui", //$NON-NLS-1$ //$NON-NLS-2$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setUsesIDMAP(true); - parent.setName(Integer.toString(numbering++)); - RightTree.addChild(parent); - parent.setParent(RightTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ATTRIBUTE, - "id", //$NON-NLS-1$ - "org.eclipse.ui", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "runtime" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ATTRIBUTE), - fdoc, - 0, - 0); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - //parent is plugin - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<editorActions", //$NON-NLS-1$ - "extension-point<editorActions", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<popupMenus", //$NON-NLS-1$ - "extension-point<popupMenus", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "extension-point<importWizards", //$NON-NLS-1$ - "extension-point<importWizards", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "plugin" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "extension-point" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setUsesIDMAP(true); - current.setName(Integer.toString(numbering++)); - parent.addChild(current); - current.setParent(parent); - - //run matching algorithm - try { - fGM.match(LeftTree, RightTree, false, null); - Vector LRMatches= fGM.getMatches(); - Vector LRMatchingPairs= new Vector(); - for (ListIterator it_M= LRMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - LRMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - } - fGM.match(LeftTree, AncestorTree, true, null); - Vector LAMatches= fGM.getMatches(); - Vector LAMatchingPairs= new Vector(); - for (ListIterator it_M= LAMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - LAMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - } - fGM.match(RightTree, AncestorTree, true, null); - Vector RAMatches= fGM.getMatches(); - Vector RAMatchingPairs= new Vector(); - for (ListIterator it_M= RAMatches.listIterator(); - it_M.hasNext(); - ) { - Match m= (Match) it_M.next(); - RAMatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) - ? -1 - : Integer.parseInt(m.fy.getName()))); - } - Vector LRexpected= new Vector(); - LRexpected.add(new Pair(0, 0)); - LRexpected.add(new Pair(1, 1)); - LRexpected.add(new Pair(2, 2)); - LRexpected.add(new Pair(3, 3)); - LRexpected.add(new Pair(4, 4)); - Vector LAexpected= new Vector(); - LAexpected.add(new Pair(0, 0)); - LAexpected.add(new Pair(1, 1)); - LAexpected.add(new Pair(2, 2)); - LAexpected.add(new Pair(3, 4)); - LAexpected.add(new Pair(4, 5)); - LAexpected.add(new Pair(5, 6)); - Vector RAexpected= new Vector(); - RAexpected.add(new Pair(0, 0)); - RAexpected.add(new Pair(1, 1)); - RAexpected.add(new Pair(2, 2)); - RAexpected.add(new Pair(3, 4)); - RAexpected.add(new Pair(4, 5)); - RAexpected.add(new Pair(5, 3)); - - assertTrue(LRexpected.size() == LRMatchingPairs.size()); - for (Enumeration enum= LRexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(LRMatchingPairs.contains(enum.nextElement())); - } - assertTrue(LAexpected.size() == LAMatchingPairs.size()); - for (Enumeration enum= LAexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(LAMatchingPairs.contains(enum.nextElement())); - } - assertTrue(RAexpected.size() == RAMatchingPairs.size()); - for (Enumeration enum= RAexpected.elements(); - enum.hasMoreElements(); - ) { - assertTrue(RAMatchingPairs.contains(enum.nextElement())); - } - } catch (InterruptedException e) { - } - } - - public void test4() { - ArrayList Ordered= new ArrayList(); - Ordered.add("root>a>b>"); //$NON-NLS-1$ - Ordered.add("root>a>b>c>"); //$NON-NLS-1$ - fGM= new GeneralMatching(Ordered); - int i= 1; - XMLChildren LeftTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - XMLChildren RightTree= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - XMLStructureCreator.ROOT_ID, - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - //create Left Tree - XMLChildren parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(i++)); - LeftTree.addChild(parent); - parent.setParent(LeftTree); - XMLChildren current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c1" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c2_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c2" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c3_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c3" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d1" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d2_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d2" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d3_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d3" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent().getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[3]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - - //create Right Tree - i= 1; - parent= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "a_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - parent.setName(Integer.toString(i++)); - RightTree.addChild(parent); - parent.setParent(RightTree); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c1" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c2_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c2" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c4_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c4" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c3_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c3" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[2]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "c_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= current; - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d1_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d1" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d3_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d3" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "d2_[1]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "c" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "d2" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - parent= (XMLChildren) parent.getParent().getParent(); - current= - new XMLChildren( - XMLStructureCreator.TYPE_ELEMENT, - "b_[3]", //$NON-NLS-1$ - "", //$NON-NLS-1$ - (XMLStructureCreator.ROOT_ID - + XMLStructureCreator.SIGN_SEPARATOR - + "a" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + "b" //$NON-NLS-1$ - + XMLStructureCreator.SIGN_SEPARATOR - + XMLStructureCreator.SIGN_ELEMENT), - fdoc, - 0, - 0); - current.setName(Integer.toString(i++)); - parent.addChild(current); - current.setParent(parent); - - //run matching algorithm - try { - fGM.match(LeftTree, RightTree, false, null); - } catch (InterruptedException e) { - } - Vector expected= new Vector(8); - expected.add(new Pair(0, 0)); - expected.add(new Pair(1, 1)); - expected.add(new Pair(2, 2)); - expected.add(new Pair(6, 7)); - expected.add(new Pair(11, 12)); - expected.add(new Pair(3, 3)); - expected.add(new Pair(4, 4)); - expected.add(new Pair(-1, 5)); - expected.add(new Pair(5, 6)); - expected.add(new Pair(7, 8)); - expected.add(new Pair(8, 9)); - expected.add(new Pair(-1, 10)); - expected.add(new Pair(9, 11)); - expected.add(new Pair(10, -1)); - Vector Matches= fGM.getMatches(); - Vector MatchingPairs= new Vector(); - for (ListIterator it_M= Matches.listIterator(); it_M.hasNext();) { - Match m= (Match) it_M.next(); - MatchingPairs.add( - new Pair( - (m.fx == null) ? -1 : Integer.parseInt(m.fx.getName()), - (m.fy == null) ? -1 : Integer.parseInt(m.fy.getName()))); - // System.out.println("("+ ((m.fx==null)?-1:Integer.parseInt(m.fx.getName()))+","+ ((m.fy==null)?-1:Integer.parseInt(m.fy.getName())) +")"); - } - // for (Enumeration enum = MatchingPairs.elements(); enum.hasMoreElements(); ) { - // System.out.print(enum.nextElement() + " "); - // } - // System.out.println(); - assertTrue(expected.size() == MatchingPairs.size()); - for (Enumeration enum= expected.elements(); enum.hasMoreElements();) { - assertTrue(MatchingPairs.contains(enum.nextElement())); - } - } - - protected void showNodeNames(XMLNode root) { - if (root != null) { - System.out.print(root.getName() + ", "); //$NON-NLS-1$ - Object[] children= root.getChildren(); - if (children != null) { - for (int i= 0; i < children.length; i++) - showNodeNames((XMLNode) children[i]); - } - } - } -} 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 deleted file mode 100644 index 25def12b1..000000000 --- a/examples/org.eclipse.compare.examples.xml/tests/org/eclipse/compare/examples/xml/TestMinCostBipartiteMatching.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.examples.xml; - -import junit.framework.*; -import org.eclipse.compare.examples.xml.HungarianMethod; - -public class TestMinCostBipartiteMatching extends TestCase { - - int[][] fA; //matrix that represents instance of matching problem - int[] fC; //solution returned by HungarianMethod - int fT; //cost of solution returned by HungarianMethod - int[] fC2; //actual solution of matching - int fT2; //actual cost of matching - HungarianMethod fH; - - public TestMinCostBipartiteMatching(String name) { - super(name); - } - public static void main(String[] args) { - //junit.textui.TestRunner.run (suite()); - //TestRunner.run(suite()); - } - - protected void setUp() { - System.out.println("TestMinCostBipartiteMatching.name()==" + getName()); //$NON-NLS-1$ - fH= new HungarianMethod(); - } - - protected void tearDown() throws Exception { - //remove set-up - } - - public static Test suite() { - return new TestSuite(TestMinCostBipartiteMatching.class); - } - - public void test0() { - fA= new int[][] { { 0, 0, 0, 0, 0, 0, 0 }, { - 0, 7, 2, 1, 9, 4, 0 }, { - 0, 9, 6, 9, 5, 5, 0 }, { - 0, 3, 8, 3, 1, 8, 0 }, { - 0, 7, 9, 4, 2, 2, 0 }, { - 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)} - fC2= new int[] { 0, 3, 5, 1, 4, 2 }; - - fT= fH.solve(fA, fC); - - for (int J= 1; J <= 5; J++) { - assertTrue(fC[J] == fC2[J]); - } - assertTrue(fT == fT2); - } - - public void test1() { - /* checks case where number of vertices on the two sides are not equal - * and dummy vertices (here, 2nd right vertice (see 3rd column)) are introduced - * with dummy cost - */ - fA= new int[][] { { 0, 0, 0, 0 }, { - 0, 2, 3, 0 }, { - 0, 0, 3, 0 } - }; - fC= new int[3]; - - fT2= 3; - //optimal matching: {(1,2), (2,1)} - fC2= new int[] { 0, 2, 1 }; - - fT= fH.solve(fA, fC); - - for (int J= 1; J < fC.length; J++) { - assertTrue(fC[J] == fC2[J]); - } - assertTrue(fT == fT2); - } - - public void test2() { - fA= new int[][] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { - 0, - 1542, - 3533, - 2787, - 1891, - 3833, - 3558, - 1173, - 2187, - 3307, - 2836, - 3792, - 2106, - 1444, - 1924, - 0 }, - { - 0, - 1510, - 3766, - 3186, - 1815, - 4931, - 3221, - 1478, - 2107, - 3344, - 2830, - 4816, - 2359, - 1223, - 1936, - 0 }, - { - 0, - 1160, - 3901, - 2100, - 1545, - 4484, - 3326, - 1355, - 1824, - 3088, - 2563, - 3627, - 2197, - 1354, - 1689, - 0 }, - { - 0, - 1203, - 4049, - 2295, - 1586, - 3556, - 4009, - 1110, - 2282, - 3990, - 2692, - 3751, - 2399, - 1691, - 1786, - 0 }, - { - 0, - 1426, - 3163, - 2242, - 1659, - 4617, - 3240, - 1712, - 1987, - 3637, - 3037, - 4471, - 2166, - 1356, - 1878, - 0 }, - { - 0, - 1172, - 3912, - 1951, - 1469, - 4272, - 3239, - 1546, - 1924, - 3560, - 2513, - 4694, - 2127, - 1951, - 1693, - 0 }, - { - 0, - 1647, - 3889, - 2097, - 1646, - 3749, - 3656, - 970, - 1957, - 3373, - 2678, - 3711, - 1788, - 1279, - 1752, - 0 }, - { - 0, - 1219, - 3754, - 2348, - 1686, - 4297, - 3677, - 1364, - 1995, - 4133, - 2888, - 3643, - 1993, - 1481, - 1880, - 0 }, - { - 0, - 1637, - 3895, - 2165, - 1575, - 4512, - 3903, - 1499, - 1935, - 2760, - 3151, - 3162, - 2306, - 1493, - 1710, - 0 }, - { - 0, - 1391, - 3992, - 1942, - 1846, - 4450, - 3211, - 1626, - 1952, - 3495, - 2951, - 4541, - 2014, - 1639, - 1932, - 0 }, - { - 0, - 1282, - 4292, - 3048, - 2074, - 4458, - 3460, - 1300, - 1952, - 3495, - 2951, - 4541, - 2014, - 1639, - 1932, - 0 }, - { - 0, - 1598, - 3721, - 2457, - 1880, - 4073, - 3164, - 1829, - 1952, - 3495, - 2951, - 4541, - 2014, - 1639, - 1932, - 0 }, - { - 0, - 1384, - 1742, - 2447, - 1858, - 4367, - 3189, - 1774, - 1699, - 3040, - 2499, - 3911, - 2203, - 1433, - 1676, - 0 }, - { - 0, - 1474, - 3815, - 2214, - 1997, - 4515, - 3202, - 1352, - 1942, - 3274, - 2502, - 5138, - 2395, - 1767, - 2136, - 0 } - }; - - fT2= 29858; - //optimal matching: {(8,1) (13,2) (10,3) (6,4) (4,5) (12,6) (1,7) (11,8) (3,9) (14,10) (9,11) (7,12) (2,13) (5,14)} - fC2= new int[] { 0, 8, 13, 10, 6, 4, 12, 1, 11, 3, 14, 9, 7, 2, 5 }; - - fC= new int[15]; - - fT= fH.solve(fA, fC); - - // for (int J=1; J<fC.length; J++) { - // System.out.print("("+fC[J]+","+J+") "); - // } - // System.out.println(); - // System.out.println("Cost: "+fT); - - for (int J= 1; J < fC.length; J++) { - assertTrue(fC[J] == fC2[J]); - } - assertTrue(fT == fT2); - } -} |