1 19 package org.netbeans.modules.javacore.jmiimpl.javamodel; 20 21 import java.util.*; 22 import org.netbeans.jmi.javamodel.NamedElement; 23 import org.netbeans.lib.java.parser.ASTree; 24 import org.netbeans.modules.javacore.parser.ElementInfo; 25 26 30 class CollectionMatcher { 31 private Object [] oldArr; 32 private Object [] newArr; 33 private int[] map; 34 35 36 CollectionMatcher(Object [] oldElements, Object [] newElements) { 37 oldArr=new Object [oldElements.length]; 38 System.arraycopy(oldElements,0,oldArr,0,oldElements.length); 39 newArr=new Object [newElements.length]; 40 for(int i=0;i<newElements.length;i++) { 41 MetadataElement el=(MetadataElement)newElements[i]; 42 newArr[i]=oldElements instanceof String [] ? ((NamedElement) el).getName() : el.getInternalForm(); 43 } 44 } 45 46 49 int[] getPositions() { 50 if (map==null) 51 mapArray(); 52 return map; 53 } 54 55 57 Set getDeleted() { 58 int i; 59 Set deleted=new HashSet(); 60 61 if (map==null) 62 mapArray(); 63 for (i=0;i<oldArr.length;i++) { 64 Object obj=oldArr[i]; 65 66 if (obj!=null) 67 deleted.add(obj); 68 } 69 return deleted; 70 } 71 72 private final void mapArray() { 73 int i; 74 Map oldMap=new HashMap(); 75 76 for (i=0;i<oldArr.length;i++) { 77 oldMap.put(oldArr[i],new Integer (i)); 78 } 79 map=new int[newArr.length]; 80 Arrays.fill(map,-1); 81 for (i=0;i<newArr.length;i++) { 82 Object newObj=newArr[i]; 83 Integer oldIndex=(Integer )oldMap.get(newObj); 84 85 if (oldIndex!=null) { 86 int index=oldIndex.intValue(); 87 88 map[i]=index; 89 oldArr[index]=null; 90 } 91 } 92 } 93 } 94 | Popular Tags |